SpringBoot与PageHelper的整合示例详解

时间:2023-12-22 12:04:50

SpringBoot与PageHelper的整合示例详解

1.PageHelper简介

PageHelper官网地址:

https://pagehelper.github.io/

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

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

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

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

SpringBoot与PageHelper的整合示例详解

2.SpringBoot与PageHelper的整合示例

结构图如下:

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的整合示例详解