大家都知道可能前台表单提交后台 ,或者后台 实体类json 序列化到前台可能格式不是我们想要的情况 ,这时候可能就需要上面三个注解来帮忙 ,但是 ,本人在项目使用过程中 使用@JsonField 一直失效 ,百思不得其解 ,难道是 在springboot 不能使用 ?
一番折腾后 ,注入fastjson 的 httpMessageConverter 解决,而之间的在实体类属性上的注解也可以删除了
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190401092350515.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1oxNzgzOTE5Mjk2OQ==,size_16,color_FFFFFF,t_70)
// 格式化前台返回日期格式
@Bean
public HttpMessageConverters fastJsonConfigure() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
//日期格式化
fastJsonConfig.setDateFormat(“yyyy-MM-dd”);
converter.setFastJsonConfig(fastJsonConfig);
return new HttpMessageConverters(converter);