多表分页

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

}

时间: 2024-10-15 15:28:56

多表分页的相关文章

vue.js-列表分页

<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" cont

Oracle优化——单表分页优化

单表分页优化思路: --创建测试表: SQL> create table t_test as select * from dba_objects; Table created. 如,下面的sql (没有过滤条件,只有排序),要将查询结果分页显示,每页显示10条,如: select * from t_test order by object_id; 例子: 1.分页查询sql语句,如下(通常会采用下面的方法,但是这是错误的分页框架) 语法:select * from (select t.*,row

JdbcTemplate+PageImpl实现多表分页查询

一.基础实体 @MappedSuperclass public abstract class AbsIdEntity implements Serializable { private static final long serialVersionUID = 7988377299341530426L; public final static int IS_DELETE_YES = 1;// 标记删除 public final static int IS_DELETE_NO = 0;// 未删除,

mybatis多表分页

mybatis的分页是通过拦截器重新拼接SQL,因此分页语句基本都是包含在整个SQL语句外面,那么对于多表查询就会出现查询结果不准确的结果,A与B为一对多关系,A为主表,当使用链接语句查询A和B时,由于A对应的B可能有多条,因此实际的结果是结果集小于A表查询的结果集,采用如下解决方式: 先通过group by id 得到A表的正确的数据集的ID,然后再降得到的ID作为条件再次查找得到数据集 select a.id from A a left join B b on b.no = a.no whe

Oracle对没有主键的表分页

一般情况对于有主键,能够做唯一表识的表,我们可以利用主键和rownum配合实现,例如: select scott.emp.* from scott.emp left join (select empno id, rownum num from scott.emp) id_num on scott.emp.empno = id_num.id where id_num.num between 5 and 10; 如果遇到没有主键的表可以尝试rowid代替,rowid不会因为排序或者查询,甚至upda

SQL 单表分页存储过程和单表多字段排序和任意字段分页存储过程

  第一种:单表多字段排序分页存储过程       --支持单表多字段查询,多字段排序 create PROCEDURE [dbo].[UP_GetByPageFiledOrder] ( @TableName varchar(50), --表名 @ReFieldsStr varchar(200) = '*', --字段名(全部字段为*) @OrderString varchar(200), --排序字段(必须!支持多字段不用加order by) @WhereString varchar(500)

Hibernate-ORM:17.Hibernate中多表分页携带条件

本次做个简单的多表带条件的分页,多对多,加多对一关联 1.三个实体类 1.1Admin public class Admin { private Integer id; private Set<Notice> noticeSet=new <Notice>HashSet(); //get/set方法 } 1.2Notice通知 public class Notice { private int id;//流水好噢 private String texts;通知内容 private i

SQLServer多表联查,多表分页查询

多表联查: select p.*,s.Sheng , i.Shifrom  [dbo].[ProductRecordInfo]   --表名 p left join [ShengInfo] s on p.ShengInfo = s.ShengId   --使用left join左连接 让两个表中的指定字段产生连接关系left join [ShiInfo] i on p.ShiInfo = i.ShiId          --使用left join左连接 让三个表中的指定字段产生连接关系 这里的

高效多表分页存储过程,可支持多表查询,任意排序

废话不多说,直接上代码: SQL存储过程: CREATE PROCEDURE usp_PagingLarge @TableNames VARCHAR(200), --表名,可以是多个表,但不能用别名 @PrimaryKey VARCHAR(100), --主键,可以为空,但@Order为空时该值不能为空 @Fields VARCHAR(4000), --要取出的字段,可以是多个表的字段,可以为空,为空表示select * @PageSize INT, --每页记录数 @CurrentPage I