一、配置pon.xml
<!-- fastjson的依賴 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency>
二、配置注入
@Bean public HttpMessageConverters fastJsonMessageConverter() { // 創建FastJson的消息轉換器 FastJsonHttpMessageConverter convert = new FastJsonHttpMessageConverter(); // 創建FastJson的配置對象 FastJsonConfig config = new FastJsonConfig(); // 對Json數據進行格式化 config.setSerializerFeatures(SerializerFeature.PrettyFormat); convert.setFastJsonConfig(config); HttpMessageConverter<?> con = convert; return new HttpMessageConverters(con); }
三、配置application.yml
spring: http: encoding: force: true
四、fastjson注解
@JSONField(format="yyyy-MM-dd HH:mm:ss") // 格式化日期