springboot mybatis获取字段为null时候返回前端不显示
最近nacos微服务项目mybatis获取字段为null时候返回前端不显示,这不是我想要的结果。我想要结果无论null还是空字段串都给前端返回字段。
废话少说,直接干货。
@Configuration
@EnableWebMvc
public class GlobalResourceConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//定义一个convert转换消息的对象
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//添加fastjson的配置信息
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setCharset(StandardCharsets.UTF_8);
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.WriteMapNullValue);//主要看这行代码
//处理日期时间格式化问题
fastJsonConfig.setDateFormat("yyyy-MM-dd hh:mm:ss");
//处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON);
//在convert中添加配置信息.
fastConverter.setSupportedMediaTypes(fastMediaTypes);
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
stringHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
converters.add(stringHttpMessageConverter);
fastConverter.setFastJsonConfig(fastJsonConfig);
//将convert添加到converters中
converters.add(fastConverter);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/script/**").addResourceLocations("classpath:/script/");
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
本文来自博客园,作者:星星之草%,转载请注明原文链接:https://www.cnblogs.com/zhaodefu/p/16384655.html