3 回答

TA貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
制作2個(gè)單獨(dú)的方法
@Query(value = "select * from Products p where type = 'L' and active =
1 and ?1 is null or p.pNum =?1", nativeQuery = true)
public List<Products> findAllParties(String productNumber);
@Query(value = "select * from Products p ", nativeQuery = true)
public List<Products> findAllParties();

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果您想要有條件地構(gòu)建查詢,請使用 JPACriteria API
或 Spring 的Specifications API
.

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
select * from Products p where req_param is null or ( type='L' and active=1)
因?yàn)槿绻?req_param 為 null 它將對所有行都為真,因此將帶來所有記錄。如果 req_param 不為空/空條件“req_param is null”將為 false,并且僅基于“(type='L' and active=1)”返回行
添加回答
舉報(bào)