SpringMVC自带toJson方法

公司同一类型的项目有两个框架,老版本的要用到toJson,新版本的不需要,直接对象就好了。当时就有点奇怪,就看了下原来MVC利用@ResponseBody注解,在加上把fastjson包直接放到pom文件里引入就好了。

<mvc:annotation-driven>
		<mvc:message-converters>
			<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>application/json;charset=UTF-8</value>
						<value>text/html;charset=UTF-8</value>
						<!--<value>text/json;charset=UTF-8</value>-->
					</list>
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>

贴出公司使用的
pom引入的包:

      <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>fastjson</artifactId>
      </dependency>
      

参考

猜你喜欢

转载自blog.csdn.net/ZCCHZ/article/details/82841824
今日推荐