1、使用?通配符
public User validate(String userName, String password) { String hql = "from User u where u.userName = ? and u.password = ?"; User user = null; List<User> list = ht.find(hql, new Object[]{userName, password}); if (list.size()!=0){ user = list.get(0); } return user; }
2、使用键值对应
public User validate(String userName, String password) { String hql = "from User u where u.userName = ? and u.password = ?"; User user = null; List<User> list = ht.find(hql, new Object[]{userName, password}); if (list.size()!=0){ user = list.get(0); } return user; }
Done
Hibernate 带参数查询的两种方式
时间: 2024-10-26 03:16:48