search

Home  >  Q&A  >  body text

java - How to determine whether the value in a custom annotation is correct?

@RestController
@RequestMapping("/api")
public class CasApiController {
    private final transient Logger logger = LoggerFactory.getLogger(getClass());
    private UpTokenServiceInterface upTokenServiceInterface;

    private static final String LIMITER_KEY = "CasApiControllerControllerLimiter";
    private static final String LIMITER_KEY_HOUR = "CasApiControllerControllerLimiterHour";
    private static final String LIMITER_KEY_DAY = "CasApiControllerControllerLimiterDay";
    private static final int LIMITER_NUM_REQUESTS = 5;
    private static final int LIMITER_NUM_REQUESTS_HOUR = 10;
    private static final int LIMITER_NUM_REQUESTS_DAY = 20;

    @Autowired
    public CasApiController(UpTokenServiceInterface upTokenServiceInterface) {
        this.upTokenServiceInterface = upTokenServiceInterface;
    }

    @RequestMapping(value = "qiniu/uptoken", method = RequestMethod.GET )
    @ResponseBody
    @ApiControllerWithArgHttpServletRequestRateLimiterThrottleable
    @RateLimit(numRequests = LIMITER_NUM_REQUESTS, key = LIMITER_KEY)
    @RateLimit2(numRequests = LIMITER_NUM_REQUESTS_HOUR, key = LIMITER_KEY_HOUR)
    @RateLimit3(numRequests = LIMITER_NUM_REQUESTS_DAY, key = LIMITER_KEY_DAY)
    public JSONObject getUpToken() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("uptoken",upTokenServiceInterface.uploadToken());
        return jsonObject;
    }
}

-----------------------------
3个@RateLimit里面各有参数限制,日时分,要避免人为写错参数,怎么加一个判断或者验证,判断它们的参数和正确的顺序匹配?
仅有的幸福仅有的幸福2775 days ago524

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-17 10:07:56

    Java 8 already supports multiple identical Annotations, making it easier to judge.

    reply
    0
  • Cancelreply