码迷,mamicode.com
首页 > 其他好文 > 详细

多表分页

时间:2017-03-23 01:09:38      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:where   osi   sys   bho   com   start   分页   sel   sql   

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;
}

}

多表分页

标签:where   osi   sys   bho   com   start   分页   sel   sql   

原文地址:http://www.cnblogs.com/csy666/p/6602517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!