编程语言
首页 > 编程语言> > 雪花算法生成id长度过长处理

雪花算法生成id长度过长处理

作者:互联网

思路:将Long类型转成字符串

代码实现:

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JacksonConf {

    /**
     * 自定义序列化类型转换
     * 注:此处解决Long型转换后,前端js损失精度的问题,将Long型转换为字符串类型
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Jackson2ObjectMapperBuilderCustomizer customizer = jacksonObjectMapperBuilder ->
                jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance)
                        .serializerByType(Long.TYPE, ToStringSerializer.instance);
        return customizer;
    }
}

 

标签:过长,Jackson2ObjectMapperBuilderCustomizer,Long,算法,springframework,org,import,ToSt
来源: https://www.cnblogs.com/liaozk/p/16526189.html