pagehelper

Pagehelper使用教程

本秂侑毒 提交于 2020-01-01 02:51:56
为什么使用pagehelper? 在使用mybatis进行分页时,要么需要编写sql进行分页,要么需要对结果集进行分页操作,当功能复杂之后,不方便拓展以及复用。pagehelper使用时,不需要去关心怎么实现的分页操作,你只管给它参数就好,同时也方便前端获取数据。 依赖 <!-- pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency> 配置文件application.properties #pagehelper pagehelper.helperDialect=postgresql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql 代码 /** * 分页请求入参对象 */ public class PageRequest { /** * 当前页码 */ private Integer pageNum; /** * 每页数量 */ private Integer

分页查询

断了今生、忘了曾经 提交于 2019-12-30 19:16:12
分页查询 <1>前端页面(使用ElementUI) <div class="filter-container"> <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input> <el-button @click="_findPage()" class="dalfBut">查询</el-button> </div> <div class="pagination-container"> <el-pagination class="pagiantion" @current-change="handleCurrentChange"//currentPage 改变时会触发 :current-page="pagination.currentPage"//当前页码 :page-size="pagination.pageSize"//每页显示几条数据 layout="total, prev, pager, next, jumper"//组件布局 :total="pagination.total">//总记录数 </el-pagination> <

mybatis-plus后出现ClassNotFoundException: org.mybatis.logging.LoggerFactory

雨燕双飞 提交于 2019-12-30 18:03:47
因引入mybatis-plus,和之前的pagehelper冲突, 解决如下: <!-- spring boot 整合pagehelper依赖 版本有兼容性问题 第一种方式依赖的包--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </exclusion> </exclusions> </dependency> 其中如下配置是新增: <exclusion>

springboot整合postgresql

两盒软妹~` 提交于 2019-12-28 15:48:52
依赖 <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> </dependency> 配置application.properties spring.datasource.url=jdbc:postgresql:/

pageHelper分页

徘徊边缘 提交于 2019-12-28 11:22:53
package com.example.controller;import com.example.entity.User;import com.example.service.UserService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controllerpublic class UserController {

Springboot整合pagehelper分页

我与影子孤独终老i 提交于 2019-12-28 11:22:39
一、在pom中添加依赖 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.2</version> </dependency> 二、使用 网络上很多文章都会说需要在application.properties进行配置 其实完全不需要,默认的设置就已经满足大部分需要了直接使用即可 @RequestMapping(value = "/getAllComtents",method = RequestMethod.GET) @ResponseBody public CommonReturnType getAllComtents(@RequestParam(defaultValue="1",required=true,value="pageNo") Integer pageNo){ //每页显示记录数 Integer pageSize=4; //分页查询 PageHelper.startPage(pageNo, pageSize); List<ContentsImagesModel> contentsImagesModels = contentsService.getAllContents();

SpringBoot+MyBatis多数据源使用分页插件PageHelper

[亡魂溺海] 提交于 2019-12-28 11:22:06
之前只用过单数据源下的分页插件,而且几乎不用配置。一个静态方法就能搞定。 PageHelper.startPage(pageNum, pageSize); 后来使用了多数据源(不同的数据库),PageHelper分页插件需要设定一个默认的数据库,mysql、oracle或者其他。但是又不能实时切换,导致请求的第一个类型数据库的请求都可以继续请求,而其他的数据库的请求因为sql语句在不同数据库的count和分页语句不同报错。解决思路是①配置先配置多数据源,再配置多个SqlSessionFactory使用不同的数据源,SqlSessionFactory同时指定某些dao层接口(或者mapper),此时不同的dao层就可以访问不同数据源②在每个SqlSessionFactory中配置一个分页插件第一步骤中的多数据源配置很多博文都有记录,在此不再重复写,我配置的时候参考的是这个链接 http://blog.csdn.net/neosmith/article/details/61202084 他提供了一个多数据源手动配置,一个自动配置方案。因为我们要在多数据源下另外配置分页插件,所以选用手动配置方案。 重点讲第二步骤:一、多数据源下配置分页插件  如果你使用的上边的配置方案,那么你现在应该有多个SqlSessionFactory的bean。我们重点来看某个SqlSessionFactory

Springboot整合pagehelper分页

坚强是说给别人听的谎言 提交于 2019-12-28 11:21:50
一、添加依赖 查找maven中pagehelper的版本 在pom中添加依赖 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.2</version> </dependency> 二、使用 网络上很多文章都会说需要在application.properties进行配置 其实完全不需要,默认的设置就已经满足大部分需要了 直接使用即可 @RequestMapping(value = "getApps.do") public String getApps(Apps apps) { PageHelper.startPage(apps.getPageNum(), apps.getPageSize()); ArrayList<Apps> appsList = appsService.getApps(apps); PageInfo<Apps> appsPageInfo = new PageInfo<>(appsList); return JSON.toJSONString(appsPageInfo); } PageHelper.startPage(需要显示的第几个页面,每个页面显示的数量);

springboot集成mybatis

守給你的承諾、 提交于 2019-12-26 17:10:33
一.springboot继承mybatis的相关说明: springboot是一款基于spring的框架,springboot能较快的搭建web工程和tomcat服务器,提高搭建环境和开发环境的效率,所以使用的越来越多,springboot也能和mybatis集成 mybatis是一款持久层框架,基于spring-jdbc,所有的持久层框架都是基于数据库的jdbc,所以导入mybatis的包后就不需要再导入jdbc的相关包,在这里我们的配置文件使用的是yml文件也可以使用以properties后缀结尾的配置文件,通过springboot集成mybatis,不需要配置额外的sqlSessionFactoryBean,mybatis基于springboot的底层已经帮我们实现了sqlSessionFactoryBean的创建,springboot中有一个自动导入配置文件的标签,这个标签以选择器的方式导入写入 spring.factoties中的配置类: @EnableAutoConfiguration 开启自动配置功能,通过一个AutoConfigurationImportSelector导入选择器去扫描 spring-boot-autoconfigure-2.0.5.RELEASE.jar 自动配置包下面的 spring.factories 文件中的很多很多的自动配置的类 如

Spring Boot使用插件PageHelper分页查询

岁酱吖の 提交于 2019-12-24 23:21:12
分页查询详细记录 1. 在pom.xml引入maven依赖 可到仓库https://mvnrepository.com/查看最新依赖 2. 在application.properties添加配置 pagehelper.helper-dialect=mysql pagehelper.reasonable=true pagehelper.support-methods-arguments=true pagehelper.params=count=countSql 3. 在service以及impl也写上相关方法: public interface EmployeeService { PageInfo < Employee > findAllEmployeeByPage ( int pageNum , int pageSize ) ; } @Override public PageInfo < Employee > findAllEmployeeByPage ( int pageNum , int pageSize ) { PageHelper . startPage ( pageNum , pageSize ) ; List < Employee > lists = employeeDao . selectPage ( ) ; PageInfo < Employee >