我在 Spring boot 中使用 webflux 和資料庫客戶端。我有一個像這樣的字串型別 String status="Quoted,Order,Bought"; 我想在caluse(在哪里)設定這些值。代碼是這樣的。
String status="Quoted,Order,Bought";
@Override
public Flux<Quotation> statusCreatedBy(Pageable pageable, String createdBy,String status) {
RowsFetchSpec<Quotation> list =db.sql("SELECT e.id AS e_id, e.amount AS e_amount, e.description AS e_description FROM quotation e WHERE e.created_by = '" createdBy "' and e.name in ('" status "') LIMIT " pageable.getPageSize() " OFFSET " pageable.getOffset()).map(this::process);
return list.all();
}
我得到了這樣的sql語法。
where e.name in ('Quoted,Order,Bought')
我想要的是
where e.name in ('Quoted','Order','Bought')
請指導我解決這個問題。另外我不知道陣列值的數量。有時狀態可以是 4 或 5 值,具體取決于用戶。例如,
String status='Quoted,Order,Bought,Cancel,Transfer' or Status='Quoted'
謝謝
uj5u.com熱心網友回復:
替換","為"','"使用:
status.replace(",", "','")
所以你的陳述看起來像:
"… and e.name in ('" status.replace(",", "','") "') …"
盡管手工構建 SQL 會起作用,但最好的做法(并且更容易恕我直言)使用庫將變數替換為占位符。考慮使用 JPA、Hibernate 等,.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/443530.html
上一篇:我正在嘗試使用來自同一API的資訊來播種2個表。我填寫了第一個表格,但第二個表格給了我錯誤,盡管有類似的代碼
下一篇:我需要創建3種型別的用戶
