SpringBoot与PageHelper的整合示例详解

1.PageHelper简介

PageHelper官网地址:

https://pagehelper.github.io/

摘要: com.github.pagehelper.PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件。

PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件,其实我并不想加上好用两个字,但是为了表扬插件作者开源免费的崇高精神,我毫不犹豫的加上了好用一词作为赞美。

原本以为分页插件,应该是很简单的,然而PageHelper比我想象的要复杂许多,它做的很强大,也很彻底,强大到使用者可能并不需要这么多功能,彻底到一参可以两用。但是,我认为,作为分页插件,完成物理分页任务是根本,其它的很多智能并不是必要的,保持它够傻够憨,专业术语叫stupid,简单就是美。

我们将简单介绍PageHelper的基本使用和配置参数的含义,重点分析PageHelper作为Mybatis分页插件的实现原理。

2.SpringBoot与PageHelper的整合示例

结构图如下:

pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.home</groupId>
<artifactId>springbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>springbootdemo</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <!--mybatis与mysql-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--druid依赖-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.25</version>
</dependency>
<!--redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> <!--pageHelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency> <!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> <!-- 热部署模块 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build> </project>
OrderPresentController:
package com.home.orderpresentdemo.controller;

import com.github.pagehelper.PageInfo;
import com.home.orderpresentdemo.entity.OrderPresentInfo;
import com.home.orderpresentdemo.service.OrderPresentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import java.util.HashMap;
import java.util.List;
@Controller
@RequestMapping("/")
public class OrderPresentController { @Autowired
private OrderPresentInfoService orderPresentService; /**
* 跳转到应用列表页面
* @param pageNo 要显示第几页内容
* @param pageSize 一页显示多少条
* @return
*/
@RequestMapping("/list")
@ResponseBody
public PageInfo<OrderPresentInfo> list(@RequestParam(value="pageNo",defaultValue="1")int pageNo, @RequestParam(value="pageSize",defaultValue="10")int pageSize) {
PageInfo<OrderPresentInfo> page = orderPresentService.getAllOrderPresentForPage(pageNo,pageSize);
return page;
} @RequestMapping("/")
public String helloHtml(HashMap<String, Object> map, Model model) {
model.addAttribute("say","欢迎欢迎,热烈欢迎");
map.put("hello", "欢迎进入HTML页面");
return "index";
} @RequestMapping("/goToAdd")
public String goToAdd() {
return "add";
} @RequestMapping("/add")
public String add(OrderPresentInfo orderPresent) {
return "添加成功";
} }
OrderPresentInfoService:
package com.home.orderpresentdemo.service;

import com.github.pagehelper.PageInfo;
import com.home.orderpresentdemo.entity.OrderPresentInfo; import java.util.List; public interface OrderPresentInfoService {
List<OrderPresentInfo> getAllOrderPresent(); PageInfo<OrderPresentInfo> getAllOrderPresentForPage(int pageNo, int pageSize);
}
OrderPresentInfoServiceImpl:
package com.home.orderpresentdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.home.orderpresentdemo.entity.OrderPresentInfo;
import com.home.orderpresentdemo.mapper.OrderPresentInfoMapper;
import com.home.orderpresentdemo.service.OrderPresentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service
public class OrderPresentInfoServiceImpl implements OrderPresentInfoService { @Autowired
private OrderPresentInfoMapper orderPresentMapper; @Override
public List<OrderPresentInfo> getAllOrderPresent() {
return orderPresentMapper.getAllOrderPresent();
} @Override
public PageInfo<OrderPresentInfo> getAllOrderPresentForPage(int pageNo, int pageSize) { PageHelper.startPage(pageNo,pageSize);
List<OrderPresentInfo> allOrderPresentList = orderPresentMapper.getAllOrderPresent();
PageInfo<OrderPresentInfo> pageInfo = new PageInfo<>(allOrderPresentList);
return pageInfo;
}
}
OrderPresentInfo:
package com.home.orderpresentdemo.entity;

import java.math.BigDecimal;
import java.util.Date; public class OrderPresentInfo {
private Long id; private String activityName; private Date beginTime; private Date endTime; private Integer activityStoresSelectType; private String activityStoresIds; private Integer memberLevelSelectType; private String memberLevelIds; private BigDecimal activityOrderConsume; private String paymentChannelIds; private Integer equityType; private Long couponId; private Long luckyTurningId; private Integer activityStatus; private Date createTime; private Date updateTime; public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public String getActivityName() {
return activityName;
} public void setActivityName(String activityName) {
this.activityName = activityName == null ? null : activityName.trim();
} public Date getBeginTime() {
return beginTime;
} public void setBeginTime(Date beginTime) {
this.beginTime = beginTime;
} public Date getEndTime() {
return endTime;
} public void setEndTime(Date endTime) {
this.endTime = endTime;
} public Integer getActivityStoresSelectType() {
return activityStoresSelectType;
} public void setActivityStoresSelectType(Integer activityStoresSelectType) {
this.activityStoresSelectType = activityStoresSelectType;
} public String getActivityStoresIds() {
return activityStoresIds;
} public void setActivityStoresIds(String activityStoresIds) {
this.activityStoresIds = activityStoresIds == null ? null : activityStoresIds.trim();
} public Integer getMemberLevelSelectType() {
return memberLevelSelectType;
} public void setMemberLevelSelectType(Integer memberLevelSelectType) {
this.memberLevelSelectType = memberLevelSelectType;
} public String getMemberLevelIds() {
return memberLevelIds;
} public void setMemberLevelIds(String memberLevelIds) {
this.memberLevelIds = memberLevelIds == null ? null : memberLevelIds.trim();
} public BigDecimal getActivityOrderConsume() {
return activityOrderConsume;
} public void setActivityOrderConsume(BigDecimal activityOrderConsume) {
this.activityOrderConsume = activityOrderConsume;
} public String getPaymentChannelIds() {
return paymentChannelIds;
} public void setPaymentChannelIds(String paymentChannelIds) {
this.paymentChannelIds = paymentChannelIds == null ? null : paymentChannelIds.trim();
} public Integer getEquityType() {
return equityType;
} public void setEquityType(Integer equityType) {
this.equityType = equityType;
} public Long getCouponId() {
return couponId;
} public void setCouponId(Long couponId) {
this.couponId = couponId;
} public Long getLuckyTurningId() {
return luckyTurningId;
} public void setLuckyTurningId(Long luckyTurningId) {
this.luckyTurningId = luckyTurningId;
} public Integer getActivityStatus() {
return activityStatus;
} public void setActivityStatus(Integer activityStatus) {
this.activityStatus = activityStatus;
} public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
} public Date getUpdateTime() {
return updateTime;
} public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
OrderPresentInfoMapper:
package com.home.orderpresentdemo.mapper;

import com.home.orderpresentdemo.entity.OrderPresentInfo;
import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper
public interface OrderPresentInfoMapper {
int deleteByPrimaryKey(Long id); int insert(OrderPresentInfo record); int insertSelective(OrderPresentInfo record); OrderPresentInfo selectByPrimaryKey(Long id); int updateByPrimaryKeySelective(OrderPresentInfo record); int updateByPrimaryKey(OrderPresentInfo record); List<OrderPresentInfo> getAllOrderPresent();
}
OrderPresentInfoMapper.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.home.orderpresentdemo.mapper.OrderPresentInfoMapper" >
<resultMap id="BaseResultMap" type="com.home.orderpresentdemo.entity.OrderPresentInfo" >
<id column="ID" property="id" jdbcType="BIGINT" />
<result column="ACTIVITY_NAME" property="activityName" jdbcType="VARCHAR" />
<result column="BEGIN_TIME" property="beginTime" jdbcType="TIMESTAMP" />
<result column="END_TIME" property="endTime" jdbcType="TIMESTAMP" />
<result column="ACTIVITY_STORES_SELECT_TYPE" property="activityStoresSelectType" jdbcType="INTEGER" />
<result column="ACTIVITY_STORES_IDS" property="activityStoresIds" jdbcType="VARCHAR" />
<result column="MEMBER_LEVEL_SELECT_TYPE" property="memberLevelSelectType" jdbcType="INTEGER" />
<result column="MEMBER_LEVEL_IDS" property="memberLevelIds" jdbcType="VARCHAR" />
<result column="ACTIVITY_ORDER_CONSUME" property="activityOrderConsume" jdbcType="DECIMAL" />
<result column="PAYMENT_CHANNEL_IDS" property="paymentChannelIds" jdbcType="VARCHAR" />
<result column="EQUITY_TYPE" property="equityType" jdbcType="INTEGER" />
<result column="COUPON_ID" property="couponId" jdbcType="BIGINT" />
<result column="LUCKY_TURNING_ID" property="luckyTurningId" jdbcType="BIGINT" />
<result column="ACTIVITY_STATUS" property="activityStatus" jdbcType="INTEGER" />
<result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
<result column="UPDATE_TIME" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
ID, ACTIVITY_NAME, BEGIN_TIME, END_TIME, ACTIVITY_STORES_SELECT_TYPE, ACTIVITY_STORES_IDS,
MEMBER_LEVEL_SELECT_TYPE, MEMBER_LEVEL_IDS, ACTIVITY_ORDER_CONSUME, PAYMENT_CHANNEL_IDS,
EQUITY_TYPE, COUPON_ID, LUCKY_TURNING_ID, ACTIVITY_STATUS, CREATE_TIME, UPDATE_TIME
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from dss_wsh_order_present_info
where ID = #{id,jdbcType=BIGINT}
</select>
<select id="getAllOrderPresent" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from dss_wsh_order_present_info
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from dss_wsh_order_present_info
where ID = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.home.orderpresentdemo.entity.OrderPresentInfo" >
insert into dss_wsh_order_present_info (ID, ACTIVITY_NAME, BEGIN_TIME,
END_TIME, ACTIVITY_STORES_SELECT_TYPE, ACTIVITY_STORES_IDS,
MEMBER_LEVEL_SELECT_TYPE, MEMBER_LEVEL_IDS,
ACTIVITY_ORDER_CONSUME, PAYMENT_CHANNEL_IDS,
EQUITY_TYPE, COUPON_ID, LUCKY_TURNING_ID,
ACTIVITY_STATUS, CREATE_TIME, UPDATE_TIME
)
values (#{id,jdbcType=BIGINT}, #{activityName,jdbcType=VARCHAR}, #{beginTime,jdbcType=TIMESTAMP},
#{endTime,jdbcType=TIMESTAMP}, #{activityStoresSelectType,jdbcType=INTEGER}, #{activityStoresIds,jdbcType=VARCHAR},
#{memberLevelSelectType,jdbcType=INTEGER}, #{memberLevelIds,jdbcType=VARCHAR},
#{activityOrderConsume,jdbcType=DECIMAL}, #{paymentChannelIds,jdbcType=VARCHAR},
#{equityType,jdbcType=INTEGER}, #{couponId,jdbcType=BIGINT}, #{luckyTurningId,jdbcType=BIGINT},
#{activityStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="com.home.orderpresentdemo.entity.OrderPresentInfo" >
insert into dss_wsh_order_present_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
ID,
</if>
<if test="activityName != null" >
ACTIVITY_NAME,
</if>
<if test="beginTime != null" >
BEGIN_TIME,
</if>
<if test="endTime != null" >
END_TIME,
</if>
<if test="activityStoresSelectType != null" >
ACTIVITY_STORES_SELECT_TYPE,
</if>
<if test="activityStoresIds != null" >
ACTIVITY_STORES_IDS,
</if>
<if test="memberLevelSelectType != null" >
MEMBER_LEVEL_SELECT_TYPE,
</if>
<if test="memberLevelIds != null" >
MEMBER_LEVEL_IDS,
</if>
<if test="activityOrderConsume != null" >
ACTIVITY_ORDER_CONSUME,
</if>
<if test="paymentChannelIds != null" >
PAYMENT_CHANNEL_IDS,
</if>
<if test="equityType != null" >
EQUITY_TYPE,
</if>
<if test="couponId != null" >
COUPON_ID,
</if>
<if test="luckyTurningId != null" >
LUCKY_TURNING_ID,
</if>
<if test="activityStatus != null" >
ACTIVITY_STATUS,
</if>
<if test="createTime != null" >
CREATE_TIME,
</if>
<if test="updateTime != null" >
UPDATE_TIME,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="activityName != null" >
#{activityName,jdbcType=VARCHAR},
</if>
<if test="beginTime != null" >
#{beginTime,jdbcType=TIMESTAMP},
</if>
<if test="endTime != null" >
#{endTime,jdbcType=TIMESTAMP},
</if>
<if test="activityStoresSelectType != null" >
#{activityStoresSelectType,jdbcType=INTEGER},
</if>
<if test="activityStoresIds != null" >
#{activityStoresIds,jdbcType=VARCHAR},
</if>
<if test="memberLevelSelectType != null" >
#{memberLevelSelectType,jdbcType=INTEGER},
</if>
<if test="memberLevelIds != null" >
#{memberLevelIds,jdbcType=VARCHAR},
</if>
<if test="activityOrderConsume != null" >
#{activityOrderConsume,jdbcType=DECIMAL},
</if>
<if test="paymentChannelIds != null" >
#{paymentChannelIds,jdbcType=VARCHAR},
</if>
<if test="equityType != null" >
#{equityType,jdbcType=INTEGER},
</if>
<if test="couponId != null" >
#{couponId,jdbcType=BIGINT},
</if>
<if test="luckyTurningId != null" >
#{luckyTurningId,jdbcType=BIGINT},
</if>
<if test="activityStatus != null" >
#{activityStatus,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.home.orderpresentdemo.entity.OrderPresentInfo" >
update dss_wsh_order_present_info
<set >
<if test="activityName != null" >
ACTIVITY_NAME = #{activityName,jdbcType=VARCHAR},
</if>
<if test="beginTime != null" >
BEGIN_TIME = #{beginTime,jdbcType=TIMESTAMP},
</if>
<if test="endTime != null" >
END_TIME = #{endTime,jdbcType=TIMESTAMP},
</if>
<if test="activityStoresSelectType != null" >
ACTIVITY_STORES_SELECT_TYPE = #{activityStoresSelectType,jdbcType=INTEGER},
</if>
<if test="activityStoresIds != null" >
ACTIVITY_STORES_IDS = #{activityStoresIds,jdbcType=VARCHAR},
</if>
<if test="memberLevelSelectType != null" >
MEMBER_LEVEL_SELECT_TYPE = #{memberLevelSelectType,jdbcType=INTEGER},
</if>
<if test="memberLevelIds != null" >
MEMBER_LEVEL_IDS = #{memberLevelIds,jdbcType=VARCHAR},
</if>
<if test="activityOrderConsume != null" >
ACTIVITY_ORDER_CONSUME = #{activityOrderConsume,jdbcType=DECIMAL},
</if>
<if test="paymentChannelIds != null" >
PAYMENT_CHANNEL_IDS = #{paymentChannelIds,jdbcType=VARCHAR},
</if>
<if test="equityType != null" >
EQUITY_TYPE = #{equityType,jdbcType=INTEGER},
</if>
<if test="couponId != null" >
COUPON_ID = #{couponId,jdbcType=BIGINT},
</if>
<if test="luckyTurningId != null" >
LUCKY_TURNING_ID = #{luckyTurningId,jdbcType=BIGINT},
</if>
<if test="activityStatus != null" >
ACTIVITY_STATUS = #{activityStatus,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where ID = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.home.orderpresentdemo.entity.OrderPresentInfo" >
update dss_wsh_order_present_info
set ACTIVITY_NAME = #{activityName,jdbcType=VARCHAR},
BEGIN_TIME = #{beginTime,jdbcType=TIMESTAMP},
END_TIME = #{endTime,jdbcType=TIMESTAMP},
ACTIVITY_STORES_SELECT_TYPE = #{activityStoresSelectType,jdbcType=INTEGER},
ACTIVITY_STORES_IDS = #{activityStoresIds,jdbcType=VARCHAR},
MEMBER_LEVEL_SELECT_TYPE = #{memberLevelSelectType,jdbcType=INTEGER},
MEMBER_LEVEL_IDS = #{memberLevelIds,jdbcType=VARCHAR},
ACTIVITY_ORDER_CONSUME = #{activityOrderConsume,jdbcType=DECIMAL},
PAYMENT_CHANNEL_IDS = #{paymentChannelIds,jdbcType=VARCHAR},
EQUITY_TYPE = #{equityType,jdbcType=INTEGER},
COUPON_ID = #{couponId,jdbcType=BIGINT},
LUCKY_TURNING_ID = #{luckyTurningId,jdbcType=BIGINT},
ACTIVITY_STATUS = #{activityStatus,jdbcType=INTEGER},
CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
where ID = #{id,jdbcType=BIGINT}
</update>
</mapper>
SqlMapperConfig.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 对在此配置文件下的所有cache进行全局性开/关设置 true|false true -->
<setting name="cacheEnabled" value="true" />
<!-- 全局性设置懒加载。如果设为‘关',则所有相关联的都会被初始化加载。 -->
<setting name="lazyLoadingEnabled" value="true" />
<!-- 当设置为‘开’的时候,懒加载的对象可能被任何懒属性全部加载。否则,每个属性都按需加载。 -->
<setting name="aggressiveLazyLoading" value="true" />
<!-- 允许和不允许单条语句返回多个数据集(取决于驱动需求) -->
<setting name="multipleResultSetsEnabled" value="true" />
<!-- 使用列标签代替列名称。不用的驱动器有不同的作法。 -->
<setting name="localCacheScope" value="STATEMENT" />
<!-- 允许JDBC生成主键。需要驱动器支持.如果设为了true,这个设置将强制使用被生成的主键, 有一些驱动器不兼容不过仍然可以执行。 -->
<setting name="useGeneratedKeys" value="true" />
<!-- 指定MyBatis是否并且如何来自动映射数据表字段与对象的属性。PARTIAL将只自动映射简单的,NONE没有嵌套的结果。 FULL将自动映射所有复杂的结果。 -->
<setting name="autoMappingBehavior" value="PARTIAL" />
<!-- 配置和设定执行器,SIMPLE执行器执行其它语句。REUSE执行器可能重复使用preparedstatements语句,BATCH执行器可以重复执行语句和批量更新。 -->
<setting name="defaultExecutorType" value="SIMPLE" />
<!-- 设置一个时限,以决定让驱动器等待数据库回应的多长时间为超时. 正整数 -->
<setting name="defaultStatementTimeout" value="5000" />
<setting name="jdbcTypeForNull" value="OTHER"/>
<setting name="logImpl" value="LOG4J"/>
</settings> </configuration>
index.html(这里测试写的比较随意,可以忽略):
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>第一个HTML页面</title>
</head>
<body>
<h1>Hello Spring Boot!!!</h1> <a th:href="@{/goToAdd}">添加</a>
<p th:text="${hello}"></p>
<div>
<p th:text="${say}"></p>
</div>
</body>
</html>
application.properties:
#server.port=80
logging.level.org.springframework=DEBUG
#springboot mybatis
#jiazai mybatis peizhiwenjian
mybatis.mapper-locations = classpath:mapper/*Mapper.xml
#mybatis.config-location = classpath:mybatis/sqlMapConfig.xml
#mybatis.type-aliases-package = com.demo.bean #shujuyuan
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/dss_wshop?useUnicode=true&characterEncoding=utf-8
spring.datasource.username = root
spring.datasource.password = root spring.thymeleaf.prefix=classpath:/templates/ #禁止thymeleaf缓存(建议:开发环境设置为false,生成环境设置为true)
spring.thymeleaf.cache=false #pagehelper分页插件配置 以下属性不加也可以实现分页功能
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
获得结果如下所示:

SpringBoot与PageHelper的整合示例详解的更多相关文章

  1. Spring Boot 2.x 快速入门(下)HelloWorld示例详解

    上篇 Spring Boot 2.x 快速入门(上)HelloWorld示例 进行了Sprint Boot的快速入门,以实际的示例代码来练手,总比光看书要强很多嘛,最好的就是边看.边写.边记.边展示. ...

  2. SpringBoot系列(十二)过滤器配置详解

    SpringBoot(十二)过滤器详解 往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件 ...

  3. jquery移除、绑定、触发元素事件使用示例详解

    这篇文章主要介绍了jquery移除.绑定.触发元素事件使用示例详解,需要的朋友可以参考下. unbind(type [,data]) //data是要移除的函数 $('#btn').unbind(&q ...

  4. Apache2.2+Tomcat7.0整合配置详解

    一.简单介绍 Apache.Tomcat Apache HTTP Server(简称 Apache),是 Apache 软件基金协会的一个开放源码的网页服务器,可以在 Windows.Unix.Lin ...

  5. gcc与g++的编译链接的示例详解

    一.编译方式的示例详解 1. 编译C代码 代码如下:main.c /*!  ************************************************************** ...

  6. 史上最易懂——ReactNative分组列表SectionList使用详情及示例详解

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  7. VS2010 Chart控件(一)Chart控件在ASP.NET网站中的应用示例详解(C#语言)

    步骤如下: 1. Chart控件(一)Chart控件在ASP.NET网站中的应用示例详解(C#语言)" title="VS2010 Chart控件(一)Chart控件在ASP.NE ...

  8. socket编程的同步、异步与阻塞、非阻塞示例详解

     socket编程的同步.异步与阻塞.非阻塞示例详解之一  分类: 架构设计与优化 简介图 1. 基本 Linux I/O 模型的简单矩阵 每个 I/O 模型都有自己的使用模式,它们对于特定的应用程序 ...

  9. String.format()【示例详解】

    String.format()[示例详解] 整理者:Vashon 前言: String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.fo ...

随机推荐

  1. my97Date如何多选日期且无重复日期

    最终的效果是: 首先引用my97Date的js WdatePicker.js html代码 <textarea cols="" name="txtNoUseDate ...

  2. 跟着9张思维导图学习Javascript js 关键字和保留字 css3中的BFC,IFC,GFC和FFC

    跟着9张思维导图学习Javascript   学习的道路就是要不断的总结归纳,好记性不如烂笔头,so,下面将 po 出我收集的 9 张 javascript 相关的思维导图(非原创). 思维导图小ti ...

  3. 一个APACHE TOMCAT漏洞修复

    这种情况加个SSL证书就行了  就是HTTPS协议

  4. (原)在anaconda3+ubuntu16.04中编译Pose flow中的deepmatching动态库

    转载请注明出处: https://www.cnblogs.com/darkknightzh/p/11285239.html 参考网址: https://github.com/YuliangXiu/Po ...

  5. HDU5952 dfs+剪枝

    题目分析: 对于给出的n个点和m条边,求这个图的完全联通子图的数量(每次查询的子图的大小为s),对于本题而言,很容易想到的是dfs暴力和这个点相连的所有的点,并且判断这个图是否是度为s 的完全联通子图 ...

  6. Android开发:为什么你的学习效率如此低,为什么你很迷茫?

    一天一天的过的真的是太快了,常常感到时间在前进,而我们还在停滞不前,看似每天努力的工作学习着,仔细想想其实又会发现,一天下来我们好像还真的什么都没干,看似忙碌的一天,我们把时间都用在哪了?学习!可是为 ...

  7. Python+OpenCV4:读写输入和输出的简单实践(图片、视频、摄像头)

    典型的文件处理流程如下: 利用命令行参数 sys.argv 命令行参数是读取文件时常用的方式. 命令行参数保存在 sys.argv 的列表中,列表的第一个元素是脚本名称,后面的元素是命令行参数: 通过 ...

  8. bootstrap的selectpicker的方法

    方法 .selectpicker('val') 您可以通过调用val元素上的方法来设置所选值. 1 2 $('.selectpicker').selectpicker('val', 'Mustard' ...

  9. Leetcode周赛165

    目录 找出井字棋的获胜者 思路 代码 不浪费原料的汉堡制作方案 思路 代码 统计全为 1 的正方形子矩阵 思路 代码 分割回文串 III 思路 代码 找出井字棋的获胜者 思路 模拟. 代码 class ...

  10. load address、entry point、 bootm address以及kernel运行地址

    load address:加载地址   load_addr      mkimage -a entry point: 入口地址     entry_point     mkimage -e bootm ...