在pom文件中添加下面三种依赖jar包
1 <dependency> 2 <groupId>com.fasterxml.jackson.core</groupId> 3 <artifactId>jackson-annotations</artifactId> 4 <version>2.9.8</version> 5 </dependency> 6 <dependency> 7 <groupId>com.fasterxml.jackson.core</groupId> 8 <artifactId>jackson-core</artifactId> 9 <version>2.9.8</version> 10 </dependency> 11 <dependency> 12 <groupId>com.fasterxml.jackson.core</groupId> 13 <artifactId>jackson-databind</artifactId> 14 <version>2.9.8</version> 15 </dependency>
spring.xml中加入以下bean
1 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> 2 <property name="messageConverters"> 3 <list> 4 <ref bean="mappingJacksonHttpMessageConverter" /> 5 </list> 6 </property> 7 </bean> 8 <bean id="mappingJacksonHttpMessageConverter" 9 class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 10 <property name = "supportedMediaTypes"> 11 <list> 12 <bean class="org.springframework.http.MediaType"> 13 <constructor-arg index="0" value="text"/> 14 <constructor-arg index="1" value="plain"/> 15 <constructor-arg index="2" value="UTF-8"/> 16 </bean> 17 <bean class="org.springframework.http.MediaType"> 18 <constructor-arg index="0" value="*"/> 19 <constructor-arg index="1" value="*"/> 20 <constructor-arg index="2" value="UTF-8"/> 21 </bean> 22 <bean class="org.springframework.http.MediaType"> 23 <constructor-arg index="0" value="text"/> 24 <constructor-arg index="1" value="*"/> 25 <constructor-arg index="2" value="UTF-8"/> 26 </bean> 27 <bean class="org.springframework.http.MediaType"> 28 <constructor-arg index="0" value="application"/> 29 <constructor-arg index="1" value="json"/> 30 <constructor-arg index="2" value="UTF-8"/> 31 </bean> 32 </list> 33 </property> 34 </bean>
具体这里的bean的意思,后期更新