相关疑难解决方法(0)

R2dbc自定义转换器

如何将自定义转换器添加到 mu spring boot 应用程序?我的实体字段

    @CreatedDate
    @Column(value = "create_time")
    private Instant createTime;
Run Code Online (Sandbox Code Playgroud)

我的转换器是

    @Bean
    public Converter<Long, Instant> longInstantConverter() {
        return new Converter<Long, Instant>() {
            @Override
            public Instant convert(Long source) {
                return Instant.ofEpochMilli(source);
            }
        };
    }

    @Bean
    public Converter<Instant, Long> instantLongConverter() {
        return new Converter<Instant, Long>() {
            @Override
            public Long convert(@NotNull Instant source) {
                return source.toEpochMilli();
            }
        };
    }
Run Code Online (Sandbox Code Playgroud)

我有一个例外

org.springframework.data.mapping.MappingException: Could not read property @org.springframework.data.relational.core.mapping.Column(value=create_time) @org.springframework.data.annotation.CreatedDate()private java.time.Instant com.example.database.model.MyTable.createTime from result set!
.........
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of …
Run Code Online (Sandbox Code Playgroud)

spring-data-r2dbc r2dbc r2dbc-postgresql

8
推荐指数
2
解决办法
1万
查看次数