Commit 59bfd0ece9725194a7c6c4b482064d29091a658e

Authored by yangfan
1 parent 88309b95

参数验证

src/main/java/com/diligrp/xtrade/product/controllor/CategoryController.java
@@ -5,6 +5,7 @@ import java.util.List; @@ -5,6 +5,7 @@ import java.util.List;
5 5
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
  8 +import org.springframework.validation.annotation.Validated;
8 import org.springframework.web.bind.annotation.PathVariable; 9 import org.springframework.web.bind.annotation.PathVariable;
9 import org.springframework.web.bind.annotation.RequestBody; 10 import org.springframework.web.bind.annotation.RequestBody;
10 import org.springframework.web.bind.annotation.RequestMapping; 11 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,6 +21,7 @@ import com.diligrp.xtrade.product.exception.ExceptionEnum; @@ -20,6 +21,7 @@ import com.diligrp.xtrade.product.exception.ExceptionEnum;
20 import com.diligrp.xtrade.product.exception.ProductException; 21 import com.diligrp.xtrade.product.exception.ProductException;
21 import com.diligrp.xtrade.product.service.CategoryService; 22 import com.diligrp.xtrade.product.service.CategoryService;
22 import com.diligrp.xtrade.shared.domain.Message; 23 import com.diligrp.xtrade.shared.domain.Message;
  24 +import com.diligrp.xtrade.shared.util.AssertUtils;
23 25
24 /** 26 /**
25 * @ClassName: CategoryController 27 * @ClassName: CategoryController
@@ -51,7 +53,7 @@ public class CategoryController { @@ -51,7 +53,7 @@ public class CategoryController {
51 * @throws 53 * @throws
52 */ 54 */
53 @RequestMapping("save") 55 @RequestMapping("save")
54 - public Message<?> save(CategoryDto categoryDTO) { 56 + public Message<?> save(@Validated CategoryDto categoryDTO) {
55 checkImageFile(categoryDTO.getImage()); 57 checkImageFile(categoryDTO.getImage());
56 categoryService.insert(categoryDTO); 58 categoryService.insert(categoryDTO);
57 return Message.success(); 59 return Message.success();
@@ -66,7 +68,7 @@ public class CategoryController { @@ -66,7 +68,7 @@ public class CategoryController {
66 * @throws 68 * @throws
67 */ 69 */
68 @RequestMapping("update") 70 @RequestMapping("update")
69 - public Message<Object> update(CategoryDto categoryDTO) { 71 + public Message<Object> update(@Validated CategoryDto categoryDTO) {
70 categoryService.update(categoryDTO); 72 categoryService.update(categoryDTO);
71 return null; 73 return null;
72 74
@@ -80,22 +82,24 @@ public class CategoryController { @@ -80,22 +82,24 @@ public class CategoryController {
80 * @return 82 * @return
81 * @throws 83 * @throws
82 */ 84 */
83 - @RequestMapping("get/{id}")  
84 - public Message<?> get(@PathVariable Long id) {  
85 - return Message.success(categoryService.selectEntityById(id)); 85 + @RequestMapping("get/{cateCode}")
  86 + public Message<?> get(@PathVariable Long cateCode) {
  87 + AssertUtils.notNull(cateCode, "编码不能为空");
  88 + return Message.success(categoryService.selectEntityById(cateCode));
86 } 89 }
87 90
88 /** 91 /**
89 * 92 *
90 * @Title delect 93 * @Title delect
91 * @Description 主键删除 94 * @Description 主键删除
92 - * @param id 95 + * @param cateCode
93 * @return 96 * @return
94 * @throws 97 * @throws
95 */ 98 */
96 - @RequestMapping("delect/{id}")  
97 - public Message<?> delect(@PathVariable Long id) {  
98 - categoryService.delectById(id); 99 + @RequestMapping("delect/{cateCode}")
  100 + public Message<?> delect(@PathVariable Long cateCode) {
  101 + AssertUtils.notNull(cateCode, "编码不能为空");
  102 + categoryService.delectById(cateCode);
99 return Message.success(); 103 return Message.success();
100 } 104 }
101 105
@@ -109,6 +113,7 @@ public class CategoryController { @@ -109,6 +113,7 @@ public class CategoryController {
109 */ 113 */
110 @RequestMapping("selectCategoryChild/{cateCode}") 114 @RequestMapping("selectCategoryChild/{cateCode}")
111 public Message<?> selectCategoryChild(@PathVariable String cateCode) { 115 public Message<?> selectCategoryChild(@PathVariable String cateCode) {
  116 + AssertUtils.notEmpty(cateCode, "编码不能为空");
112 List<CategoryDo> categoryDos = categoryService.selectCateChild(cateCode); 117 List<CategoryDo> categoryDos = categoryService.selectCateChild(cateCode);
113 return Message.success(categoryDos); 118 return Message.success(categoryDos);
114 } 119 }
@@ -125,11 +130,11 @@ public class CategoryController { @@ -125,11 +130,11 @@ public class CategoryController {
125 if (!ImageUtil.isImage(file.getInputStream())) { 130 if (!ImageUtil.isImage(file.getInputStream())) {
126 throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"只能上传图片"); 131 throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"只能上传图片");
127 } 132 }
128 -// if (!ImageUtil.checkImageSize(file.getInputStream(), MAX_WIDTH, MAX_HEIGHT, MIN_WIDTH, MIN_HEIGHT)) {  
129 -//  
130 -// throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片长宽超过限制,请保证图片大小范围为" + MIN_WIDTH + "*" + MIN_HEIGHT + "到" + MAX_WIDTH + "*"  
131 -// + MAX_HEIGHT);  
132 -// } 133 + if (!ImageUtil.checkImageSize(file.getInputStream(), MAX_WIDTH, MAX_HEIGHT, MIN_WIDTH, MIN_HEIGHT)) {
  134 +
  135 + throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片长宽超过限制,请保证图片大小范围为" + MIN_WIDTH + "*" + MIN_HEIGHT + "到" + MAX_WIDTH + "*"
  136 + + MAX_HEIGHT);
  137 + }
133 if (file.getBytes().length > MAX_FILE_SIZE) { 138 if (file.getBytes().length > MAX_FILE_SIZE) {
134 throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片大小超过限制,请保证图片不超过256K"); 139 throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片大小超过限制,请保证图片不超过256K");
135 } 140 }
src/main/java/com/diligrp/xtrade/product/controllor/ShopController.java
@@ -14,6 +14,7 @@ import com.diligrp.xtrade.product.domain.dto.ShopDto; @@ -14,6 +14,7 @@ import com.diligrp.xtrade.product.domain.dto.ShopDto;
14 import com.diligrp.xtrade.product.domain.entity.ShopDo; 14 import com.diligrp.xtrade.product.domain.entity.ShopDo;
15 import com.diligrp.xtrade.product.service.ShopService; 15 import com.diligrp.xtrade.product.service.ShopService;
16 import com.diligrp.xtrade.shared.domain.Message; 16 import com.diligrp.xtrade.shared.domain.Message;
  17 +import com.diligrp.xtrade.shared.util.AssertUtils;
17 18
18 /** 19 /**
19 * @ClassName: ShopControler 20 * @ClassName: ShopControler
@@ -53,6 +54,7 @@ public class ShopController { @@ -53,6 +54,7 @@ public class ShopController {
53 @RequestMapping("get/{shopId}") 54 @RequestMapping("get/{shopId}")
54 55
55 public Message<?> get(@PathVariable Long shopId){ 56 public Message<?> get(@PathVariable Long shopId){
  57 + AssertUtils.notNull(shopId, "店铺id不能为空");
56 return Message.success(shopService.selectByShopId(shopId)); 58 return Message.success(shopService.selectByShopId(shopId));
57 } 59 }
58 60
@@ -66,6 +68,7 @@ public class ShopController { @@ -66,6 +68,7 @@ public class ShopController {
66 */ 68 */
67 @RequestMapping("selectShopByMerId/{merId}") 69 @RequestMapping("selectShopByMerId/{merId}")
68 public Message<?> selectShopByMerId(@PathVariable Long merId){ 70 public Message<?> selectShopByMerId(@PathVariable Long merId){
  71 + AssertUtils.notNull(merId, "商户id不能为空");
69 List<ShopDo> shopDos = shopService.selectShopByMerId(merId); 72 List<ShopDo> shopDos = shopService.selectShopByMerId(merId);
70 return Message.success(shopDos); 73 return Message.success(shopDos);
71 74