基于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测试工具测试接口

相关推荐
不恋水的雨2 小时前
mybatis-plus保存数据实现公共字段自动填充
mybatis
devilnumber2 小时前
Spring Boot 2 vs Spring Boot 3:50 条核心区别 + 升级优势 + 避坑指南
java·spring boot·springboot升级
一 乐2 小时前
咖啡商城|基于springboot + vue咖啡商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·咖啡商城系统
码农周4 小时前
告别大体积PDF!基于PDFBox的Java压缩工具
java·spring boot
吕永强4 小时前
基于SpringBoot+Vue小区报修系统的设计与实现(源码+论文+部署)
spring boot·毕业设计·毕业论文·报修系统·小区报修
qingwufeiyang_5305 小时前
Mybatis-plus学习笔记1
笔记·学习·mybatis
程序员老邢6 小时前
【产品底稿 05】商助慧 V1.1 里程碑:RAG 文章仿写模块全链路实现
java·spring boot·程序人生·ai·milvus
消失的旧时光-19436 小时前
Spring Boot 实战(三):Service 分层 + 统一返回 + 异常处理(工程级写法)
java·spring boot·接口·解耦
霸道流氓气质6 小时前
SpringBoot中集成LangChain4j实现集成阿里百炼平台进行AI对话记忆功能和对话隔离功能
java·人工智能·spring boot·langchain4j