SSH集成项目开发中,怎样将Hibernate查询到的数据插入到另一张表中,控制层用的是Struts2.跪求大神指点……

package com.xinhua.rmp.push.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.xinhua.rmp.common.BaseSessionFactory;
import com.xinhua.rmp.common.Pager;
import com.xinhua.rmp.push.bean.AppDevice;
import com.xinhua.rmp.push.dao.AppDeviceDao;
import com.xinhua.rmp.push.domain.AppDeviceQueryConditions;

public class AppDeviceDaoImpl extends BaseSessionFactory implements AppDeviceDao  {

  @Override
  public int add(AppDevice info) {
    return (Integer) super.add(info);
  }

  @Override
  public boolean delete(int id) {
    return (Boolean) super.deleteById(AppDevice.class, id);
  }

  @Override
  public boolean update(AppDevice info) {
    return (Boolean)super.update(info);
  }


  @Override
  public List<AppDevice> query(AppDeviceQueryConditions conditions, Pager pager) {
    String hql = null;
    String totalCountHql = null;
    List<Object> list = new ArrayList<Object>();
    if(conditions.getMessageId().equals("")){
      hql = "from AppDevice where 1=1";
      totalCountHql = "select count(*) from AppDevice where 1=1";
    }else 
      if(conditions.getMessageId().equals("-1")){
      hql = "from AppDevice where 1=1";
      totalCountHql = "select count(*) from AppDevice where 1=1";
    }else{
      
      hql = "from AppDevice where appId in(select appId from Message where id ="+conditions.getMessageId()+")";
      totalCountHql = "select count(*) from AppDevice where appId in(select appId from Message where id ="+conditions.getMessageId()+")";
    }
      Object[] params = list.toArray();
      pager.setTotalNum(super.getTotalCount(totalCountHql, params));
      return super.query(hql, pager, params);
  }
}

我的意思就是将上边的查询结果,插入到下面的数据表中。

package com.xinhua.rmp.push.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.xinhua.rmp.common.BaseSessionFactory;
import com.xinhua.rmp.common.Pager;
import com.xinhua.rmp.push.bean.Message;
import com.xinhua.rmp.push.bean.PushDevice;
import com.xinhua.rmp.push.dao.MessageDao;
import com.xinhua.rmp.push.domain.MessageQueryConditions;
import com.xinhua.rmp.smp.bean.Device;

public class MessageDaoImpl extends BaseSessionFactory implements MessageDao  {

  @Override
  public int add(Message info) {
    return (Integer) super.add(info);
  }

  @Override
  public boolean delete(int id) {
    return (Boolean) super.deleteById(PushDevice.class, id);
  }

  @Override
  public boolean update(Message info) {
    return (Boolean)super.update(info);
  }

  @Override
  public List<Message> query(MessageQueryConditions conditions, Pager pager) {
    
    String hql = null;
    String totalCountHql = null;
    List<Object> list = new ArrayList<Object>();
    
    
    if(conditions.getAppId().equals("")){
      hql = "from Message where 1=1";
      totalCountHql = "select count(*) from Message where 1=1";
      
    }else
      if(conditions.getAppId().equals("-1")){
      hql = "from Message where 1=1";
      totalCountHql = "select count(*) from Message where 1=1";
    }else{
      
      hql = "from Message where appId = '"+conditions.getAppId()+"'";
      totalCountHql = "select count(*) from Message where appId ='"+ conditions.getAppId() +"'";
    }
    Object[] params = list.toArray();
    pager.setTotalNum(super.getTotalCount(totalCountHql, params));
    return super.query(hql, pager, params);      

  }
  

}


评论

最新评论(7

Alyce
2015/01/06 17:35  
回复 @糖咖啡 : 我知道啊,不过现在问题解决了,我们优化了下数据库,问题就变得简单多了
Alyce
2015/01/06 17:33  
回复 @JacarriChan : 88No,做数据展现
JacarriChan
2015/01/05 22:40  
做数据审计?
爱喝貓的咖啡
2015/01/05 17:16  
@Alyce insert select 是一条mysql语句。
不知所措ii
2015/01/05 17:14  
用程序控制就是查出AppDevice模型以后赋值到Message模型的成员变量中然后通过DAO的add插入 如果用sql一步搞定 看下他们的字段是否是一致的 如果一致 就insert (Message) into (select AppDevice) 这种可以插入
Alyce
2015/01/05 17:11  
回复 @糖咖啡 : 我知道插入用insert,但是在整个业务中怎样插不太清楚?就是不知道 insert 在那个位置去进行插入?
爱喝貓的咖啡
2015/01/05 17:08  
这种东西,最好考虑sql方言,比如mysql的insert select。

没有更多内容

加载失败,请刷新页面

没有更多内容

返回顶部
顶部