添加通用验证操作

This commit is contained in:
zhh
2018-04-19 17:19:41 +08:00
parent 79c6602f2f
commit 3f2652545f
5 changed files with 48 additions and 19 deletions

View File

@@ -36,9 +36,6 @@ public class PmsBrandController {
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public Object create(@Validated @RequestBody PmsBrandParam pmsBrand, BindingResult result) {
if (result.hasErrors()) {
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
}
CommonResult commonResult;
int count = brandService.createBrand(pmsBrand);
if (count == 1) {
@@ -52,10 +49,9 @@ public class PmsBrandController {
@ApiOperation(value = "更新品牌")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public Object updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandParam pmsBrandParam, BindingResult result) {
if (result.hasErrors()) {
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
}
public Object updateBrand(@PathVariable("id") Long id,
@Validated @RequestBody PmsBrandParam pmsBrandParam,
BindingResult result) {
CommonResult commonResult;
int count = brandService.updateBrand(id, pmsBrandParam);
if (count == 1) {

View File

@@ -27,10 +27,8 @@ public class PmsProductCategoryController {
@ApiOperation("添加产品分类")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam, BindingResult result) {
if (result.hasErrors()) {
return new CommonResult().validateFailed(result);
}
public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam,
BindingResult result) {
int count = productCategoryService.create(pmsProductCategoryParam);
if (count > 0) {
return new CommonResult().success(count);
@@ -46,9 +44,6 @@ public class PmsProductCategoryController {
@Validated
@RequestBody PmsProductCategoryParam pmsProductCategoryParam,
BindingResult result) {
if (result.hasErrors()) {
return new CommonResult().validateFailed(result);
}
int count = productCategoryService.update(id, pmsProductCategoryParam);
if (count > 0) {
return new CommonResult().success(count);