遇到问题?
第一次写的时候in 关键字后面传的是将List 集合转化为一个这样的字符串,
"'123','23','23'"
@Query(nativeQuery = true, value = "SELECT COUNT(beew.id) AS total FROM `bhpp2.0_evenmngtservice`.`evenmngt_workitem` beew "
+"WHERE beew.thingnum IN(:thingnumListStr) "
+"ORDER BY beew.id DESC"
)
public Object findWorkIteamByThingNumListTotal(@Param("thingnumListStr") String thingnumListStr);
然后发现不管什么情况下都查不到数据,鼓捣了半天,找到原因我们传的 字符串参数中单引号被spring data jpa 框架给转义了,将单引号转换为普通的字符串。
解决方法其实是想多了,直接传List集合就能找到数据,解析List集合交给spring data jpa 框架去做。
@Query(nativeQuery = true, value = "SELECT COUNT(beew.id) AS total FROM `bhpp2.0_evenmngtservice`.`evenmngt_workitem` beew "
+"WHERE beew.thingnum IN(:thingnumList) "
+"ORDER BY beew.id DESC"
)
public Object findWorkIteamByThingNumListTotal(@Param("thingnumList") List<String> thingnumList);