資料內(nèi)容:
1.2 添加依賴
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1.tmp</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.46</version>
</dependency>
</dependencies>
1.3 配置文件
2.3.1 在 application.yml 配置文件中添加 Mysql 數(shù)據(jù)庫的
相關(guān)配置:
server:
port: 4321
spring:
profiles:
active: /
datasource:
url:
jdbc:mysql://10.20.7.143:3306/test_mysql?useUnicode=true&useSSL=false&characterEncoding=
UTF-8&serverTimezone=Asia/Shanghai
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
mybatis-plus:
configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath*:mapper/*.xml
2.3.2 在 Spring Boot 啟動(dòng)類中添加 @MapperScan 注解,
掃描 Mapper 文件夾:
@SpringBootApplication@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(QuickStartApplication.class, args);
}
}
1.4 編碼
2.4.1 編寫實(shí)體類 User.java(此處使用了 Lombok 簡(jiǎn)化代碼)
@Data
public class User {
private Long id;
private String name;
private Integer age;
private String email;
}