为什么无法查询到数据
- Java code
package com.test.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.test.service.Iservice;public class ListUserAction extends ActionSupport{ private Iservice service; public Iservice getService() { return service; } public void setService(Iservice service) { this.service = service; } @SuppressWarnings("unchecked") @Override public String execute() throws Exception { Map request = (Map) ActionContext.getContext().get("request"); request.put("list",service.listUser()); return SUCCESS; } }- Java code
<s:iterator value="#request.list" id="us"> <tr> <td><s:property value="#us.id"/> </td> <td><s:property value="#us.firstname"/> </td> <td><s:property value="#us.lastname"/> </td> <td><s:property value="#us.age"/> </td> </tr> </s:iterator>
这二段代码有问题吗?不然为什么查询不出任何数据,也没报错,顺便贴出查询代码,看看是否有错。
- Java code
public List<User> listUser() { String hql = "from User user order by user.id desc"; return (List<User>)this.getHibernateTemplate().find(hql); }[解决办法]
Hibernate 配置的是否正确??
[解决办法]
你确定有数据?
[解决办法]
hibernate show_sql参数打开
拿到生成的sql直接去数据库里面查看有数据没
[解决办法]
private Iservice service;
你的service是拿什么管理的?
没有配置还是spring?
你试下Iservice service = new Iservice ();
看看能出来数据不。
[解决办法]
那么你struts.xml里管理了bean
[解决办法]
[解决办法]
要与实体类的hbm.xml的class->name属性对应
[解决办法]
帮不上楼主啊、就帮忙顶下贴吧!~