您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
09-SpringMVC的数据响应-回写数据-返回对象或集合2(更精简的控制器方法返回对应数据类型的json字符串于前端)
发布时间:2024-12-30 17:47:32编辑:雪饮阅读()
-
虽然上篇中用
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
</bean>
这东西解决了控制器中的方法直接返回对应数据类型即可在前端响应对于该数据类型转换为json字符串的结果,但是这个配置毕竟还是有些麻烦不优雅的。
那么还有更优雅的方式。
那么首先是在Spring MVC的配置文件xml中新增名称空间
xmlns:mvc="http://www.springframework.org/schema/mvc"
以及xsi:schemaLocation的值新增两个mvc关联的location
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
然后添加mvc注解驱动于该xml文件中
<mvc:annotation-driven/>
关键字词:SpringMVC,json,jackson,响应,类型
相关文章
- 08-SpringMVC的数据响应-回写数据-返回对象或集合(更
- 07-SpringMVC的数据响应-回写数据-直接回写json格式字
- 06-SpringMVC的数据响应-回写数据-直接回写字符串(直
- 05-SpringMVC的数据响应-页面跳转-返回ModelAndView3(
- 04-SpringMVC的数据响应-页面跳转-返回ModelAndView形
- 03-SpringMVC的数据响应-页面跳转-返回ModelAndView形
- 13-SpringMVC组件解析-SpringMVC的XML配置解析(资源解
- 12-SpringMVC组件解析-SpringMVC组件扫描(SpringMVC配
- 11-SpringMVC组件解析-SpringMVC注解解(限定http请求
- 08-SpringMVC简介-SpringMVC快速入门代码实现(并解决C