SpringMvc 支持 jsonP

来源:互联网 发布:新加坡 北京 知乎 编辑:程序博客网 时间:2024/05/16 07:53

原理:http://blog.csdn.net/z69183787/article/details/52290032


1、基于Controller 注解

Advice:

@ControllerAdvice(annotations = RestController.class)public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {    public JsonpAdvice() {        super("callback","jsonp");    }}

controller:

@RestController@RequestMapping("/api")public class ApiController {}


2、基于包名

Advice:xxxxx包名下的所有Controller,且返回为 responseBody

@ControllerAdvice(basePackages = "com.xxxxxxx")public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {    public JsonpAdvice() {        super("callback", "jsonp");    }}


controller:

@Controller@RequestMapping("/api")public class ApiController {}


0 0