问题描述
- 为什么我按照学号查询查哪个学号都是查出全部,下边有我的代码,哪位大神会的,求详解求改正谢谢了
- 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 ""
时间: 2025-01-18 11:12:45