众所周知,SpringBoot是目前非常流行的Java开发框架。 今天分享一个简单的案例。
省略。
<?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>2.5.13</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cnhongker</groupId>
<artifactId>platform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>platform</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
主配置文件
spring:
profiles:
active: dev
server:
port: 8081
激活配置的文件
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/platform?serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&useSSL=false
username: root
password: root
mybatis-plus:
mapper-locations: classpath:mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
type-aliases-package: com.cnhongker.platform.entity
global-config:
db-config:
#主键类型 0:"数据库ID自增",1:"无主键设置",2:"用户输入ID",3:"全局唯一ID (数字类型唯一ID)", 4:"全局唯一ID UUID";
id-type: ASSIGN_ID
#是否开启大写命名,默认不开启
capital-mode: true
#逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
几个重要说明:
Response.java
: 全局响应实体,用于封装Ajax请求结果数据
GlobalException.java
全局异常处理