Spring MVC获取客户端传给的json数据
来源:互联网 发布:mysql offset查询优化 编辑:程序博客网 时间:2024/03/29 21:39
Spring MVC获取客户端传给的json数据
@RequestMapping(value = "/postRequest", method = RequestMethod.POST, headers = "Content-Type=application/json")
@ResponseBody
public Object postRequest(HttpServletRequest request) throws IOException {
//表示请求的内容区数据为json数据
InputStream is = request.getInputStream();
byte bytes[] = new byte[request.getContentLength()];//可以得到请求头的内容区数据的长度
is.read(bytes);
//得到请求中的内容区数据(以CharacterEncoding解码)
String jsonStr = new String(bytes, request.getCharacterEncoding());
JSONObject jsonObject = JSON.parseObject(str);
System.out.println("json data:" + jsonStr);
Map<String, Object> map = new HashMap<String, Object>();
map.put("result", "ok");
return map;
}
spring-servlet.xml中配置:
<bean id = "stringHttpMessageConverter" class = "org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id = "formHttpMessageConverter" class = "org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" >
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter"/>
<ref bean="stringHttpMessageConverter" />
<ref bean="formHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json</value>
</list>
</property>
</bean>
- Spring MVC获取客户端传给的json数据
- spring MVC 如何获取客户端post过来的数据。
- AJAX MVC 服务器返回Json数据,客户端获取Json数据
- Spring 4.0.* MVC通过客户端获取JSON数据报406错误
- php的老兄传给客户端[object object]数据如何解析,但他坚称是json...
- 获取JSON数据客户端
- Spring MVC返回json数据的方法
- Spring MVC返回json数据的方法
- spring mvc返回json 类型的 数据
- Spring MVC 对 json数据的处理
- Spring MVC接受JSON格式的数据
- Spring MVC返回JSON格式的数据
- Spring MVC接受JSON格式的数据
- Spring MVC返回JSON格式的数据
- Ajax发送和获取json数据到Spring mvc
- Spring MVC EL ModelAndView传给JSP的值不显示
- Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程
- Android 客户端通过内置API(HttpClient) 访问 服务器(用Spring MVC 架构) 返回的json数据全过程
- Perl笔记:Perl语言入门(第六版) - 智能匹配、given-when
- 看完别人的文章想哭,看到底下的留言更想哭,咋能如此相似
- [DP]HOJ 1316Human Gene Functions
- C#之重构与重载
- RESTful架构风格
- Spring MVC获取客户端传给的json数据
- 【设计模式-外观模式】facade模式
- POJ 1743 后缀数组+分组二分
- 使用share SDK实现人人网授权登录分享(1.x版本)
- SQLQuery接口addScalar方法
- JSONObject与JSONArray的使用
- ORA-03113 ORA-27103: internal error MMAN (ospid: 21061)
- JAVA--将二进制流转换成图片文件
- 导致电脑网速变慢的几个方面