现在需要在页面中显示user表中的信息,其中一个状态属性并不在user表中,而是从请假表leave和外出表workout中查询,我现在就是想点击查询按钮时能够获取该员工处于什么状态~~用到hibernate,具体该怎么实现啊~~,新手还请各位高人请教,页面中是:  <td class="tableInfonoIndent" style="" id="td_staffStatus_<ww:property value="id"/>" title="<ww:property value="staffStatus"/>" >
   <div class="nowrapDiv" style="width:80px;" id="td_<ww:property value="id"/>">
    <input type="button" id="<ww:property value="id"/>" onClick="findStatusById('<ww:property value="id"/>');" name="xxxx" value="查询"  title="查询" style="cursor:pointer"/>
   </div>
     </td> 

解决方案 »

  1.   

    1. 获取userId.2. String hql = "select top 1 * from leave where userId = "+userId+" order by lid  desc";
       //获取用户最后一次请假记录.3. String hql = "select top 1 * from workout where  userId = "+userId+" order by wid desc";
       //获取用户最好一次外出记录.4. 另外一种方法: 把用户表和外出表配置成一对多的关系.
       吧用户表和请假表配置成一对多的关系.
      

  2.   

    是这一种~~
    在hql中,如何比较当前时间和数据表中的endtime,因为要判断是否仍在请假范围内
      

  3.   

    请请假范围是在那个范围,endtime 是 leave 表中的什么字段.
      

  4.   

                    List<Staff> statusList01 ;//staff是用户表,因为用到left join,不知道类型是不是该这样写
    List<Staff> statusList02 ;
    int status = 0;
    String currentDate = new SimpleDateFormat("HH:mm E").format(new Date());//这个我不知道写得对不对,目的是比较时间
    StringBuffer hql01 = new StringBuffer("select id from Staff left join workOutBills as wo where wo.id==statusId and wo.endTime >= '");//statusId是用户的ID
    hql01.append(currentDate).append("'");//外出表
    StringBuffer hql02 = new StringBuffer("select id from Staff left join leaveBills as lb where lb.id==statusId and lb.endTime >= '");
    hql02.append(currentDate).append("'");//请假表
    statusList01 = this.find(hql01.toString());
    statusList02 = this.find(hql02.toString());
    if(statusList01.size() == 0 || statusList02.size() == 0)
    status = 1;//都没有暂且返回一个标志1
    else if(statusList01.size() != 0)
    status = 2;
    else status =3;
    return status;
    刚学,不妥之处还请指教~
      

  5.   

    这三个表是主外键关系撒,你只要写一个简单的查询语句就可以得到所有数据啊。你不是在用hibernate嘛。你只要查一张表,相关联的表数据都会查出来。查出来后,你根据表关系取值就行了。不用你上面那种去法。 
    <input type="password" name="user.upass" id="upass" size="20" style="width: 90px">
      

  6.   

    用hibernate你还要分开这样查 ,那你用hibernate做啥子?
      

  7.   

    昨天刚看过hql的东西,hibernate就更不用提了~
      

  8.   

    时间对象可以作为条件来比较的;比如:Date date = new Date();String hql = "from XXX x where x.date>'"+date+"'";
      

  9.   

    把请假表leave和外出表workout作为用户form的属性,然后在配置文件中
    配置成映射关系 用 many one
      

  10.   

    这个问题:貌似我已经答过N次啦!用HIBERNATE的构造方法查询!! hql:select new User(你需要嘎字段) from User,Leave,WorkOut where 条件!但是你一定要在你的pojo USER中加上你的构造方法!!
      

  11.   

       你一定是知道怎么实现,而不知道怎么解析是吧.
       你可以用session.createSqlQuery("在这里面写sql语句").list;
       此时 就会把你想要的字段全部装Object[]数组里面,(每一个Object[]代表着一行数据)所有的行数据
       又被封装在list里面.   这样可以解析出来;
       Object obj[] = null; 
       List list(Object obj[]) = session.createSqlQuery("在这里面写sql语句").list;
      for(int i = 0 ; i<list.size() ; i++){
       obj = list.get(i)
         for(int j = 0 ; j<obj.lenght ; j++){
          obj[j]; //此时这里的obj[j]就可以把你想要的东西解析出来    }
        
      }