本文介绍了在Spring MVC 3.2中实现JSONP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在Spring MVC的早期版本中可以使用自定义过滤器来实现JSONP.另外,此示例描述了一种通过扩展MappingJacksonHttpMessageConverter类并修改域对象在Spring MVC 3.1中实现JSONP的方法.
I understand that custom filters can be used in earlier version of Spring MVC to implement JSONP. Additionally this example describes a method to implement JSONP in Spring MVC 3.1 by extending the MappingJacksonHttpMessageConverter class and modifying the domain objects.
除了使用上述方法之外,在Spring MVC 3.2中是否有更简单(或常规)的方法来处理JSONP?在Spring 3.2文档中我根本看不到JSONP.
Is there a simpler (or conventional) method to address JSONP in Spring MVC 3.2 besides using the above methods? I did not see JSONP addressed at all in the Spring 3.2 documentation.
推荐答案更简单的方法
@RequestMapping(value = "/jsonp", method = RequestMethod.GET) @ResponseBody public String jsonp(@RequestParam("c")String callBack) throws Exception{ ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> map = new HashMap<String, Object>(); map.put("data", "<p>jsonp data<p>"); return objectMapper.writeValueAsString(new JSONPObject(callBack,map)); }更多推荐
在Spring MVC 3.2中实现JSONP
发布评论