JDK版本:17
SpringBoot 整合Mybatis Plus 、Redis等
依赖文件
<?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><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.1.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.xzm</groupId><artifactId>server</artifactId><version>0.0.1-SNAPSHOT</version><name>Server</name><description>Server</description><properties><java.version>17</java.version></properties><packaging>jar</packaging><dependencies><!-- Spring Data JPA: 使用JPA进行数据访问 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><!-- Spring Boot Web: Spring Boot的Web应用程序启动器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Lombok: 简化Java代码,提高开发效率 --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><!-- Spring Boot Starter Test: Spring Boot测试支持 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- 导入MybatisPlus相关依赖--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.33</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.16</version></dependency><!-- Spring Boot Starter Validation: 提供验证功能支持,包括Bean验证和方法验证 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency><!-- FastJSON: 高性能的 JSON 处理库 --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.32</version> <!-- 请根据需要调整版本号 --></dependency><!--用于将Spring Boot与Redis集成--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>3.0.0</version></dependency></dependencies></project>
文件位置视图
tree .\src\main
├─java
│ └─com
│ └─xzm
│ ├─common
│ ├─configs
│ ├─controller
│ ├─domain
│ ├─intercepts
│ ├─mapper
│ ├─service
│ │ └─impl
│ └─utils
└─resources
└─mapper**
application.yaml配置文件
#Spring
spring:#Mysqldatasource:url: jdbc:mysql://localhost:3306/staticdb?characterEncoding=utf-8&serverTimezone=Asia/Shanghaiusername: rootpassword: 123456driver-class-name: com.mysql.cj.jdbc.Driver#Redisdata:redis:host: localhostpassword: 123456database: 0port: 6379
server:port: 8080# MyBatis-Plus Config
mybatis-plus:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmapper-locations: classpath:mapper/*.xmltype-aliases-package: com.xzm.generator.domain
logging:level:com.baomidou.mybatisplus: debug
SpringBoot 启动类
package com.xzm;import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;@SpringBootApplication
@SuppressWarnings({"all"})
@MapperScan(basePackages = "com.xzm.mapper") // 指定 Mapper 接口所在的包
@Slf4j
public class ServerApplication {public static void main(String[] args) {ConfigurableApplicationContext context = SpringApplication.run(ServerApplication.class, args);log.info("访问链接:\thttp://localhost:"+context.getEnvironment().getProperty("server.port"));log.info("启动成功");}}
控制台
\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v3.1.0)2023-12-19T20:31:35.035+08:00 INFO 16132 --- [ main] com.xzm.ServerApplication : Starting ServerApplication using Java 17.0.8 with PID 16132 (W:\IDEA WorkSpace\Server\target\classes started by Administrator in W:\IDEA WorkSpace\Server)
2023-12-19T20:31:35.037+08:00 INFO 16132 --- [ main] com.xzm.ServerApplication : No active profile set, falling back to 1 default profile: "default"
2023-12-19T20:31:35.682+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-12-19T20:31:35.683+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-12-19T20:31:35.710+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 19 ms. Found 0 JPA repository interfaces.
2023-12-19T20:31:35.725+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2023-12-19T20:31:35.726+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2023-12-19T20:31:35.736+08:00 INFO 16132 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 1 ms. Found 0 Redis repository interfaces.
2023-12-19T20:31:36.278+08:00 INFO 16132 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-12-19T20:31:36.286+08:00 INFO 16132 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-12-19T20:31:36.287+08:00 INFO 16132 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.8]
2023-12-19T20:31:36.361+08:00 INFO 16132 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-12-19T20:31:36.361+08:00 INFO 16132 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1285 ms
2023-12-19T20:31:36.486+08:00 INFO 16132 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-12-19T20:31:36.760+08:00 INFO 16132 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@22f8adc2
2023-12-19T20:31:36.762+08:00 INFO 16132 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-12-19T20:31:36.793+08:00 INFO 16132 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-12-19T20:31:36.837+08:00 INFO 16132 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.2.2.Final
2023-12-19T20:31:36.839+08:00 INFO 16132 --- [ main] org.hibernate.cfg.Environment : HHH000406: Using bytecode reflection optimizer
2023-12-19T20:31:36.938+08:00 INFO 16132 --- [ main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-12-19T20:31:37.050+08:00 INFO 16132 --- [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-12-19T20:31:37.114+08:00 INFO 16132 --- [ main] org.hibernate.orm.dialect : HHH035001: Using dialect: org.hibernate.dialect.MySQLDialect, version: 8.0.30
2023-12-19T20:31:37.179+08:00 INFO 16132 --- [ main] o.h.b.i.BytecodeProviderInitiator : HHH000021: Bytecode provider name : bytebuddy
2023-12-19T20:31:37.320+08:00 INFO 16132 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-12-19T20:31:37.323+08:00 INFO 16132 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-12-19T20:31:37.735+08:00 DEBUG 16132 --- [ main] c.b.m.e.s.MybatisSqlSessionFactoryBean : Parsed mapper file: 'file [W:\IDEA WorkSpace\Server\target\classes\mapper\ResourcesTagsMapper.xml]'
2023-12-19T20:31:37.759+08:00 DEBUG 16132 --- [ main] c.b.m.e.s.MybatisSqlSessionFactoryBean : Parsed mapper file: 'file [W:\IDEA WorkSpace\Server\target\classes\mapper\UserMapper.xml]'_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\ / | 3.5.3.1
2023-12-19T20:31:37.869+08:00 WARN 16132 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-12-19T20:31:38.251+08:00 INFO 16132 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-12-19T20:31:38.261+08:00 INFO 16132 --- [ main] com.xzm.ServerApplication : Started ServerApplication in 3.563 seconds (process running for 4.094)
2023-12-19T20:31:38.265+08:00 INFO 16132 --- [ main] com.xzm.ServerApplication : 访问链接: http://localhost:8080
2023-12-19T20:31:38.265+08:00 INFO 16132 --- [ main] com.xzm.ServerApplication : 启动成功