环境
ide:idea 2020.3
jdk:11
mysql:5.7
依赖
这个直接给出pom文件
<?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>
<!--统一设置springboot系列版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/>
</parent>
<groupId>demo</groupId>
<artifactId>tank</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<!--主要-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--数据库链接,使用此依赖,否则yml缺失相关设置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--thymeleaf模板,方便好用,当然也可以用其他的-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--mybatis,使用此依赖,否则yml缺失相关设置-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<!--因使用jdk版本较高,所以选用此版本-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.22</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.22</version>
</dependency>
<!--json解析,个人感觉好用-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.71</version>
</dependency>
<!--主要-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>5.0.0.Alpha2</version>
</dependency>
<!--热启动-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
如果不使用以上版本,其他依赖请选择和springboot相对的版本,不然会产生编译错误。
文件结构
这里可能有人会问怎么没有entity(实体类)层,因为根本就不需要,同时也没有service层也没有imp层。
yml配置
server:
port: 80
spring:
datasource:
username: root
password: your password
url: jdbc:mysql://127.0.0.1:3306/tank?serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
thymeleaf:
cache: false
mybatis:
config-location: classpath:mybatis/config.xml
mapper-locations: classpath:mybatis/mapper/*.xml
mybatis配置
<?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>
<!--开发驼峰格式与下划线格式对应-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!--关闭通过变量名替换sql语句中的参数,本人没有过多深入了解此参数-->
<setting name="useActualParamName" value="false"/>
</settings>
</configuration>
其他
idea配置热启动
1、找到Setting---->Compiler设置(也可以快捷键:Ctrl+Alt+S),勾选"Build project automatically"。
2、点击快捷键Alt+Ctrl+shift+a+/,(idea版本过高,点击Alt+shift+a)选择Registry,勾选 compiler.automake.allow.when.app.running即可。
3、重启idea。
eclipse配置热启动
请自行百度。
到这里基本上算是搭建好了。