CROS 跨域
@EnableCORS
如果想要 Controller 支持 CROS,在类上添加@EnableCORS 即可 如果想要 Action 支持 CROS,在方法上添加@EnableCORS 即可 DefaultHttpRequestHandler.processDynamic 方法会处理@EnableCORS 注解 @EnableCORS 使用示例如下
package com.litongjava.tio.boot.admin.AController.api.admin.system;
import com.litongjava.tio.boot.annotation.EnableCORS;
import com.litongjava.tio.http.common.HttpRequest;
import com.litongjava.tio.http.common.HttpResponse;
import com.litongjava.tio.http.server.annotation.RequestPath;
import com.litongjava.tio.http.server.util.Resps;
@AController
@RequestPath("/admin-api/system/captcha")
@EnableCORS
public class CaptchaController {
@RequestPath("/check")
public HttpResponse check(HttpRequest request) {
HttpResponse response = Resps.json(request, "OK");
return response;
}
}
HttpServerResponseUtils.enableCORS
如果你为了更高的性能可以不使用@EnableCORS,使用 HttpResponseUtils.enableCORS 方法 代码示例
HttpResponse response = Resps.json(request, "OK");
HttpServerResponseUtils.enableCORS(response, new HttpCors());