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();
}
findAll方法中
Query query = sess.createQuery(" From Xuesheng " + where + " order by id ");
return query.list();
其实就是:查询出User实体对象所对应的所有数据,而且将数据封装成User实体对象,并且放入List中返回。
改一下这个语句:From Xuesheng " + where + " order by id " 不知道你要查什么字段我用@表示。
把上面的语句改为:select x.@ from Xuesheng as x " + where + " order by id "