suchen

Heim  >  Fragen und Antworten  >  Hauptteil

java - Wie kann festgestellt werden, ob der Wert in einer benutzerdefinierten Anmerkung korrekt ist?

@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里面各有参数限制,日时分,要避免人为写错参数,怎么加一个判断或者验证,判断它们的参数和正确的顺序匹配?
仅有的幸福仅有的幸福2784 Tage vor529

Antworte allen(1)Ich werde antworten

  • ringa_lee

    ringa_lee2017-05-17 10:07:56

    java 8 已经支持多个相同 Annotation 了,判断起来更方便。

    Antwort
    0
  • StornierenAntwort