首页 > 代码库 > 多表分页
多表分页
package cn.com.jgt.irs.dao.web;
import java.util.List;
import org.springframework.stereotype.Repository;
import cn.com.jgt.irs.dao.HibernateBaseDao;
@Repository("webHomePageDaoImpl")
public class WebHomePageDaoImpl extends HibernateBaseDao<Object> implements WebHomePageDao {
@Override
public List<Object> getSearch(int startRow, int pageSize, String keyword) {
System.out.println("进入WebHomePageDaoImpl方法...");
StringBuffer sqlTemp = new StringBuffer();
//FT字段为虚拟字段,表示数据来自哪一张表From Table
sqlTemp.append("SELECT BH, BT, CONTENT, GXSJ, FT FROM ");
sqlTemp.append(" ((SELECT notice.BH BH, notice.BT BT, notice.CONTENT CONTENT, notice.GXSJ GXSJ, ‘notice‘ AS FT FROM notice WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT lzgy.BH BH, lzgy.BT BT, lzgy.MSXQ CONTENT, lzgy.GXSJ GXSJ, ‘lzgy‘ AS FT FROM lzgy WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT industry_info.BH BH, industry_info.BT BT, industry_info.CONTENT CONTENT, industry_info.GXSJ GXSJ, ‘industry‘ AS FT FROM industry_info WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT policy_info.BH BH, policy_info.BT BT, policy_info.CONTENT CONTENT, policy_info.GXSJ GXSJ, ‘policy‘ AS FT FROM policy_info WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT zcxx.BH BH, zcxx.BT BT, zcxx.CONTENT CONTENT, zcxx.GXSJ GXSJ, ‘zcxx‘ AS FT FROM zcxx WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT lzqg.BH BH, lzqg.BT BT, lzqg.CONTENT CONTENT, lzqg.GXSJ GXSJ, ‘lzqg‘ AS FT FROM lzqg WHERE " + keyword + " ) UNION ALL");
sqlTemp.append(" (SELECT user_guide.BH BH, user_guide.BT BT, user_guide.CONTENT CONTENT, user_guide.GXSJ GXSJ, ‘guide‘ AS FT FROM user_guide WHERE " + keyword + " )) AS search");
String sql = sqlTemp.toString();
List<Object> list = getSearchList(sql, startRow, pageSize);
return list;
}
@Override
public int getCount(String keyword) {
StringBuffer sqlTemp = new StringBuffer();
sqlTemp.append("SELECT BH, BT, CONTENT, GXSJ FROM ");
sqlTemp.append(" ((SELECT notice.BH BH, notice.BT BT, notice.CONTENT CONTENT, notice.GXSJ GXSJ FROM notice WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT lzgy.BH BH, lzgy.BT BT, lzgy.MSXQ CONTENT, lzgy.GXSJ GXSJ FROM lzgy WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT industry_info.BH BH, industry_info.BT BT, industry_info.CONTENT CONTENT, industry_info.GXSJ GXSJ FROM industry_info WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT policy_info.BH BH, policy_info.BT BT, policy_info.CONTENT CONTENT, policy_info.GXSJ GXSJ FROM policy_info WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT zcxx.BH BH, zcxx.BT BT, zcxx.CONTENT CONTENT, zcxx.GXSJ GXSJ FROM zcxx WHERE " + keyword + " ) UNION ALL ");
sqlTemp.append(" (SELECT lzqg.BH BH, lzqg.BT BT, lzqg.CONTENT CONTENT, lzqg.GXSJ GXSJ FROM lzqg WHERE " + keyword + " ) UNION ALL");
sqlTemp.append(" (SELECT user_guide.BH BH, user_guide.BT BT, user_guide.CONTENT CONTENT, user_guide.GXSJ GXSJ FROM user_guide WHERE " + keyword + " )) AS search");
String sql = sqlTemp.toString();
int count = getSearchListCount(sql);
return count;
}
}
多表分页