feature: 增加了雪花id配置文件,还没有测试

This commit is contained in:
during 2021-06-11 17:15:08 +08:00
parent 9d7b912879
commit 1bae0ca3ca

View File

@ -4,19 +4,26 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/**
* Ming LI
* 当Mybatis plus设置为雪花ID时使用此类会把所有数字返回变为字符串返回适配前端Long型失真问题
*/
@Configuration
public class JacksonConfig {
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder)
@ConditionalOnProperty(value = "mybatis-plus.global-config.dbConfig.idType",havingValue = "ASSIGN_ID")
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder)
{
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
// 全局配置序列化返回 JSON 处理