簡體   English   中英

Trim() Function 與 Spring JPA 類似查詢方法

[英]Trim() Function with Spring JPA like Query Methods

我正在制作一個 rest 服務,該服務在內部使用 JPA 來查找帶有前綴的數據(例如:信息前綴)。

我使用 Spring 數據的查詢方法如下所示:

List<Entity> findAllByFieldStartsWithIgnoreCase(String field);

一切正常,但是,數據庫中的數據具有 Information 前綴,但也有空格,如下例所示:

場地:

Information 1
    Information 2
 Information 3
Information 4 

就像您在上面的示例中看到的那樣,信息 1 沒有一些空白,但信息 2 和 3 有一個或多個空白。

I am looking the way to ignore these spaces, I know that sql has the trim function to make it, but in JPA repository with Spring , with query methods, does not exist:

我想找一個 function 來鍵入這樣的查詢方法:

List<Entity> findAllByField  Trim   StartsWithIgnoreCase(String field);

為了在 StartWith 之前執行修剪 function。

我會感謝你的幫助,問候。

您可以使用@Query注釋在此處使用 JPQL 查詢。 例如,下面的代碼片段應該給你一個修剪列的前綴搜索

@Query("select e from Entity e where trim(e.field) like concat(:field,'%')")
List<Entity> findAllByFieldStartsWithIgnoreCase(@Param("field") String field);

這是有關如何將本機/JPQL 查詢與 Hibernate 一起使用的資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM