action对应的代码:
private int xueHao;
public String getList() throws Exception
{
xueshengList = dao.getList(xueHao);
return SUCCESS;
}
public int getXueHao() {
return xueHao;
}
public void setXueHao(int xueHao) {
this.xueHao = xueHao;
}
DAOA里代码:
public List getList(int xh)
{
String where="";
if(xh!=0)
{
where=where+" where xueHao="+xh+"";
}
return this.findAll(where);
}
findAll方法:
private List<Xuesheng> findAll(String where)
{
Session sess = this.getSessionFactory().openSession();
try
{
Query query = sess.createQuery(" From Xuesheng " + where + " order by id ");
return query.list();
}
finally
{
sess.close();
}