// 后台添加
@RequestMapping("notadd")
public String notadd(
HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "ufile", required = false) MultipartFile file,
Model model, Notice notice) {
String path = request.getSession().getServletContext()
.getRealPath("file");// 获得上传的路径
String fileName = file.getOriginalFilename();// 获得上传的文件名
File targetFile = new File(path, fileName);// 创建上传到服务器的文件对象
try {
file.transferTo(targetFile);// 文件转储
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String imgUrl = request.getContextPath() + "/file/" + fileName;
notice.setNoticepicture(imgUrl);
noticeService.noticeadd(notice);
jiazai(request);
//Sos
if ("6".equals(notice.getNoticetype())) {
return "redirect:toaddlisttupian.do?ids=" + notice.getNoticetype();
}
return "redirect:notlists.do?ids=" + notice.getNoticetype();
}
@RequestMapping("notadd")
public String notadd(
HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "ufile", required = false) MultipartFile file,
Model model, Notice notice) {
String path = request.getSession().getServletContext()
.getRealPath("file");// 获得上传的路径
String fileName = file.getOriginalFilename();// 获得上传的文件名
File targetFile = new File(path, fileName);// 创建上传到服务器的文件对象
try {
file.transferTo(targetFile);// 文件转储
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String imgUrl = request.getContextPath() + "/file/" + fileName;
notice.setNoticepicture(imgUrl);
noticeService.noticeadd(notice);
jiazai(request);
//Sos
if ("6".equals(notice.getNoticetype())) {
return "redirect:toaddlisttupian.do?ids=" + notice.getNoticetype();
}
return "redirect:notlists.do?ids=" + notice.getNoticetype();
}