JAVA全系列 教程
3762个小节阅读:7093.2k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</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.4.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
在 application.yml
配置文件中添加 MySQL 数据库的相关配置:
xxxxxxxxxx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.66.100:3306/test?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
在 Spring Boot 启动类中添加 @MapperScan
注解,扫描 Mapper 文件夹:
xxxxxxxxxx
@SpringBootApplication
@MapperScan("com.itbaizhan.sonwflake.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
编写实体类 User.java
xxxxxxxxxx
@Data
public class User {
@TableId(type = IdType.ASSIGN_ID)// 雪花算法
private Long id;
private String name;
private Integer age;
private String email;
}
xxxxxxxxxx
public interface UserMapper extends BaseMapper<User> {
}
xxxxxxxxxx
@Test
void createUser() {
User user = new User();
user.setName("张三");
user.setAge(18);
user.setEmail("23472@qq.com");
userMapper.insert(user);
}