Java解决跨域的方案

   在后台加上,在数据返回之前添加

        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;
	}
	

  

posted @ 2017-11-02 16:29  xh_Blog  阅读(497)  评论(0编辑  收藏  举报