我有这样的存储库:
public interface ApartmentRepository
extends PagingAndSortingRepository<Apartment, Long> {
Page<LandlordPageApartment> findAllByOwnerId(long ownerId, Pageable pageable);
}
当我使用它时,会有一个例外:org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [Apartment] to type [LandlordPageApartment]
在这里定义我的转换器:
@Component
public class ApartmentToLandlordPageApartmentConverter implements Converter<Apartment, LandlordPageApartment> {
@Override
public LandlordPageApartment convert(Apartment apartment) {
// some conversion
}
}
转换器注册:
@Configuration
@EnableWebMvc
public class AbsWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(apartmentToLandlordPageApartmentConverter());
}
@Bean
public ApartmentToLandlordPageApartmentConverter
apartmentToLandlordPageApartmentConverter() {
return new ApartmentToLandlordPageApartmentConverter();
}
// ...
}
我做错了什么?