专栏首页Spring相关SpringBoot与PageHelper的整合示例详解

SpringBoot与PageHelper的整合示例详解

SpringBoot与PageHelper的整合示例详解

1.PageHelper简介

PageHelper官网地址: https://pagehelper.github.io/ 摘要: com.github.pagehelper.PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件。 PageHelper是一款好用的开源免费的Mybatis第三方物理分页插件,其实我并不想加上好用两个字,但是为了表扬插件作者开源免费的崇高精神,我毫不犹豫的加上了好用一词作为赞美。 原本以为分页插件,应该是很简单的,然而PageHelper比我想象的要复杂许多,它做的很强大,也很彻底,强大到使用者可能并不需要这么多功能,彻底到一参可以两用。但是,我认为,作为分页插件,完成物理分页任务是根本,其它的很多智能并不是必要的,保持它够傻够憨,专业术语叫stupid,简单就是美。 我们将简单介绍PageHelper的基本使用和配置参数的含义,重点分析PageHelper作为Mybatis分页插件的实现原理。

ZvCzAx.png

2.SpringBoot与PageHelper的整合示例

结构图如下:

ZvPHat.png

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
获得结果如下所示:

ZvicLj.png

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • SpringBoot整合Mybatis之进门篇

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结。        之前...

    赵小忠
  • pagehelper和通用mapper与springboot整合

    关于pageHelper的使用,其官方文档中介绍的比较清楚,地址为:https://pagehelper.github.io/docs/howtouse/

    开发架构二三事
  • Spring Boot入门系列(十六)整合pagehelper,一秒实现分页功能!

    之前讲了Springboot整合Mybatis,然后介绍了如何自动生成pojo实体类、mapper类和对应的mapper.xml 文件,并实现最基本的增删改查功...

    架构师精进
  • Mybatis-PageHelper分页插件的使用与相关原理分析

    今天使用了分页插件,并将其整合到SpringBoot中。各种遇到了个别问题,现在记录下。吃一垫长一智。

    码农飞哥
  • SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页

    本篇文章主要讲述的是SpringBoot整合Mybatis、Druid和PageHelper 并实现多数据源和分页。其中SpringBoot整合Mybatis这...

    田维常
  • SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页

    本篇文章主要讲述的是SpringBoot整合Mybatis、Druid和PageHelper 并实现多数据源和分页。其中SpringBoot整合Mybatis这...

    Java团长
  • SpringBoot与RabbitMQ详解与整合

    Direct Exchange是RabbitMQ默认的交换机模式,也是最简单的模式,根据key全文匹配去寻找队列。

    码哥字节
  • SpringBoot 通过注解的方式整合 Mybatis + PageHelper 分页显示

    本篇博客主要利用 SpringBoot 通过注解的方式整合 Mybatis 同时利用 PageHelper 对结果分页,所有涉及的代码已经上传 Github m...

    村雨遥
  • SpringBoot使用pageHelper分页插件【面试+工作】

    可能有些不太详细,具体可以参考插件作者的文档哦。 https://github.com/pagehelper/Mybatis-PageHelper/blob/...

    Java帮帮
  • Spring Boot + MyBatis + Druid + PageHelper 实现多数据源并分页

    本篇文章主要讲述的是 Spring Boo t整合Mybatis、Druid和PageHelper 并实现多数据源和分页。其中Spring Boot整合Myba...

    java思维导图
  • 用了这么多年分页PageHelper,才发现自己一直用错了!

    在实际项目运用中,PageHelper的使用非常便利快捷,仅通过PageInfo + PageHelper两个类,就足以完成分页功能,然而往往这种最简单的集成使...

    业余草
  • SpringBoot 实战 (十三) | 整合 MyBatis (XML 版)

    如题,今天介绍 SpringBoot 与 Mybatis 的整合以及 Mybatis 的使用,之前介绍过了 SpringBoot 整合MyBatis 注解版的使...

    一个优秀的废人
  • SpringBoot整合MVC Mybatis plus 最全thymeleaf讲解(保姆级讲解,带Java代码案例讲解)

    默认的静态资源路径为: classpath:/META-INF/resources/ 或者 classpath:/resources/ ...

    CaesarChang张旭
  • SpringBoot整合Mybatis,使用通用mapper和PageHelper进行分页

    上节介绍了如何整合Security,这节就说下如何再Springboot下使用持久层框架mybatis和牛人封装的通用mapper与mybatis的整合,直接进...

    AI码师
  • Springboot 整合微信小程序实现登录与增删改查

    链接:https://www.cnblogs.com/ckfeng/p/12812214.html

    程序IT圈
  • springboot整合pagehelper插件失效

    因为我之前用的是SSM框架写的我们的项目,但是只有因为技术主管让我们做成微服务的架构,所以现在是又用springboot把之前的项目重新编写了一遍,之前自己在S...

    萌萌哒的瓤瓤
  • 手把手教你Spring Boot 整合微信小程序实现登录与增删改查

    编辑:业余草 来源:https://www.xttblog.com/?p=4998

    业余草
  • Spring Boot 整合微信小程序实现登录与增删改查

    项目描述:在微信小程序中通过与Springboot操作数据库实现简单的增删改查,其中我是用springboot整合mybatis-plus 和mysql使用的

    Java编程指南
  • PageHelper分页插件怎么这么好用

    参数说明https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToU...

    码农飞哥

扫码关注云+社区

领取腾讯云代金券