Hello, I wrote a program that User can add several photos. When the user adds photos, these are added to the database in the same line, that is, when he chose a valid 2 photos and clicked add, I put this debug on this moment and watched step by step, it saves the photo at number one and then in the same line adds the photo under number 2 what could be the reason?
Photo add code
@RequestMapping(value = "/addAnswerPicture",method = RequestMethod.POST) public String addAnswerPicture(@ModelAttribute("answerPicture") AnswerPicture answerPicture,@RequestParam("pic") MultipartFile[] files) throws IOException { File dir = new File(imageUploadPath); if (!dir.exists()) { dir.mkdir(); } for (MultipartFile file : files) { String picName = System.currentTimeMillis() + "_" + file.getOriginalFilename(); File picture = new File("D:\\itBrainPictures\\" + picName); file.transferTo(picture); answerPicture.setImagePath(picName); answerPictureRepository.save(answerPicture); } return "redirect:/adminHome"; } redirect goes here
@RequestMapping(value = "/adminHome", method = RequestMethod.GET) public String adminController(ModelMap map) { map.addAttribute("newTask", new Task()); map.addAttribute("newAnswer", new Answer()); map.addAttribute("newAnswerPicture",new AnswerPicture()); map.addAttribute("allTasks", taskRepository.findAll()); map.addAttribute("allAnswers", answerRepository.findAll()); return "adminHomes"; } Jsp
<spring:form action="/addAnswerPicture" modelAttribute="newAnswerPicture" method="post" enctype="multipart/form-data"> <spring:select path="answer"> <c:forEach items="${allAnswers}" var="answer"> <option value="${answer.id}">${answer.timestamp}</option> </c:forEach> </spring:select> <input type="file" name="pic" multiple accept="pic/*"/> <input type="submit" value="ok"> the program was written in Spring
