提交表单后控制台输出语句WARN: [DEPRECATION] Encountered positional parameter near line 1, column 34 in HQL: [from entity.Users where username=? and password=? ]. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.三月 01, 2018 6:34:23 下午 org.hibernate.hql.internal.ast.HqlSqlWalker generatePositionalParameterWARN: [DEPRECATION] Encountered positional parameter near line 1, column 49 in HQL: [from entity.Users where username=? and password=? ]. Positional parameter are considered deprecated; use named parameters or JPA-style positional parameters instead.Hibernate: select users0_.uid as uid1_1_, users0_.username as username2_1_, users0_.password as password3_1_ from USERS users0_ where users0_.username=? and users0_.password=?public class UserDAOImpl implements UsersDAO{
@Override
public boolean usersLogin(Users u) {
// TODO Auto-generated method stub
//创建事物对象
//事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit)
Transaction ts = null;
String hql = "";
try {
Session session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession();
//开启事物
ts =session.beginTransaction();
//hql查询语句
hql = "from Users where username=? and password=? ";
//Query是Hibernate的查询接口,用于从数据存储源查询对象及控制执行查询的过程,Query包装了一个HQL查询语句
org.hibernate.Query query =session.createQuery(hql);
//传递参数
query.setParameter(0, u.getUsername());
query.setParameter(1, u.getPassword());
//调用其中的方法得到结果
List list =query.list();
ts.commit();
if (list.size()>0) {
return true;
} else {
return false;
}
}
catch (Exception ex) {
// TODO: handle exception
//打印异常对象
ex.printStackTrace();
return false;
}
finally{
//释放事物对象资源
if (ts!=null) {
ts=null;
}
}
}
}
public class UsersAction extends superAction implements ModelDriven<Users>{
/**
*
*/
private static final long serialVersionUID = 1L;
private Users user = new Users();
//用户登录动作
public String login() {
UsersDAO udao =new UserDAOImpl();
if (udao.usersLogin(user)) {
return "login_success";
}
else {
return "login_failure";
}
}
@Override
public Users getModel() {
// TODO Auto-generated method stub
return this.user;
}
}
添加回答
举报
0/150
提交
取消