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