添加通用验证操作
This commit is contained in:
parent
79c6602f2f
commit
3f2652545f
10
README.md
10
README.md
@ -24,14 +24,14 @@ AdminLte | 前端模版
|
|||||||
集成SpringSecurity | ✔
|
集成SpringSecurity | ✔
|
||||||
集成Swagger-UI | ✔
|
集成Swagger-UI | ✔
|
||||||
集成Hibernator-Validator | ✔
|
集成Hibernator-Validator | ✔
|
||||||
对通用返回结果进行封装 | ✔
|
|
||||||
crud操作demo | ✔
|
|
||||||
添加分页查询功能 | ✔
|
|
||||||
集成日志功能 | ✔
|
集成日志功能 | ✔
|
||||||
集成监控功能 | ✔
|
集成监控功能 | ✔
|
||||||
包结构调整 | ✔
|
crud操作demo | ✔
|
||||||
SpringSecurity登录改为Restful形式 |
|
合理规划包结构 | ✔
|
||||||
SpringAOP通用日志处理 | ✔
|
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.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@ -31,6 +32,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
|
@Order(1)
|
||||||
public class WebLogAspect {
|
public class WebLogAspect {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);
|
||||||
private ThreadLocal<Long> startTime = new ThreadLocal<>();
|
private ThreadLocal<Long> startTime = new ThreadLocal<>();
|
||||||
|
@ -36,9 +36,6 @@ public class PmsBrandController {
|
|||||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object create(@Validated @RequestBody PmsBrandParam pmsBrand, BindingResult result) {
|
public Object create(@Validated @RequestBody PmsBrandParam pmsBrand, BindingResult result) {
|
||||||
if (result.hasErrors()) {
|
|
||||||
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
|
|
||||||
}
|
|
||||||
CommonResult commonResult;
|
CommonResult commonResult;
|
||||||
int count = brandService.createBrand(pmsBrand);
|
int count = brandService.createBrand(pmsBrand);
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
@ -52,10 +49,9 @@ public class PmsBrandController {
|
|||||||
@ApiOperation(value = "更新品牌")
|
@ApiOperation(value = "更新品牌")
|
||||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object updateBrand(@PathVariable("id") Long id, @Validated @RequestBody PmsBrandParam pmsBrandParam, BindingResult result) {
|
public Object updateBrand(@PathVariable("id") Long id,
|
||||||
if (result.hasErrors()) {
|
@Validated @RequestBody PmsBrandParam pmsBrandParam,
|
||||||
return new CommonResult().validateFailed(result.getFieldError().getDefaultMessage());
|
BindingResult result) {
|
||||||
}
|
|
||||||
CommonResult commonResult;
|
CommonResult commonResult;
|
||||||
int count = brandService.updateBrand(id, pmsBrandParam);
|
int count = brandService.updateBrand(id, pmsBrandParam);
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
|
@ -27,10 +27,8 @@ public class PmsProductCategoryController {
|
|||||||
@ApiOperation("添加产品分类")
|
@ApiOperation("添加产品分类")
|
||||||
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
@RequestMapping(value = "/create", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam, BindingResult result) {
|
public Object create(@Validated @RequestBody PmsProductCategoryParam pmsProductCategoryParam,
|
||||||
if (result.hasErrors()) {
|
BindingResult result) {
|
||||||
return new CommonResult().validateFailed(result);
|
|
||||||
}
|
|
||||||
int count = productCategoryService.create(pmsProductCategoryParam);
|
int count = productCategoryService.create(pmsProductCategoryParam);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return new CommonResult().success(count);
|
return new CommonResult().success(count);
|
||||||
@ -46,9 +44,6 @@ public class PmsProductCategoryController {
|
|||||||
@Validated
|
@Validated
|
||||||
@RequestBody PmsProductCategoryParam pmsProductCategoryParam,
|
@RequestBody PmsProductCategoryParam pmsProductCategoryParam,
|
||||||
BindingResult result) {
|
BindingResult result) {
|
||||||
if (result.hasErrors()) {
|
|
||||||
return new CommonResult().validateFailed(result);
|
|
||||||
}
|
|
||||||
int count = productCategoryService.update(id, pmsProductCategoryParam);
|
int count = productCategoryService.update(id, pmsProductCategoryParam);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return new CommonResult().success(count);
|
return new CommonResult().success(count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user