第五步:控制器UploadController实现。
UploadController 主要分为3部分
2.1 调整页面请求goUploadImg
2.2 上传请求方法uploadImg
2.3 存储图片方法uploadFile
@Controllerpublic class UploadController {
//跳转到上传文件的页面
@RequestMapping(value = "/gouploadimg", method = RequestMethod.GET)
public String goUploadImg() {
//跳转到 templates 目录下的 uploadimg.html
return "uploadimg";
}
//处理文件上传
@ResponseBody //返回json数据
@RequestMapping(value = "/testUploadimg", method = RequestMethod.POST)
public String uploadImg(@RequestParam("file") MultipartFile file,
HttpServletRequest request) {
tring contentType = file.getContentType();
String fileName = file.getOriginalFilename();
String filePath = "D:/img";
if (file.isEmpty()) {