@RequestMapping("/update") R update(@RequestBody Flower flower){ R r = new R(); int ans = flowerService.update(flower); if (ans >= 0) { return r.setCode(2000).setMsg(HttpMsg.UPDATE_FLOWER_OK); } return r.setCode(4000).setMsg(HttpMsg.UPDATE_FLOWER_FAILED); }
@RequestMapping("/changeState") R changeState(@RequestBody Flower flower){ R r = new R(); flowersDao.changeState(flower); String msg = flower.getState() == 1?HttpMsg.GOODS_UP_OK:HttpMsg.GOODS_DOWN_OK; return r.setCode(2000).setMsg(msg); }
// 保存上传的图片 @RequestMapping("/updateImg") R updateImg(@RequestParam("file") MultipartFile file){ R r = new R(); // 只接收 jpg/png 图片 String filename = file.getOriginalFilename(); if (!filename.endsWith(".jpg") && !filename.endsWith(".png")){ return r.setCode(4000).setMsg(HttpMsg.ERROR_FILE_TYPE); } String img_guid = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg"; try { savePic(file.getInputStream(), img_guid); return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK).setData(img_guid); } catch (IOException e) { return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED); } }
@PutMapping("/updateImgGuid") R updateImgGuid(@RequestParam("guid") String guid, @RequestParam("id")int id){ R r = new R(); int ans = flowerService.updateImg(guid, id); if (ans == 1) { return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK); } return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED); }
@RequestMapping("/test") R test(){ R r = new R(); return r.setCode(4000).setMsg(Constant.IMG_PATH).setData(dao.findAll()); }
@RequestMapping("/queryByAccount") R queryByAccount(@RequestParam("account") String account){ R r = new R(); if (StringUtil.isEmpty(account)) { return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM); } List<Cart> carts = cartService.queryByAccount(account); for (Cart cart : carts) { float price = flowersDao.queryPrice(cart.getFid()); cart.setPrice(cart.getAmount() * price); } return r.setCode(2000).setData(carts); }
@RequestMapping("/find") R find(@RequestParam("page")int page, @RequestParam("searchKey") String searchKey, @RequestParam("account") String account){ R r = new R(); Map<String, Object> map = new HashMap<>();
@RequestMapping("/doLogin") R doLogin(@RequestBody LoginForm form){ R r = new R(); if (!VerifyUtil.verifyLoginForm(form)) { return r.setCode(4000).setMsg(HttpMsg.ERROR_INPUT); } User loginUser = loginDao.login(form); if (loginUser != null) { return r.setCode(2000).setMsg("欢迎您:" + loginUser.getName()).setData(loginUser); }
@RequestMapping("/create") R create(@RequestBody Cart cart){ R r = new R(); int ans = cartService.add(cart); if (ans == 1) { return r.setCode(2000).setMsg(HttpMsg.ADD_CART_OK); } return r.setCode(4000).setMsg(HttpMsg.ADD_CART_FAILED); }
@RequestMapping("/update") R update(@RequestBody Cart cart){ R r = new R(); int ans = cartService.update(cart); if (ans >= 0) { return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK); } return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED); }
@DeleteMapping("/delete") R delete(@RequestParam("id")int id){ R r = new R(); int ans = cartService.delete(id); if (ans == 1) { return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK); } return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED); } }