response.setStatus(HttpServletResponse.SC_OK);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
PrintWriter printWriter = null;
try {
printWriter = response.getWriter();
printWriter.write(JsonUtils.toJson(responseDto));
} catch (Exception e) {
logger.error(“handlerResponse catch a exception:” + e.getMessage());
} finally {
if (printWriter != null) {
printWriter.close();
}
}
}
}
b)定义流量控制拦截器,流量控制拦截器继承自上面的拦截器抽象类,在preFilter方法中进行流量控制。
/**
-
@author linzhiqiang
-
@date 2019/4/17
*/
@Component(“rateLimitInterceptor”)
public class RateLimitInterceptor extends AbstractInterceptor {
private Logger logger = LoggerFactory.getLogger(RateLimitInterceptor.class);
/**
-
<