1、要实现jpa分页管理首先得要正确配置jpa环境,在spring环境中的配置如下:

开启注解功能

<bean

class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />



<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"

destroy-method="close">

<property name="driverClass" value="com.mysql.jdbc.Driver" />

<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/bus" />

<property name="user" value="root" />

<property name="password" value="root" />

<property name="minPoolSize" value="3" />

<property name="maxPoolSize" value="30" />

<property name="initialPoolSize" value="3" />

<property name="maxIdleTime" value="25000" />

<property name="acquireIncrement" value="1" />

<property name="acquireRetryAttempts" value="30" />

<property name="acquireRetryDelay" value="1000" />

<property name="testConnectionOnCheckin" value="true" />

<property name="idleConnectionTestPeriod" value="18000" />

<property name="checkoutTimeout" value="3000" />

</bean>

<bean id="myEmf"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<property name="dataSource" ref="dataSource"></property>

<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"></property>

<property name="packagesToScan" value="com.jjb.domain"></property>

<property name="persistenceUnitName" value="cml"></property>

<property name="loadTimeWeaver">

<bean

class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />

</property>

</bean>

<bean id="template" class="org.springframework.orm.jpa.JpaTemplate"

scope="prototype">

<property name="entityManagerFactory" ref="myEmf"></property>

</bean>

<!-- 配置事务 -->

<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">

<property name="entityManagerFactory" ref="myEmf" />

</bean>





<tx:annotation-driven transaction-manager="myTxManager" />

还需在src目录下建立META-INF/persistence.xml

具体配置如下:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

version="2.0">

<persistence-unit name="cml" transaction-type="RESOURCE_LOCAL">

<properties>

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />

<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bus" />

<property name="hibernate.connection.username" value="root" />

<property name="hibernate.connection.password" value="root" />

<property name="hibernate.show_sql" value="true" />

<property name="hibernate.hbm2ddl.auto" value="update" />

</properties>

</persistence-unit>





</persistence>

使用时,需要使用JPATemplate进分页功能代码如下:

this.getTemplate().execute(new JpaCallback<List<BusStation>>()

{



public List<BusStation> doInJpa(EntityManager manager)

throws PersistenceException

{

Query query = manager

.createQuery("from BusStation order by id desc");

query.setFirstResult(start);

query.setMaxResults(size);

return query.getResultList();

}

});

JPA 分页处理的更多相关文章

  1. spring data jpa 分页查询

    https://www.cnblogs.com/hdwang/p/7843405.html spring data jpa 分页查询   法一(本地sql查询,注意表名啥的都用数据库中的名称,适用于特 ...

  2. SpringBoot Jpa 分页查询最新配置方式

    这是已经被废弃的接口 Sort sort = new Sort(Sort.Direction.DESC,"bean类中字段"); //创建时间降序排序 Pageable pagea ...

  3. Spring Boot JPA分页 PageRequest报错

    在使用Spring Boot JPA分页 PageRequest分页时,出现如下错误: 本来以为是包导入出现了问题,结果发现并不是.导入包如下: 后来在网上查找相关资料,发现这样的用法,好像也可以用, ...

  4. spring data jpa分页5种方法

    7.12.12 分页 本地sql查询 注意表名啥的都用数据库中的名称, 适用于特定数据库的查询 public interface UserRepository extends JpaRepositor ...

  5. jpa分页

    法一(本地sql查询,注意表名啥的都用数据库中的名称,适用于特定数据库的查询) public interface UserRepository extends JpaRepository<Use ...

  6. JPA分页查询与条件分页查询

    情有独钟的JPA 平时在写一些小项目时,比较喜欢引用 Spring Data Jpa,其实还是图他写代码快~在日常的开发工作中,分页列表查询基本是随处可见,下面一起看一下如何使用 jpa 进行多条件查 ...

  7. SpringBoot JPA + 分页 + 单元测试SpringBoot JPA条件查询

    application.properties 新增数据库链接必须的参数 spring.jpa.properties.hibernate.hbm2ddl.auto=update 表示会自动更新表结构,所 ...

  8. Spring data Jpa 分页从1开始,查询方法兼容 Mybatis,分页参数兼容Jqgrid

    废话少说 有参数可以设置 在org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties 中 /** * Whethe ...

  9. springBoot jpa 分页

    1.jap中有自带的分页方法 在dao层中使用 Page<LinkUrl> findAll(Pageable pageable); 2.在controller层 public List&l ...

随机推荐

  1. 树莓派3b在rt-thread上移植LittlevGL

    树莓派3b在rt-thread上移植LittlevGL 目录 树莓派3b在rt-thread上移植LittlevGL 1.本文概述 2.资源准备 3.上手体验 4.rt-thread与lvgl进行无缝 ...

  2. 2020最新的web前端体系和路线图,想学web前端又不知道从哪开始的快来瞧一瞧呀

    web前端其实是相对于服务器语言是简单的,并且对于初学者是非常友好的,因为在前期学习能够看到很好的效果.但是他的路线 也就是学习体系不成熟,所以导致很多初学者不知道怎么学?下面我就讲讲web前端的体系 ...

  3. sqlilabs less18-22 HTTP头的注入

    less18 user-agent的注入 源码分析: check_input对name,password进行了过滤 function check_input($value) { if(!empty($ ...

  4. sqlliab7-8

    less-7 https://www.jianshu.com/p/20d1282e6e1d ?id=0')) union select 1,'2','<?php @eval($_POST[&qu ...

  5. thinkphp--多表查询

    我们可以将两个表连起来一起查询数据,我现在有两张表,一个是feedback表和member表,如图: 总目录: 上代码: $where = array(); $"; $Model = M(' ...

  6. Visual Studio 添加图标和版本

    在Visual Studio中,如果你创建的是纯C语言的工程,那么给可执行程序添加图标就没有便捷的入口. 但也只是入口不好找了,添加步骤还是比较简单的,以下为具体操作方法:     1. 右键点击C工 ...

  7. Add text to 'Ready Page' in Inno Setup

    https://stackoverflow.com/questions/1218411/add-text-to-ready-page-in-inno-setup

  8. ThinkJS前端搭配vue时的Nginx配置

    Thinkjs 作为奇舞团开源的nodejs mvc框架之一,引起了很多NodeJS程序员的亲赖.但是其关于静态文件处理部分支持不够完善,主要是体现在SPA单页应用,之前在ThinkJS 2.*版本时 ...

  9. js 函数对象的继承 inherit 带 插件完整解析版[helpers.js]

    前言:         本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽.         本篇文章为您分析一下原生JS的对象继承方法 需求分析: 1. ...

  10. Silverlight Tools Beta2更新了中文语言支持

    1,似乎是微软偷偷摸摸更新的......刚才无意间发现,已经下载安装并测试,已在中文版的VS2008安装成功.注意下载页面的安装说明: http://www.microsoft.com/downloa ...