Spring Data Jpa多表动态查询
1、采用原生SQL方式:
sql语句(value)
IF(expr1,expr2,expr3)
如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。IF() 的返回值为数字值或字符串值,具体情况视其所在语境而定。
SELECT * FROM project USER ON project.leader_id = `user`.id LEFT lastweekplan ON project.id = lastweekplan.id WHERE project.deleteflag = '0' and project_status != '5' AND IF (: porjectName IS NULL || : porjectName = '', TRUE, project.`name` = : porjectName ) AND IF (: STATUS IS NULL || : STATUS = '', TRUE, project.project_status = : STATUS ) ORDER BY start_time DESC