SpringMVC-day03(JSON&FastJson&数据校验)
目录:
第一章 SpringMVC与JSON交互
第二章 FastJson
1.7 SpringMVC集成FastJson
第一章 SpringMVC与JSON交互
概述:json数据是企业级开发数据交互经常使用的一种方式,它比较轻量级,格式比较清晰。
数据交互:前后端的互动
前端传递json字符串,后台转换成pojo对象
后台返回pojo对象,前端接收成json格式字符串。
这就需要序列化工具,市面上常用的进行JSON序列化和反序列化的工具有:FastJson、JackSon、Gson.
注意:SpringMVC默认使用JackSon进行JSON序列化和反序列化
第二章 FastJson
1.7 SpringMVC集成FastJSON
SpringMVC框架中,默认使用的json序列化工具是jackson,我们需要在SpringMVM的配置文件中,配置消息转换器,由jackson切换到FastJson.
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=utf-8value>
list>
property>
bean>
mvc:message-converters>
mvc:annotation-driven>