0
我使用Spring 3.2,Hibernate 4.1和Mysql。我試圖將文件保存到本地驅動器,然後將文件路徑保存到數據庫以供將來下載。我已經實現了文件上傳到服務器,但現在我不知道誰去保存到MySQL表的文件路徑。Spring將文件路徑插入到mysql
這是控制器代碼
@RequestMapping(value = "/add", method = RequestMethod.POST, params = "save")
public String saveProcess(@RequestParam("moduleId") Integer moduleId,
@ModelAttribute("module") Module module, BindingResult result,
@RequestParam("file") CommonsMultipartFile[] file ,
HttpSession session, HttpServletRequest request) throws
IllegalStateException, IOException {
logger.info("Request to save the module");
if(module != null){
if (file != null && file.length > 0) {
for (CommonsMultipartFile aFile : file){
System.out.println("Saving file: " + aFile.getOriginalFilename());
if (!aFile.getOriginalFilename().equals("")) {
aFile.transferTo(new File(saveDirectory +
aFile.getOriginalFilename()));
}
}
}
moduleService.saveorupdate(module);
}
return "redirect:/home";
}
這是分貝
CREATE TABLE `modules` (
`module_id` bigint(20) NOT NULL AUTO_INCREMENT,
`document_title` varchar(255) DEFAULT NULL,
`document_path` varchar(255) DEFAULT NULL,
PRIMARY KEY (`module_id`);
的filepath是要被插入到所述document_path柱。任何想法都會受到歡迎。
什麼問題?你卡在哪裏? –
感謝您的回覆。我想知道如何保存我上傳到數據庫表的文件的文件路徑。 – user2259555