您的位置:首页 > 编程语言 > Java开发

Spring 返回Json

2016-06-02 00:00 330 查看
需要 jackson-annotations.jar,jackson-core.jar,jackson-databind.jar

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>


@RequestMapping(value = "regist", method = RequestMethod.POST)
@ResponseBody
public Object regist(@RequestBody UsersEntity usersEntity) {
/*System.out.println(usersEntity.toString());
UsersEntity users =  new UsersEntity("zzyo","zzyo","1111@qq.com","1111");
User newuser = new UserImpl();
System.out.println(newuser.register(users));*/
String code = doRegister(usersEntity);
System.out.println(code);
Map map=new HashMap();
map.put("code", code);
return map;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: