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 "