基于EasyCode插件的SpringBoot和Mybatis框架快速整合以及PostMan的使用

参考视频:基于EasyCode插件的Spring boot、Mybatis框架快速整合搭建以及PostMan的使用 点击观看

文章目录

  • [1 创建项目](#1 创建项目)
  • [2 创建数据库](#2 创建数据库)
  • [3 导包](#3 导包)
  • [4 配置application.yaml文件](#4 配置application.yaml文件)
  • [5 使用插件EasyCode](#5 使用插件EasyCode)
  • [6 验证项目是否运行成功](#6 验证项目是否运行成功)
  • [7 使用PostMan测试工具测试接口](#7 使用PostMan测试工具测试接口)

1 创建项目

pom.xml

xml 复制代码
<?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.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 创建数据库

sql 复制代码
create database malldb default character set utf8mb4 collate utf8mb4_unicode_ci;
# 使用数据库
use malldb;
-- 建表sql
create table mall_user
(
    id            int auto_increment comment '主键id'
        primary key,
    user_id       bigint  default 0                       null comment '用户id',
    user_name     varchar(8)   default ''                null comment '用户姓名',
    user_gender   int          default 0                 null comment '性别',
    user_address  varchar(256) default ''                null comment '用户地址',
    user_birthday timestamp      default CURRENT_TIMESTAMP  null comment '用户生日',
    user_phone    varchar(20)  default ''                null comment '用户手机号',
    create_time   timestamp      default CURRENT_TIMESTAMP  null COMMENT '创建时间',
    update_time   timestamp      default CURRENT_TIMESTAMP  null ON update  CURRENT_TIMESTAMP   COMMENT '更新时间'
)
    comment '用户表';
-- 建立唯一索引
create unique index idx_user_id on mall_user(user_id);
-- 插入数据
INSERT INTO mall_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);
INSERT INTO mall_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);
INSERT INTO mall_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  * from mall_user;

3 导包

pom.xml

xml 复制代码
<?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.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文件

yaml 复制代码
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/malldb?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver

5 使用插件EasyCode



6 验证项目是否运行成功


7 使用PostMan测试工具测试接口

相关推荐
txxzjmzlh8 小时前
SpringBoot 配置⽂件
java·spring boot·spring
Thomas.Sir14 小时前
第13课:MyBatis-Plus整合SpringBoot4.x,分页、条件查询、逻辑删除实战
java·spring boot
郭小李16 小时前
mybatis 动态 sql
java·sql·mybatis
知守观16 小时前
技术考古:iBATIS 2.3.4 时代的持久层,是如何用 Map 玩转 307 个存储过程的?
java·后端·mybatis
captain37617 小时前
MyBatis Plus(1)
java·服务器·mybatis
小蒜学长18 小时前
编程语言在线学习平台的设计与实现(代码+数据库+LW)
java·spring boot·后端·编程语言在线学习平台·在线编码
Félix25120 小时前
Nacos学习笔记(SpringBoot/SpringCloud)
java·spring boot·spring
lqbzlll20 小时前
Spring Boot 开启虚拟线程后接口反而变慢了?4 个排查方向和对应修法
java·spring boot·后端
企业数字化笔记21 小时前
业务单据怎样接入流程中心?启动条件、实例关联与失败回退
java·spring boot·mysql
孤狼GPT21 小时前
ChatGPT、Codex工程实战:Spring Boot的SSE一直在推送,为什么经过Nginx后前端才一次性显示?
spring boot·chatgpt·sse·codex·chatgptplus