xuanzi 2019-11-03
MYSQL:
@Query(value = "select * from project_demand where project_id=?1 and if(?2!='',demand_id in (select demand_id from demand_user where user_id=?2),1=1)",nativeQuery = true) if(?2!='',demand_id in (select demand_id from demand_user where user_id=?2),1=1),就是生成动态SQL的方法,利用MYSQL的if函数和我们传递的参数去进行判断,然后获取SQL语句
Oracle:
DECODE(VALUE,IF1,THEN1,IF2,THEN2,IF2,THEN2,..,ELSE) 表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else。