项目创建:
如图选择:
第一步:
第二步:依赖选择
总共添加了四个依赖:
项目结构:
DemoController.java
package com.fzf.seckill.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author 繁星
* @Date 2022/10/16 16:53
* @Function
*/
@RestController
@RequestMapping("/demo")
public class DemoController {
/**
* 测试页面跳转
* @param model
* @return
*/
@RequestMapping("/hello")
public String hello(Model model){
return "hello";
}
}
SeckillDemoApplication.java
package com.fzf.seckill;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.fzf.seckill.pojo")
public class SeckillDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SeckillDemoApplication.class, args);
}
}
spring:
# thymeleaf配置
thymeleaf:
# 关闭缓存
cache: false
# 数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
password: root
hikari:
# 连接池名称
pool-name: DateHikariCP
#最小空闲连接出
minimum-idle: 5
#空闲连接存货最大时间,默认600000(10分钟)
idle-timeout: 180000
#最大连接数,默认10
maximum-pool-size: 10
#从连接池返回自动提交
auto-commit: true
#连接最大存活时间,0表示永久存活,默认1800000(30分支)
max-lifetime: 1800000
#连接超时时间,默认30000(30秒)
connection-timeout: 30000
#测试连接是否可用的查询语句
connection-test-query: SELECT 1
#Mybatis-plus配置
mybatis-plus:
#配置Mapper.xml映射文件
mapper-locations: classpath*:/mapper/*Mapper.xml
#配置Mybatis数据返回类型别名(默认别名是类名)
type-aliases-package: com.fzf.seckill.pojo
# MyBatis SQL打印(方法接口所在的包,不是Mapper.xmL所在的包)
logging:
level:
com.fzf.seckill.mapper: debug
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 https://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.7.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.fzf</groupId>
<artifactId>seckill-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>seckill-demo</name>
<description>seckill-demo</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--thymeleaf组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--test组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
下一篇: