java Long型数据返回到前端失进度问题解决

直接在springmvc配置中增加信息转换。亲测可用。简单粗暴

@Override
public void configureMessageConverters(List> converters) {
    MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
    ObjectMapper objectMapper = new ObjectMapper();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
    simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
    objectMapper.registerModule(simpleModule);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);//忽略未知字段
    jackson2HttpMessageConverter.setObjectMapper(objectMapper);
    converters.add(jackson2HttpMessageConverter);
}

如果对以上代码。不太清楚的。可以翻看下,springmvc的HttpMessageConvert。括号需要实现WebMvcConfigurer去增加信息转换

你可能感兴趣的:(java,前端,开发语言)