Skip to content

Commit 4fd0c42

Browse files
committed
2016-05-26
1 parent 9169229 commit 4fd0c42

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
Binary file not shown.

src/com/bishe/photo/controller/PhotoController.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ public class PhotoController {
3232

3333
@ResponseBody
3434
@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,
3636
String name,Integer belongId,HttpServletRequest request)throws Exception{
3737
//基本表单
3838

3939
//获得物理路径webapp所在路径
4040
String pathRoot = request.getSession().getServletContext().getRealPath("");
4141
String path="";
4242
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()){
4546
//生成uuid作为文件名称
4647
// String uuid = UUID.randomUUID().toString().replaceAll("-","");
4748
//获得文件类型(可以判断如果不是图片,禁止上传)
@@ -53,13 +54,13 @@ private Message fildUpload(@RequestParam(value="file",required=false) MultipartF
5354
+ FilenameUtils.getExtension(name);
5455
System.out.println("imageName:"+newFileName);
5556
path="/upload/"+newFileName;
56-
mf.transferTo(new File(pathRoot+path));
57+
file.transferTo(new File(pathRoot+path));
5758
listImagePath.add(path);
58-
System.out.println(path);
59+
// System.out.println(path);
5960
logger.info("name:"+name);
6061
logger.info("belongId:"+belongId);
6162
User user = (User) request.getSession().getAttribute("user");
62-
Integer saveId = null;
63+
6364
try {
6465
saveId = photoService.save(new Photo(name, path, belongId, user.getId()));
6566
} catch (Exception e) {
@@ -68,8 +69,8 @@ private Message fildUpload(@RequestParam(value="file",required=false) MultipartF
6869
return new Message("0","保存相片失败");
6970
}
7071
}
71-
}
72-
return this.findAll(belongId);
72+
// }
73+
return this.findById(saveId);
7374
}
7475

7576
@RequestMapping("/findByid")

0 commit comments

Comments
 (0)