在后台加上,在数据返回之前添加
response.setHeader("Access-Control-Allow-Origin","*");
就可以了,前台不用做任何处理!!!
完整案例如下:
@RequestMapping("xxx") @ResponseBody public Today xxx(@PathVariable Integer id,HttpServletRequest request,HttpServletResponse response ){ request.setAttribute("xxx", xxx); response.setHeader("Access-Control-Allow-Origin","*"); return xxx; }
时间: 2024-10-05 23:14:06