@@ -32,16 +32,17 @@ public class PhotoController {
32
32
33
33
@ ResponseBody
34
34
@ RequestMapping (value ="/upload" ,method =RequestMethod .POST )
35
- private Message fildUpload (@ RequestParam (value ="file" ,required =false ) MultipartFile file [] ,
35
+ private Message fildUpload (@ RequestParam (value ="file" ,required =false ) MultipartFile file ,
36
36
String name ,Integer belongId ,HttpServletRequest request )throws Exception {
37
37
//基本表单
38
38
39
39
//获得物理路径webapp所在路径
40
40
String pathRoot = request .getSession ().getServletContext ().getRealPath ("" );
41
41
String path ="" ;
42
42
List <String > listImagePath =new ArrayList <String >();
43
- for (MultipartFile mf : file ) {
44
- if (!mf .isEmpty ()){
43
+ // for (MultipartFile mf : file) {
44
+ Integer saveId = null ;
45
+ if (!file .isEmpty ()){
45
46
//生成uuid作为文件名称
46
47
// String uuid = UUID.randomUUID().toString().replaceAll("-","");
47
48
//获得文件类型(可以判断如果不是图片,禁止上传)
@@ -53,13 +54,13 @@ private Message fildUpload(@RequestParam(value="file",required=false) MultipartF
53
54
+ FilenameUtils .getExtension (name );
54
55
System .out .println ("imageName:" +newFileName );
55
56
path ="/upload/" +newFileName ;
56
- mf .transferTo (new File (pathRoot +path ));
57
+ file .transferTo (new File (pathRoot +path ));
57
58
listImagePath .add (path );
58
- System .out .println (path );
59
+ // System.out.println(path);
59
60
logger .info ("name:" +name );
60
61
logger .info ("belongId:" +belongId );
61
62
User user = (User ) request .getSession ().getAttribute ("user" );
62
- Integer saveId = null ;
63
+
63
64
try {
64
65
saveId = photoService .save (new Photo (name , path , belongId , user .getId ()));
65
66
} catch (Exception e ) {
@@ -68,8 +69,8 @@ private Message fildUpload(@RequestParam(value="file",required=false) MultipartF
68
69
return new Message ("0" ,"保存相片失败" );
69
70
}
70
71
}
71
- }
72
- return this .findAll ( belongId );
72
+ // }
73
+ return this .findById ( saveId );
73
74
}
74
75
75
76
@ RequestMapping ("/findByid" )
0 commit comments