JPA自定义条件查询

 @Query(value = "select a.name,a.name from tablea a left join tableb b on a.id = b.id where if(?1 !='',a.xx=?1,1=1) and if(?2 !='',b.xxx like %?2%,1=1) and a.xxx = ?3",nativeQuery = true)

List query(int deptId,String xxx);

if(?1 !='',a.xx=?1,1=1),当?1不为空时,a.xx=?1,否则1=1。第二个if同理

你可能感兴趣的:(java技术)