Code Monkey home page Code Monkey logo

custom-annotation's Introduction

自定义注解

模块介绍

  • 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自定义注解从入门到精通

custom-annotation's People

Contributors

tiantianupup avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.