springBoot添加aop配置
      
      我的
      
      
valid
      
      
      
      请求验证登陆


      
      @valid 使用

      
      主要 log打印,打印请求request信息(url,method,ip,类方法,参数)
      
      springboot+aop编程
      
      git的拉取,切换项目
      
      
      
      表单验证步骤:
1、在方法中使用 pojo对象作为参数,并在参数前添加@ Valid注解,同时pojo后面还要传入另一个参数:BindingResult对象,用来接受返回验证结果。
2、在POJO对象的需要验证的字段上添加注解,例如:private int age字段需要限制年龄小于18岁,就不通过。那么就在字段上加上@Min注解,例如:
@Min(value = 18,message = " 未成年不能添加 ")
private int age;
其中:
    1、@Min 表示字段的限制条件,此处为最小值
2、value表示需要限制的阈值
3、message表示对限制后的提示信息。
      
      
      
      11212
      
      @Pointcut可以提取相同的切面方法,@Before或者@After等可以应用该方法。

      
      添加依赖

新建一个类
在类上加上注解:@Aspect和@Component
在类的方法上加前置方法注解:@Before("execution(public * 方法路径)")
      
      对API的测试
      
      自定义异常要继承RuntimeException,继承Exception是没有事务回滚的,继承RuntimeException有事务回滚。
      
      
      
      
      
      aop获取方法名,参数,结果集
      
      @RunWith( SpringRunner. class)
@SpringBootTest 封装的junit测试
Assert. assertEquals 断言
----------
@AutoConfigureMockMvc
MockMVC 测试Controller
      
      使用 @ControllerAdvice 实现全局异常处理
@ExceptionHandler(value = Exception. class )
自动的事务回滚只支持 RuntimeException
      
      统一接口返回数据格式
      
      ServletRequestAttributes  attributes = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
      
      @Pointcut 切点
共用的方法
LoggerFactory.getLogger(HttpAspect.class)
日志打印
      
      第一步,添加依赖
Springboot.starter.aop
第二步,启动类添加注解
AOP不需要
第三步,创建处理文件
@Aspect 拦截注解
@Component 被扫描
@Before ("execution(public * 包.类.方法(..))") 方法执行之前
      
      将通用的服务,从具体业务逻辑中分离出来
      
      @Valid 启用验证
BindingResult 验证结果
bindingResult.hasErrors() 验证失败
bindingResult.getFieldError().getDefaultMessage() 错误信息
      
      项目源码,https://github.com/Daoshun/girl,连接oracle版,需要的同学可以参考下。
      
      源码地址:https://git.oschina.net/liaoshixiong/girl/tags