springmvc 支持对象与json 自动转换的配置
2023-09-27 14:24:39 时间
基于maven的工程,
需要在pom.xml中添加如下依赖
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
在springmvc的配置文件中添加如下代码
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
<!--支持对象与json的自动转换--> <mvc:annotation-driven />
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context" xmlns:flow="http://www.springframework.org/schema/webflow-config" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.3.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.3.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <!--关于扫描包的问题https://blog.csdn.net/lhpnba/article/details/77988616--> <context:component-scan base-package="com.hs" > <!--只扫描控制器。 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!--支持对象与json的自动转换--> <mvc:annotation-driven /> <!--对静态资源的处理--> <mvc:resources mapping="/static/**" location="/static/" /> <!-- 视图解析器 --> <!-- <bean class="org.springframework.web.servlet.HandlerInterceptor"></bean> --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> </bean> </beans>
相关文章
- SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
- SpringMVC -- 梗概--源码--贰--异常管理
- SpringMvc学习-4-Spring MVC 拦截器
- SpringMVC学习笔记
- SpringMVC运行流程
- SpringMVC 使用百度Ueditor
- springmvc国际化 基于请求的国际化配置
- spring、springMvc、springBoot和springCloud的联系与区别
- springmvc 日期解决方案(三)使用jackson
- SpringMVC数据库连接配置
- SpringMvc_快速入门,深入分析
- 【springMVC】文件下载
- SpringMVC关于json、xml自动转换的原理研究[附带源码分析 --转