簡體   English   中英

Spring jpa查詢未獲取

[英]Spring jpa query not fetching

我需要使用 spring 數據 jpa 執行此查詢

select substring_index(date_time,' ',1) as date, number,msg,type 
   from sms  where substring_index(date_time,' ',1) 
   between ("parameter1") and ("parameter2") and type=("parameter3")";

我定義的java方法如下:上面的查詢應該采用下面的三個參數來獲取所需的數據

public List<Sms> findByDateContainingAndNumberAndMsgAndType( 
                                         String startDate, String endDate,String type);

我如何使用 spring 數據 jpa 來做到這一點?

在這里,您需要根據查詢返回 2 個以上的字段,因此您需要使用該對象來收集所有值。

很可能查詢可以返回多行,因此要收集它們,我們需要使用List

所以在你的控制器中包含這樣的東西

    @PostMapping("/endpoint")
    public String search(Model model) {
        List<fill_sms_entity_class_name_here> list = sms_service.retrieve(parameter1,2,3);
        model.addAttribute("list", list);
        return "index";
    }

現在在您的存儲庫中包含以下代碼

@Query(value="select substring_index(date_time,' ',1) as date, number,msg,type from sms where substring_index(date_time,' ',1) between ?1 and ?2 and type=?3", nativeQuery = true)
List<classname> retrieve(parameter1,2,3);

暫無
暫無

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

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