@RequestMapping(value = "codiRoomMyClothesUpload", method = RequestMethod.POST) public String codiRoomMyClothesUpload( Clothes clothes, MultipartFile file, HttpServletRequest request) throws IOException { if (!file.isEmpty()) { ServletContext application = request.getServletContext(); String url = "/resource/image/clothes"; String path = application.getRealPath(url); String temp = file.getOriginalFilename(); String fname = temp.substring(temp.lastIndexOf("\\") + 1); String fpath = path + "\\" + fname; InputStream ins = file.getInputStream(); // part.getInputStream(); OutputStream outs = new FileOutputStream(fpath); byte[] buffer = new byte[1024]; int len = 0; while ((len = ins.read(buffer, 0, 1024)) >= 0) outs.write(buffer, 0, len); outs.flush(); outs.close(); ins.close(); clothes.setImage(fname); } clothesDao.addClothes(clothes); return "redirect:codiRoomMyClothes"; }
@RequestMapping("codiRoomMyClothes") public String codiRoomMyClothes(Model model, HttpSession session, Principal principal) { String mid = principal.getName(); List<Clothes> list = clothesDao.getMyClothes(mid); model.addAttribute("list", list); return "tastecoordi.codiRoomMyClothes"; }
@RequestMapping(value = "codiRoomMyClothesDelete", method = RequestMethod.POST) public String codiRoomMyClothesDelete(HttpServletRequest request) { String[] deleteClothes = request.getParameterValues("check"); for (int i = 0; i < deleteClothes.length; i++) { String code = deleteClothes[i]; clothesDao.removeClothes(code); } return "redirect: codiRoomMyClothes"; }