在Spring MVC 3.2中实现JSONP

编程入门 行业动态 更新时间:2024-10-23 21:38:47
本文介绍了在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

本文发布于:2023-11-24 21:13:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MVC   Spring   JSONP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!