/**
* 因为Long类型id数据传递到前端之后失去精度导致id值发生了改变
* 配置全局处理,Long类型转String再返回到前端
* @author Mr peng
*/
@Configuration
public class JackSonConfig {
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(Long.class,ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
return objectMapper;
}
}
//当然也可以在对应的属性上面加上如下注解来解决
@JsonFormat(shape = JsonFormat.Shape.STRING)