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: 557 · Posted: 2024-04-13

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh