第一种:
/**
* 判断是否为操作员
*
* @param operatorName 操作员名称
* @param operatorPsw 操作员密码
* @return 返回操作员,不存在返回空
*/
public Operator isOperator(String operatorName, String operatorPsw) {
Operator operator = null;
Session session = getSession();
String hql = "from Operator o where o.operatorName=? and o.operatorPwd=?";
Query query = session.createQuery(hql);
query.setParameter(0, operatorName);
query.setParameter(1, operatorPsw);
List list = query.list();
if (list.iterator().hasNext()) {
operator = (Operator) list.iterator().next();
}
return operator;
}
第二种:
/**
* 判断是否为操作员
*
* @param operatorName 操作员名称
* @param operatorPsw 操作员密码
* @return 返回操作员,不存在返回空
*/
public Operator isOperator(String operatorName, String operatorPsw) {
Operator operator = null;
Session session = getSession();
String hql = "from Operator o where o.operatorName='" + operatorName + "' and o.operatorPwd='" + operatorPsw + "'";
Query query = session.createQuery(hql);
List list = query.list();
if (list.iterator().hasNext()) {
operator = (Operator) list.iterator().next();
}
return operator;
}