添加通用验证操作
This commit is contained in:
parent
79c6602f2f
commit
3f2652545f
10
README.md
10
README.md
@ -24,14 +24,14 @@ AdminLte | 前端模版
|
||||
集成SpringSecurity | ✔
|
||||
集成Swagger-UI | ✔
|
||||
集成Hibernator-Validator | ✔
|
||||
对通用返回结果进行封装 | ✔
|
||||
crud操作demo | ✔
|
||||
添加分页查询功能 | ✔
|
||||
集成日志功能 | ✔
|
||||
集成监控功能 | ✔
|
||||
包结构调整 | ✔
|
||||
SpringSecurity登录改为Restful形式 |
|
||||
crud操作demo | ✔
|
||||
合理规划包结构 | ✔
|
||||
SpringAOP通用日志处理 | ✔
|
||||
SpringAOP通用验证失败结果返回 | ✔
|
||||
CommonResult对通用返回结果进行封装 | ✔
|
||||
SpringSecurity登录改为Restful形式 |
|
||||
|
||||
### 功能完善
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.macro.mall.component;
|
||||
|
||||
import com.macro.mall.dto.CommonResult;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
/**
|
||||
* HibernateValidator错误结果处理切面
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(2)
|
||||
public class BindingResultAspect {
|
||||
@Pointcut("execution(public * com.macro.mall.controller.*.*(..))")
|
||||
public void BindingResult() {
|
||||
}
|
||||
|
||||
@Around("BindingResult()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
for (Object arg : args) {
|
||||
if (arg instanceof BindingResult) {
|
||||
BindingResult result = (BindingResult) arg;
|
||||
if (result.hasErrors()) {
|
||||
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@ -31,6 +32,7 @@ import java.util.*;
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
public class WebLogAspect {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
private ThreadLocal<Long> startTime = new ThreadLocal<>();
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user