我在 JPA Repository 类中使用 jpql 创建了一个自定义查询。如果 documentText 列包含 :text,则查询将仅返回 DocumentDTO 列表。对于这个操作,我需要执行小写操作。
代码:
@Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
"(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
"FROM Document " +
"WHERE LOWER(documentText) LIKE CONCAT('%', LOWER(:text), '%')")
List<DocumentDTO> findByDocument(@Param("text") String text);
错误:
org.hibernate.QueryException: Parameter 1 of function lower() has type STRING, but argument is of type java.lang.String
我找不到如何将 java.lang.string 类型转换为字符串。我应该这样做吗?请帮我。我2天都无法解决这个错误。
我尝试了这段代码,但没有得到任何结果。
@Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
"(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
"FROM Document " +
"WHERE LOWER(documentText as string) LIKE CONCAT('%'," +
"LOWER(:text as string)" +
",'%')")
List<DocumentDTO> findByDocument(@Param("text") String text);
在调用 findByDocument 方法之前将字符串参数“text”转换为小写
我这样解决了错误。
@Query("SELECT new com.hakstudio.archiveapp.dto.DocumentDTO" +
"(id, name, accessAuth, uploadedDate, uploadedBy, uploadedByTc, editedBy, editedByTc) " +
"FROM Document " +
"WHERE LOWER(" +
"cast(documentText as string)" +
") LIKE CONCAT('%', LOWER(" +
"cast(:text as string)" +
"), '%')")
List<DocumentDTO> findByDocument(@Param("text") String text);