SpringBoot + Thymeleaf + MP
依赖配置:
- <!-- spring boot 的父类 -->
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.2.1.RELEASE</version>
- </parent>
- <dependencies>
- <!-- spring web 依赖 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-Web</artifactId>
- </dependency>
- <!-- spring test 测试 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- </dependency>
- <!-- mysql 驱动 -->
- <dependency>
- <groupId>MySQL</groupId>
- <artifactId>MySQL-connector-java</artifactId>
- <version>5.1.37</version>
- </dependency>
- <!-- mybatisplus 与 springboot 整合 如果版本过低需要导入 mp 的依赖 -->
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>3.2.0</version>
- </dependency>
- <!-- mybatis-plus 依赖 -->
- <!-- <dependency>-->
- <!-- <groupId>com.baomidou</groupId>-->
- <!-- <artifactId>mybatis-plus</artifactId>-->
- <!-- <version>3.2.0</version>-->
- <!-- </dependency>-->
- <!-- spring 整合 mp 分页工具类 版本 2 一下需要自定义 -->
- <!-- <dependency>-->
- <!-- <groupId>com.github.pagehelper</groupId>-->
- <!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
- <!-- <version>1.2.3</version>-->
- <!-- </dependency>-->
- <!-- thymeleaf 页面 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-thymeleaf</artifactId>
- </dependency>
- <!-- 热启动 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- </dependencies>
配置文件信息:
- server:
- port: 8081 #端口号
- spring:
- application:
- name: user #程序名称
- datasource: #数据库连接基本四项
- driver-class-name: com.MySQL.jdbc.Driver
- url: jdbc:MySQL://127.0.0.1:3306/mp?allowMultiQueries=true
- username: root
- password: 123456
- main:
- allow-bean-definition-overriding: true # 覆盖相同的 bean
- thymeleaf: #thymeleaf 前端
- cache: false #是否进行数据缓存 选择 false 便于使用热部署 必须配置
- prefix: classpath:/templates/ #前缀
- suffix: .html #后缀
- mode: LEGACYHTML5 #模块类型 LEGACYHTML5 必须配置
- encoding: UTF-8 #编码类型 必须配置
- servlet:
- content-type: text/HTML #文件类型
- enable-spring-el-compiler: true #
- mybatis:
- typeAliasesPackage: com.Web.mp.pojo #扫描实体类的包
- mapperLocations: classpath:mappers/*.xml #mapper 配置文件扫描
- mybatis-plus:
- configuration:
- map-Underscore-to-camel-case: false # 小驼峰和下换线的转换
坑:
1. 配置 thymeleaf 的时候 前缀最好写成如下形式, 否者容易无法识别:
- prefix: classpath:/templates/
来源: http://www.bubuko.com/infodetail-3299329.html