通过SQL/HQL语句在数据库中查询数据的时候,往往是需要带条件参数的,带参的方式有如下两种:
一。写在语句里面。例:
String sql = select * from calendar where 1=1 and isdelete = 0 order by add_date desc;
List list = this.getListBySQL(sql, null);
二。写在执行的方法里面。例:
String hql = "FROM TMember t left join fetch t.TMember where (t.email = ? or t.phone = ? or t.account = ?) and t.pwd = ? ";
List<TMember> existList = this.getListByHQL(hql, userName, userName, userName, pwd);
本文介绍了在数据库查询中使用SQL与HQL语句时的两种带参方式:直接在语句中写入参数与在执行方法中传递参数。这两种方式各有优缺点,适用于不同的场景。
1858

被折叠的 条评论
为什么被折叠?



