@RequestMapping(value = "schoolBagOK") public String schoolBagOK(String bagId, String schoolbagId, Model model) { SchoolBag schoolbag = schoolBagService.findById(schoolbagId); model.addAttribute("msgV", schoolbag.getMsgV()); model.addAttribute("guanming", schoolbag.getHeadImage()); model.addAttribute("image", schoolbag.getBgtype()); model.addAttribute("moban", schoolbag.getMoban()); model.addAttribute("bagId", bagId); return "hongbaoOK"; }
@RequestMapping(value = "findById") public String findById(String openId, String url, Model model) { int cc = url.indexOf("bagId="); String bagId = url.substring(cc + 6, cc + 6 + 32); Bag bag = bagService.findById(bagId); SchoolBag schoolbag = schoolBagService.findBySchoolBagId(bag.getSchoolBagId()); model.addAttribute("hengimage", schoolbag.getHeadImage()); model.addAttribute("msg", schoolbag.getMsgV()); model.addAttribute("beijing", schoolbag.getBgtype()); model.addAttribute("bagId", bag.getId()); model.addAttribute("openId", openId); return "home"; }
@RequestMapping(value = "upload") public String upload( @RequestParam("fileupload") MultipartFile file, String guanming, String sum, SchoolBag schoolBag, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException { String imgPath = null; System.out.println("模板:" + schoolBag.getMoban()); System.out.println("冠名:" + guanming); System.out.println("总和:" + sum); if (schoolBag.getMoban().equals("3")) { if (!file.isEmpty()) { String image = null; try { String name = file.getOriginalFilename().substring(file.getOriginalFilename().indexOf(".")); image = UUID.randomUUID().toString() + name; imgPath = request.getSession().getServletContext().getRealPath("/views/headImg") + "/" + image; file.transferTo(new File(imgPath)); } catch (Exception e) { return "error"; } schoolBag.setBgtype("/views/headImg/" + image); } } try { Map<Object, Object> map = request.getParameterMap(); schoolBag.setNumN(Integer.parseInt(sum)); schoolBag.setHeadImage(guanming); schoolBag.setDateN(DateUtils.getDate("yyyy-MM-dd")); String bagId = schoolBagService.save(schoolBag, map, Integer.parseInt(sum)); System.out.println("生成的红包Id:" + bagId); model.addAttribute("bagId", bagId); model.addAttribute("schoolbagId", schoolBag.getId()); return "redirect:/schoolBag/schoolBagOK"; } catch (Exception e) { if (imgPath != null) { File f = new File(imgPath); if (f.exists()) { f.delete(); } } return "error"; } }