如何将我的自定义转换器添加到 mu spring boot 应用程序?我的实体字段
@CreatedDate
@Column(value = "create_time")
private Instant createTime;
我的转换器是
@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();
}
};
}
我有一个例外
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 converting from type [java.lang.Long] to type [java.time.Instant]
........
我该如何解决它,请帮助我!