解决renren-security使用oracle主键问题

分享 未结 1 45
LancCJ
LancCJ 2019-11-04
悬赏:20积分
下载项目,直接配置oracle数据库,在配置文件中使用 id-type: ID_WORKER 模式的主键生成策略,但是出现了错误 错误描述为:前端的Long类型主键最后位数精度不对,变成了00 解决方法在项目新增如下代码,方式是将返回的Long 类型的id以字符串的方式返回 [pre] package io.renren.common.config; 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; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; @Configuration public class JacksonConfig { /** * Jackson全局转化long类型为String,解决jackson序列化时long类型缺失精度问题 * @return Jackson2ObjectMapperBuilderCustomizer 注入的对象 */ @Bean public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { Jackson2ObjectMapperBuilderCustomizer cunstomizer = new Jackson2ObjectMapperBuilderCustomizer() { @Override public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) { jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance) .serializerByType(Long.TYPE, ToStringSerializer.instance); } }; return cunstomizer; } } [/pre]
回帖
  • LancCJ
    LancCJ (楼主)
    2019-11-04
    今天亲测可用无毒无侵入,翻看好多帖子太简单了,这个全面点。
    1 回复