日期:2014-05-17  浏览次数:20704 次

为什么无法查询到数据
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
------解决方案--------------------
探讨

原来要用这样访问才能出现数据
http://localhost:8080/s2sh-test/listUser.action
那为什么下面的访问没出数据呢
http://localhost:8080/s2sh-test/list.jsp

------解决方案--------------------
要与实体类的hbm.xml的class->name属性对应
------解决方案--------------------
帮不上楼主啊、就帮忙顶下贴吧!~