具体来说,我希望整个控制器发送“Access-Control-Allow-Origin = *”。
我在下面尝试过,但这似乎不起作用:
@Controller
@RequestMapping(value = "/controller/base", headers="Access-Control-Allow-Origin=*")
public class UserController {
@RequestMapping(method = RequestMethod.GET, value = "/blah", produces = application/json")
@ResponseBody
public Map blah(/*...,*/ HttpServletResponse response, HttpServletRequest request) throws Exception {
//...
}
}
它仅在我像这样明确设置(在所有方法中)时才有效:
response.addHeader("Access-Control-Allow-Origin", "*");
有什么方法可以在一个地方为一个或多个控制器设置这个?