如何使用hibernate选择数据?
我正在使用SpringMVC和Hibernate。我使用Hibernate编写insert,但找不到从数据库中写入搜索数据的方法。我在下面的例子中插入了一个我喜欢的过程。如何使用SessionFactory自动连线对象写入select 我想使用Hibernate执行如何使用hibernate选择数据?,hibernate,Hibernate,我正在使用SpringMVC和Hibernate。我使用Hibernate编写insert,但找不到从数据库中写入搜索数据的方法。我在下面的例子中插入了一个我喜欢的过程。如何使用SessionFactory自动连线对象写入select 我想使用Hibernate执行select*from employee where username='hesh' @Repository public class EmployeeDaoImpl implements EmployeeDAO{ @Autowir
select*from employee where username='hesh'
@Repository
public class EmployeeDaoImpl implements EmployeeDAO{
@Autowired
private SessionFactory sessionFactory;
@Override
public void AddEmployee(Employee employee) throws ClassNotFoundException, SQLException {
this.sessionFactory.getCurrentSession().save(employee);
}}
尝试使用以下方法:
@Override
public List listEmployee(String username) throws Exception{
Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Employee.class)
.add(Restrictions.eq("username", username));
criteria.setMaxResults(10);//optionally set max return rows.
return criteria.list();
}}