SpringBoot與PageHelper的整合示例詳解
1.PageHelper簡介
PageHelper官網地址:
摘要: 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