Spring Boot Long 类型返回前端多了两个零
Spring Boot About 521 words现象
Spring Boot
接口中返回的字段中包含了Long
类型,但前端收到的Long
字段返回值多了两个0
。
解决
给ObjectMapper
添加Long
类型序列化处理器。
@Configuration
public class ObjectMapperConfig {
@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
return objectMapper;
}
}
Views: 916 · Posted: 2024-04-13
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...