如何处理后台向前台传递的json数据

这篇文章主要介绍了如何处理后台向前台传递的json数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

在pom文件中添加下面三种依赖jar包

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-annotations</artifactId>

<version>2.9.8</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-core</artifactId>

<version>2.9.8</version>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-databind</artifactId>

<version>2.9.8</version>

</dependency>

spring.xml中加入以下bean

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">

<property name="messageConverters">

<list>

<ref bean="mappingJacksonHttpMessageConverter" />

</list>

</property>

</bean>

<bean id="mappingJacksonHttpMessageConverter"

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

<property name = "supportedMediaTypes">

<list>

<bean class="org.springframework.http.MediaType">

<constructor-arg index="0" value="text"/>

<constructor-arg index="1" value="plain"/>

<constructor-arg index="2" value="UTF-8"/>

</bean>

<bean class="org.springframework.http.MediaType">

<constructor-arg index="0" value="*"/>

<constructor-arg index="1" value="*"/>

<constructor-arg index="2" value="UTF-8"/>

</bean>

<bean class="org.springframework.http.MediaType">

<constructor-arg index="0" value="text"/>

<constructor-arg index="1" value="*"/>

<constructor-arg index="2" value="UTF-8"/>

</bean>

<bean class="org.springframework.http.MediaType">

<constructor-arg index="0" value="application"/>

<constructor-arg index="1" value="json"/>

<constructor-arg index="2" value="UTF-8"/>

</bean>

</list>

</property>

</bean>

以上是 如何处理后台向前台传递的json数据 的全部内容, 来源链接: utcz.com/z/312152.html

回到顶部