- custom-annotation-demo1:自定义校验注解
- custom-annotation-demo2:自定义权限注解
- custom-annotation-demo3:自定义缓存注解
- custom-annotation-web:自定义注解测试
- 实体类 User.java
@Check(paramValues = {"man", "woman"})
private String sex;
对需要校验的字段添加@Check
注解
- Controller层
@PostMapping("/api/test")
public Object test(@Validated @RequestBody User user) {
return "hello world";
}
- Postman模拟请求测试
- Controller层
@GetMapping("/api/test")
@PermissionCheck(resourceKey = "test")
public Object testPermissionCheck() {
return "hello world";
}
- Postman模拟请求测试
将@PermissionCheck(resourceKey = "test")
替换为@PermissionCheck(resourceKey = "testKey")
- Controller层
@GetMapping("/api/cache")
@CustomCache(key = "test")
public Object testCustomCache() {
return "don't hit cache";
}
- Postman模拟请求测试
将@CustomCache(key = "test")
替换为@CustomCache(key = "testKey")
了解更多:Spring自定义注解从入门到精通