# validateAspectHandel **Repository Path**: AVC_HC/validateaspecthandel ## Basic Information - **Project Name**: validateAspectHandel - **Description**: 一个用于Controller过滤参数的AOP项目 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2017-05-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 提供Controller层参数校验 ##一、使用 ### 1、在controller上加上@ValidateGroup和内部的ValidateField注解即可实现校验 ```java @ValidateGroup(fields = { @ValidateField(index = 0, notNull = true, showName = "a 符号a") }) @RequestMapping(value = "/test") public Result test(String a){ return new Result<>("", true, a); } ``` ### 2、发送URL ```json http://localhost:8080/value/test ``` > 2.1、得到返回值 ```Json {"message":"","success":false,"returnValue":"a 符号a 不能为空!"} ``` ### 3、发送合法的URL ```Json http://localhost:8080/value/test?a=1 ``` > 3.1、得到返回值 ```Json {"message":"","success":true,"returnValue":"1"} ``` ### 4、若为一个Bean,需要对其属性进行校验 ```java @ValidateGroup(fields = { @ValidateField(index = 0,filedName = "value", notNull = true, showName = "value 属性value") }) @RequestMapping(value = "/param", method = RequestMethod.POST) public Result param(@RequestBody Param param){ return new Result<>("", true, param.getValue()); } ``` > 4.1、则需要在validateField上添加一个fileName字段属性表明对应的对象属性 > > 其中对象Param的类型格式为 ```java @Data public class Param { private String value; } ``` > 4.2、发送请求,其中value为空 ```sh curl --request POST \ --url http://localhost:8080/value/param \ --header 'content-type: application/json' \ --data '{ "value":"" }' ``` > 4.3、得到返回值为: ```json { "message": "", "success": false, "returnValue": "value 属性value 不能为空!" } ```