前言
Spring boot + Mybatis + Thymeleaf + Druid +mySql
开发环境(小编使用的版本)
JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题
Spring boot :2.1.1RELEASE ;
Thymeleaf
Mybatis
阿里云的连接池 : Druid ;
步骤
1.创建Springboot:
2.创建项目文件结构
3.POM依赖
如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择
点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)
4.项目结构
5.POM
<?xml version="1.0" encoding="UTF-8"?>4.0.0org.springframework.bootspring-boot-starter-parent2.1.1.RELEASEcom.springboot0.0.1-SNAPSHOTbootDemo project for Spring Boot1.8org.springframework.bootspring-boot-devtoolstruecom.alibabadruid-spring-boot-starter1.1.10org.springframework.bootspring-boot-starter-thymeleaforg.springframework.bootspring-boot-starter-weborg.mybatis.spring.bootmybatis-spring-boot-starter1.3.2mysqlmysql-connector-javaruntimeorg.springframework.bootspring-boot-starter-testtestorg.springframework.bootspring-boot-maven-plugin
注:IDEA失效解决方法
6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:
#缓存设置为false, 修改之后马上生效spring.thymeleaf.cache=falsespring.thymeleaf.encoding=UTF-8#spring.thymeleaf.prefix=classpath:/templates/#spring.thymeleaf.suffix=.htmlserver.port=8080server.tomcat.uriEncoding=utf-8spring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.url=jdbc:mysql://localhost:3306/web?useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf-8&allowMultiQueries=true&useSSL=falsespring.datasource.username=rootspring.datasource.password=rootspring.datasource.druid.driverClassName=com.mysql.cj.jdbc.Driver#初始化连接spring.datasource.initialSize=20#最大空闲数spring.datasource.maxActive=50#最小空闲数spring.datasource.minIdle=10#获取连接等待时间#spring.datasource.druid.max-wait=60000#最小等待时间#spring.datasource.minEvictableIdleTimeMillis=3600000
7.其他文件生成
User.java
package com.spring.boot.bean;public class User {public Integer uid;public String uname;public String upassword;public Integer getUid() {return uid;}public void setUid(Integer uid) {this.uid = uid;}public String getUanme() {return uname;}public void setUanme(String uanme) {this.uname = uanme;}public String getUpassword() {return upassword;}public void setUpassword(String upassword) {this.upassword = upassword;}@Overridepublic String toString() {return "User{" +"uid=" + uid +