数据库查询 带参的两种方式

来源:互联网 发布:昂酷拍卖系统源码 编辑:程序博客网 时间:2024/06/14 05:05
通过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);
0 0
原创粉丝点击