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. Nginx 高级配置-实现多域名HTTPS

    Nginx 高级配置-实现多域名HTTPS 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx支持基于单个IP实现多域名的功能 Nginx支持基于单个IP实现多域名的功能 ...

  2. 大数据技术原理与应用【第五讲】NoSQL数据库:5.5 从NoSQL到NewSQL数据库

    应用场景: OldSql数据库:希望一种架构就能支持多种应用场景,但证明不可能.   NewSql数据库:同时具备OldSql和NoSQL各自的优点:水平可扩展性,强一致性,事务一致性,支持查询,支持 ...

  3. Jupyter notebook 中常用的快捷键

    1.注释和缩进 注释一行或多行: Ctrl + / 多行同时缩进:Tab 或者 Ctrl + ] 多行取消缩进: Shift + Tab 或者 ctrl + [ 2.编辑和运行 Enter : 转入编 ...

  4. Codeforces 749E: Inversions After Shuffle

    题目传送门:CF749E. 记一道傻逼计数题. 题意简述: 给一个 \(1\) 到 \(n\) 的排列,随机选取区间 \([l,r]\) 随机打乱区间内的元素,问打乱后的整个序列的逆序数期望. 题解: ...

  5. 前端(4)BOM与DOM

    前端(4)BOM与DOM I/O前戏 到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些简单的语法,并没有和浏览器有任何交互. 也就是我们还不能制作一些我们经常看到的网页的一些交 ...

  6. wordpress调用自定义post_type文章

    前面我们讲了wordpress添加post_type自定义文章类型,我们现在来讲一下如何把自定义文章调用出来,我们以product为例,虽然我们自定义好了 Post Type 同时也编写了一些内容,但 ...

  7. NOIP 2008 火柴棒等式

    洛谷 P1149 火柴棒等式 洛谷传送门 JDOJ 1540: [NOIP2008]火柴棒等式 T2 JDOJ传送门 Description 给你n根火柴棍,你可以拼出多少个形如"A+B=C ...

  8. Vue 分页功能伪代码实现

    Vue分页功能的实现 其实分页功能是一个比较简单的demo 后端写好pageNum和pageSize的接口直接传参就是了 // 这里我们假设后端已经写好了 pageNum和pagesize <v ...

  9. 10-排序6 Sort with Swap(0, i) (25 分)

    Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order ...

  10. 一篇文章看懂mysql中varchar能存多少汉字、数字,以及varchar(100)和varchar(10)的区别

    看完这篇文章,你能搞清楚以下问题: 1.varchar(100)和varchar(10)的区别在哪里? 2.varchar能存多少汉字.数字? 3.varchar的最大长度是多少呢? 4.字符.字节. ...