分页查询

oracle数据库的分页查询语句

隐身守侯 提交于 2019-12-23 22:50:17
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行数 1单表查询 start页面的起始位置,size 为页面要展示的信息个数: SQL语句如下:如果有order by语句,那至少要使用两个子查询 select t.* from ( select tt.id,tt.name,rownum as rwn from ( select id ,name from student order by id ) tt where rownum<10) t where t.rwn>4 2多表查询 多表联合查询可以使用这个语句 ,使用orcle中rownum来控制返回的记录数在多少行到多少行之间。 select * from ( select p.*,rownum rwn from product p inner join productupid pu on p.id=pu.productid where rownum<5 ) where rwn> 2 选择需要的字段,减少网络传输量: select res.id from ( select p.*,rownum rwn from product p inner join

Mybatis的分页插件PageHelper4.1.6的使用

那年仲夏 提交于 2019-12-10 17:41:10
1、引入jar包 这里以maven为例(如果下载jar,还需要下载pageHelper的依赖com.github.jsqlparser): <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.6</version> </dependency> 2、添加配置 在mybatis的全局配置文件里<configuration>标签下添加下面的配置 <!-- plugins在配置文件中的位置必须符合要求,否则会报错,顺序如下: properties?, settings?, typeAliases?, typeHandlers?, objectFactory?,objectWrapperFactory?, plugins?, environments?, databaseIdProvider?, mappers? --> <plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 4.0.0以后版本可以不设置该参数 --> <property name=

hibernate hql 分页查询

耗尽温柔 提交于 2019-11-27 16:46:15
今天封装了自己的hibernateDao,主要是基于hql的,期间遇到一个问题,最后解决了,和大家分享分享 其他hibernate的查询,像QBE,QBC,这些就不说了,如果用hibernate还是hql最强大,也很容易上手 先上代码,这里只列出主要代码 /** * hql分页查询 * * @param hql * 查询字符串 * @param queryResult * 查询结果 * @param values * 查询值 * @return */ @SuppressWarnings("unchecked") public QueryResult hqlQueryPage(final String hql, final QueryResult queryResult, final Map values) { return hibernateTemplate.execute(new HibernateCallback() { @Override public QueryResult doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(hql).setFirstResult( (queryResult