基于EasyCode插件的SpringBoot和Mybatis框架快速整合以及PostMan的使用
参考视频:基于EasyCode插件的Spring boot、Mybatis框架快速整合搭建以及PostMan的使用 点击观看
文章目录
- 1 创建项目
- pom.xml
- 2 创建数据库
- 3 导包
- pom.xml
- 4 配置application.yaml文件
- 5 使用插件EasyCode
- 6 验证项目是否运行成功
- 7 使用PostMan测试工具测试接口
1 创建项目
pom.xml
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="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.6</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.findx</groupId><artifactId>springboot-mybatis-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot-mybatis-demo</name><description>springboot-mybatis-demo</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><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></plugin></plugins></build></project>2 创建数据库
createdatabasemalldbdefaultcharactersetutf8mb4collateutf8mb4_unicode_ci;# 使用数据库usemalldb;-- 建表sqlcreatetablemall_user(idintauto_incrementcomment'主键id'primarykey,user_idbigintdefault0nullcomment'用户id',user_namevarchar(8)default''nullcomment'用户姓名',user_genderintdefault0nullcomment'性别',user_addressvarchar(256)default''nullcomment'用户地址',user_birthdaytimestampdefaultCURRENT_TIMESTAMPnullcomment'用户生日',user_phonevarchar(20)default''nullcomment'用户手机号',create_timetimestampdefaultCURRENT_TIMESTAMPnullCOMMENT'创建时间',update_timetimestampdefaultCURRENT_TIMESTAMPnullONupdateCURRENT_TIMESTAMPCOMMENT'更新时间')comment'用户表';-- 建立唯一索引createuniqueindexidx_user_idonmall_user(user_id);-- 插入数据INSERTINTOmall_user(user_id,user_name,user_gender,user_address,user_birthday,user_phone,create_time,update_time)VALUES(88880001,'zs',1,'sh',DEFAULT,'15821238534',DEFAULT,DEFAULT);INSERTINTOmall_user(user_id,user_name,user_gender,user_address,user_birthday,user_phone,create_time,update_time)VALUES(88880002,'ls',0,'bj',DEFAULT,'15821238588',DEFAULT,DEFAULT);INSERTINTOmall_user(user_id,user_name,user_gender,user_address,user_birthday,user_phone,create_time,update_time)VALUES(88880003,'ww',1,'sh',DEFAULT,'15821238577',DEFAULT,DEFAULT);# 查看数据库select*frommall_user;3 导包
pom.xml
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="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.6</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.findx</groupId><artifactId>springboot-mybatis-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot-mybatis-demo</name><description>springboot-mybatis-demo</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.3.2</version></dependency><!--mysql驱动--><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.31</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>4 配置application.yaml文件
spring:datasource:url:jdbc:mysql://localhost:3306/malldb?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghaiusername:rootpassword:rootdriver-class-name:com.mysql.cj.jdbc.Driver