fastjson替換springMVC官方Jackson,代替message-converters

spring-mvc.xml

<mvc:annotation-driven>
	<mvc:message-converters register-defaults="true">
		<!-- 配置Fastjson支持 -->
		<ref bean="jsonHttpMessageConverter" />
	</mvc:message-converters>
</mvc:annotation-driven>
<bean id="jsonHttpMessageConverter"
	class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
	<property name="supportedMediaTypes">
		<list>
			<value>text/html;charset=UTF-8</value>
			<value>application/json</value>
		</list>
	</property>
	<property name="features">
		<list>
			<!--設置null值也要輸出,fastjson默認是關閉的 -->
			<!-- <value>WriteMapNullValue</value> -->
			<!--設置使用文本方式輸出日期,fastjson默認是long -->
			<value>WriteDateUseDateFormat</value>
		</list>
	</property>
</bean>
總結一下這個問題  就是springMVC  json插件官方用的 jackson  如果要時間轉換的話 要在每個date字段上都加上註解   顯得很麻煩   換成fastjson之後  只需要配置features  WriteDateUseDateFormat就能自動格式化時間戳爲yyyy-mm-dd hh24:mi:ss 然而 這個對數據庫字段要求比較精確,必須是timestamp(oracle),其他數據庫相應也應該差不多,如果是date的話,格式化出來自動就剪掉時分秒了 變成yyyy-mm-dd 00:00:00

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章