[英]Spring Data Containing doesn't work for Integer
我正在实现搜索方法。 我想搜索整数。 所以我在回购中有这种方法:
public interface CarRepository extends CrudRepository<Car, Long> {
List<Car> findByRocznikIsContaining(Integer rocznik);
}
我的实体:
@Entity
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String model;
private @Lob
String historiaSamochodu;
private Double przebieg;
private Integer rocznik;
但是当我将参数传递给我的方法时,例如:
findByRocznikIsContaining(5);
它抛出一个错误:
java.lang.IllegalArgumentException: Parameter value [%5%] did not match expected type [java.lang.Integer (n/a)]
知道为什么吗?
我已经检查了此链接https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation并为findBy...Containing
它显示了后面的伪SQL代码… where x.firstname like ?1 (parameter bound wrapped in %)
。 在您的情况下,哪个转换为where x.roczik like %5%
。 基本上%5%
是字符串,不能转换为整数。 您可以尝试为该方法使用@Query
注释,如下所示:
@Query("select c from Car c where to_char(c.rocznik) like %?1%")
List<Car> findByRocznikIsContaining(Integer rocznik);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.