【发布时间】:2019-07-26 12:09:08
【问题描述】:
我正在使用类似的条件是 JPA,我正面临这个问题。
@Query("select new com.tivo.extract.config.model.DTO(s.SourceId, s.SourceName, t.TvsourceLongName) from MyTelevisionSource t join fetch RCMSource s ON s.SourceId = t.SourceId where s.SourceId LIKE ?1% ")
List<DTO> findFilteredSourceList(String seachInput);
如果我使用s.SourceId 就像%?1% --> %searchInput% -> 一样工作
但是对于s.SourceId LIKE ?1% -> searchInput% -> 它不起作用
SourceId DB 中 Long 类型的列。
我遇到了一个异常:
Parameter value [021%] did not match expected type [java.lang.Long (n/a)];
nested exception is java.lang.IllegalArgumentException:
Parameter value [021%] did not match expected type [java.lang.Long (n/a)]
【问题讨论】:
-
也许
SourceId是一个数字而seachInput是一些文本... -
我认为这是因为源 ID 是 Long stackoverflow.com/questions/18462376/like-operator-for-integer
-
@Zorglube,如果我给 s.SourceId 像 %?1%,它可以工作,你能建议如何使用 s.SourceId 像 ?1%,因为我想要帖子搜索。
-
@mohan,你不能在号码上使用
LIKE。在号码上,您可以使用>或=或<。如果 oyu 想做一些LIKE你必须将你的号码转换成一个字符串。
标签: java jpa spring-data-jpa