controller的代码:
@PostMapping(“addBookInfo”)
public String addBookInfo(@RequestParam HashMap map,MultipartFile file, HttpSession session){
try {
String realPath = session.getServletContext().getRealPath("/images/book_img");
String filename = file.getOriginalFilename(); //文件名字
filename=filename.replace(filename.substring(0, filename.lastIndexOf(".")), UUID.randomUUID().toString());
map.put(“imgurl”, filename);
filename=realPath+filename;
file.transferTo(new File(filename));
} catch (Exception e) {
e.printStackTrace();
}
bookInfoService.addBookInfo(map);
return “redirect:qureyLikeAll”;
}
导入配置文件:
文件上传的controller
最新推荐文章于 2023-07-10 09:48:16 发布