当前位置: 首页 > news >正文

5分钟快速搭建一个 SpringBoot3 + MyBatis-Plus 工程项目

环境

idea 2023.3.5
jdk 17
mysql 8

创建SpringBoot工程

创建SpringBoot工程,这里有两种方式可选,一种是使用idea提供的Spring Initializr自动创建,一种是通过Maven Archetype手动创建

自动创建SpringBoot工程

使用Spring Initializr创建,这里选择Maven类型,JDKJava选择17,选择后点击Next
在这里插入图片描述

上方选择自己想要的spring boot版本,下方在Web栏勾选Spring Web,选择后点击Create
在这里插入图片描述
pom.xml文件的右上角点击maven图标刷新maven依赖
在这里插入图片描述
刷新后,在工程名 + Application的文件中可以启动这个springBoot项目
在这里插入图片描述
这里我们创建一个/hello/word路径来做测试,在com.jiunian.springboot_mybatisplus_auto下创建controller包,并创建HelloController

@RestController
@RequestMapping("/hello")
public class HelloController {@RequestMapping("/world")public String helloWorld() {return "Hello World!";}
}

在这里插入图片描述
启动SpringbootMybatisplusAutoApplication
在这里插入图片描述
在下方的终端输出可以看出,项目启动在8080端口的/目录下
在这里插入图片描述
尝试访问,访问成功
在这里插入图片描述

手动创建SpringBoot工程

选择Maven Archetype方式创建项目,在Archetype处选择quickstart选项,选择后点击Create
在这里插入图片描述
等待项目创建完成,修改pom.xml文件添加springboot父类并添加spring-boot-web依赖,修改后需要点击右上角maven图标刷新依赖

  <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.1</version></parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><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 http://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>3.4.1</version></parent><groupId>com.jiunian</groupId><artifactId>springboot_mybatisplus_manual</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>springboot_mybatisplus_manual</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>

将初始提供给我们的App类重构,改名为SpringBootMyBatisPlusManualApplication,并将其内容修改为下方方式

package com.jiunian;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBootMyBatisPlusManualApplication
{public static void main( String[] args ){// 第一个参数是当前类的.classSpringApplication.run(SpringBootMyBatisPlusManualApplication.class, args);}
}

创建该项目的spring配置文件,在main下新创建一个文件夹,resources
在这里插入图片描述
在resource目录下创建一个application.yaml文件或application.properties,没有修改配置需求时可以不写东西
在这里插入图片描述
最后,和自动创建一样,创建一个/hello/word路径来做测试,在com.jiunian下创建controller包,并创建HelloController

@RestController
@RequestMapping("/hello")
public class HelloController {@RequestMapping("/world")public String helloWorld() {return "Hello World!";}
}

在这里插入图片描述
启动SpringbootMybatisplusManualApplication
在这里插入图片描述

在下方的终端输出可以看出,项目启动在8080端口的/目录下
在这里插入图片描述

尝试访问,访问成功
在这里插入图片描述

整合MyBatis-Plus

我这里使用手动创建的SpringBoot工程继续整合MyBatis-Plus,修改项目pom.xml,导入mybatis-pluslombokmysql-connector-java,其中lombok是用于简化类开发,修改后,记得更新maven依赖

<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 http://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>3.4.1</version></parent><groupId>com.jiunian</groupId><artifactId>springboot_mybatisplus_manual</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>springboot_mybatisplus_manual</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.27</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.8</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies>
</project>

修改application.yaml文件,配置数据库连接

spring:datasource:# 连接的数据库地址url: jdbc:mysql:///mybatis?useSSL=false# 数据库用户名称username: root# 该用户的密码password: 123456

为了测试是否配置成功,我们创建数据库mybatis

create table mybatis

创建dept表

CREATE TABLE dept (id INT NOT NULL PRIMARY KEY,name VARCHAR(255) NOT NULL,address VARCHAR(255) NOT NULL,age INT NOT NULL,sex VARCHAR(255) NOT NULL
);

插入语句

INSERT INTO dept VALUES (1, '张三', 25, '男', '北京');
INSERT INTO dept VALUES (2, '李四', 26, '男', '上海');
INSERT INTO dept VALUES (3, '王五', 30, '女', '天津');

创建对应的pojoDept,在com.jiunian下创建一个pojo包并在其下创建Dept

package com.jiunian.pojo;import lombok.Data;
// 这里使用了lombok的注解
// 能够自动生成所有属性对应的getters/setters、equals、hashCode和toString方法
// 如果不使用 @TableName 注解,MyBatis-Plus 默认会使用实体类的类名作为表名(默认是首字母小写,驼峰转下划线形式)
@Data
public class Dept {private int id;private String name;private int age;private String sex;private String address;
}

如下图结构创建该类的MapperServiceServiceImpl
在这里插入图片描述
DeptMapper

package com.jiunian.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiunian.pojo.Dept;
import org.apache.ibatis.annotations.Mapper;@Mapper
// 继承BaseMapper<T>接口,可以直接调用Mybatis-Plus提供的CRUD方法
public interface DeptMapper extends BaseMapper<Dept> {
}

DeptService

package com.jiunian.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.jiunian.pojo.Dept;public interface DeptService extends IService<Dept> {
}

DeptServiceImpl

package com.jiunian.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiunian.mapper.DeptMapper;
import com.jiunian.pojo.Dept;
import com.jiunian.service.DeptService;
import org.springframework.stereotype.Service;@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
}

controller下为Dept创建一个控制类DeptController

package com.jiunian.controller;import com.jiunian.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/dept")
public class DeptController {@Autowiredprivate DeptService deptService;@RequestMapping("/getAll")public String getAll() {return deptService.list().toString();}
}

接下来访问localhost:8080/dept/getAll来检查是否连接成功,如下图所示,连接成功
在这里插入图片描述

相关文章:

5分钟快速搭建一个 SpringBoot3 + MyBatis-Plus 工程项目

环境 idea 2023.3.5 jdk 17 mysql 8 创建SpringBoot工程 创建SpringBoot工程&#xff0c;这里有两种方式可选&#xff0c;一种是使用idea提供的Spring Initializr自动创建&#xff0c;一种是通过Maven Archetype手动创建 自动创建SpringBoot工程 使用Spring Initializr创建…...

如何判断https使用了哪个版本的TLS?

互联网各领域资料分享专区(不定期更新): Sheet 正文 一、使用浏览器开发者工具(适合普通用户) 1. Google Chrome 打开目标网站(如 https://example.com)。点击地址栏左侧的 锁形图标。选择 「连接是安全的」 → 「证书信息」。在证书详情中,查看 「技术详细信息」 或 「…...

如何在 NocoBase 中实现 CRM 的线索转化

1. 引言 本教程将一步一步地引导您如何在 NocoBase 中实现 CRM 的商机转化&#xff08;Opportunity Conversion&#xff09;功能。我们将介绍如何创建所需的 collections&#xff08;数据表&#xff09;、配置数据管理页面、设计转化流程以及设置关联管理&#xff0c;从而帮助…...

StarRocks-fe工程在Cursor中不能识别为Java项目

SR简介 StarRocks 是一款高性能分析型数据库&#xff0c;支持实时、多维度、高并发的数据分析。本指南旨在解决在使用 VSCode 或 Cursor 开发 StarRocks 后端项目时遇到的模块识别问题。 问题描述 使用 Cursor 或 VSCode 打开 StarRocks 的后端工程 fe 时&#xff0c;spark-…...

影刀RPA开发拓展--SQL常用语句全攻略

前言 SQL&#xff08;结构化查询语言&#xff09;是数据库管理和操作的核心工具&#xff0c;无论是初学者还是经验丰富的数据库管理员&#xff0c;掌握常用的 SQL 语句对于高效管理和查询数据都至关重要。本文将系统性地介绍最常用的 SQL 语句&#xff0c;并为每个语句提供详细…...

05类加载机制篇(D6_方法调用和方法执行)

目录 一、字节码指令集 二、基本数据类型 1. 加载和存储指令 2. const系列 3. push系列 4. ldc系列 5. load系列 load系列A load系列B 6. store系列 store系列A store系列B 7. pop系列 8. 栈顶元素数学操作及移位操作系列 9. 运算指令 10. 类型转换指令 11. 宽…...

视音频数据处理入门:颜色空间(二)---ffmpeg

目录 概述 流程 相关流程 初始化方法 初始化代码 转换方法 转换代码 释放方法 整体代码介绍 代码路径 概述 本篇简单说一下基于FFmpeg的libswscale的颜色空间转换&#xff1b;Libswscale里面实现了各种图像像素格式的转换&#xff0c;例如&#xff1a;YUV与RGB之间的…...

从零开始:H20服务器上DeepSeek R1 671B大模型部署与压力测试全攻略

前言 最近&#xff0c;我有幸在工作中接触到了DeepSeek R1 671B模型&#xff0c;这是目前中文开源领域参数量最大的高质量模型之一。DeepSeek团队在2024年推出的这款模型&#xff0c;以其惊人的6710亿参数量和出色的推理性能&#xff0c;引起了业界广泛关注。 作为一名AI基础…...

【FAQ】HarmonyOS SDK 闭源开放能力 —Map Kit(5)

1.问题描述&#xff1a; 提供两套标准方案&#xff0c;可根据体验需求选择&#xff1a; 1.地图Picker(地点详情) 用户体验&#xff1a;①展示地图 ②标记地点 ③用户选择已安装地图应用 接入文档&#xff1a;https://developer.huawei.com/consumer/cn/doc/harmonyos-guide…...

Leetcode 3469. Find Minimum Cost to Remove Array Elements

Leetcode 3469. Find Minimum Cost to Remove Array Elements 1. 解题思路2. 代码实现 题目链接&#xff1a;3469. Find Minimum Cost to Remove Array Elements 1. 解题思路 这一题我没啥特别好的思路&#xff0c;就只能动态规划了&#xff0c;倒是也能过&#xff0c;不过总…...

Excel的行高、列宽单位不统一?还是LaTeX靠谱

想要生成田字格、米字格、带拼音标准&#xff0c;方便小学生书法和练字。Word&#xff0c;Excel之类所见即所得是最容易相当的方式。但它们处理带田字格之类背景时&#xff0c;如果没有专用模板、奇奇怪怪的插件&#xff0c;使用起来会碰到各种问题。比如&#xff0c;Word里面用…...

(新版本onenet)stm32+esp8266/01s mqtt连接onenet上报温湿度和远程控制(含小程序)

物联网实践教程&#xff1a;微信小程序结合OneNET平台MQTT实现STM32单片机远程智能控制 远程上报和接收数据——汇总 前言 之前在学校获得了一个新玩意&#xff1a;ESP-01sWIFI模块&#xff0c;去搜了一下这个小东西很有玩点&#xff0c;远程控制LED啥的&#xff0c;然后我就想…...

告别GitHub连不上!一分钟快速访问方案

一、当GitHub抽风时&#xff0c;你是否也这样崩溃过&#xff1f; &#x1f621; npm install卡在node-sass半小时不动&#x1f62d; git clone到90%突然fatal: early EOF&#x1f92c; 改了半天hosts文件&#xff0c;第二天又失效了... 根本原因&#xff1a;传统代理需要复杂…...

迷你世界脚本对象库接口:ObjectLib

对象库接口&#xff1a;ObjectLib 迷你世界 更新时间: 2023-04-26 20:21:09 具体函数名及描述如下: 序号 函数名 函数描述 1 getAreaData(...) 获取区域数据 2 getPositionData(...) 获取位置数据 3 getLivingData(...) 获取生物数据 4 getItemDat…...

数据库事务、乐观锁及悲观锁

参考&#xff1a;node支付宝支付及同步、异步通知、主动查询支付宝订单状态 以下容结合上述链接查看 1. 什么是数据库事务&#xff1f; 1.1. 连续执行数据库操作 在支付成功后&#xff0c;我们在自定义的paidSuccess里&#xff0c;依次更新了订单状态和用户信息。也就说这里…...

蓝桥王国--dij模板

#include <bits/stdc.h> // 万能头 using namespace std; typedef pair<long long ,int> PII; int n,m; long long d[300011]; struct edge///邻接表 {int v;long long w; }; int vis[300011]; vector<edge> mp[300011];///邻接表 void dij(int s)///dij单源…...

Java基础关键_017_集合(一)

目 录 一、概述 二、Collection 关系结构 1.概览 2.说明 三、Collection 接口 1.通用方法 &#xff08;1&#xff09;add(E e) &#xff08;2&#xff09;size() &#xff08;3&#xff09;addAll(Collection c) &#xff08;4&#xff09;contains(Object o) &#…...

Rust编程实战:Rust实现简单的Web服务,单线程性能问题

知识点 tcp 服务多线程处理 实现功能 启动web服务&#xff0c;访问链接获取页面内容。 单线程web服务 TcpListener 使用 TcpListener 开启服务端口 let listener TcpListener::bind("127.0.0.1:7878").unwrap();处理客户端连接&#xff1a; for stream in lis…...

GitLab 密钥详解:如何安全地使用 SSH 密钥进行身份验证

目录 一、什么是 GitLab SSH 密钥&#xff1f;二、为什么要使用 SSH 密钥&#xff1f;三、如何生成 SSH 密钥&#xff1f;1. Linux/macOS2. Windows 四、将公钥添加到 GitLab五、配置 SSH 客户端六、常见问题及解决方案七、总结 GitLab 是一个功能强大的 Git 仓库管理平台&…...

《论数据分片技术及其应用》审题技巧 - 系统架构设计师

论数据分片技术及其应用写作框架 一、考点概述 本论题“论数据分片技术及其应用”主要考察的是软件工程中数据分片技术的理解、应用及其实际效果分析。考点涵盖以下几个方面&#xff1a; 首先&#xff0c;考生需对数据分片的基本概念有清晰的认识&#xff0c;理解数据分片是…...

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…...

Debian系统简介

目录 Debian系统介绍 Debian版本介绍 Debian软件源介绍 软件包管理工具dpkg dpkg核心指令详解 安装软件包 卸载软件包 查询软件包状态 验证软件包完整性 手动处理依赖关系 dpkg vs apt Debian系统介绍 Debian 和 Ubuntu 都是基于 Debian内核 的 Linux 发行版&#xff…...

将对透视变换后的图像使用Otsu进行阈值化,来分离黑色和白色像素。这句话中的Otsu是什么意思?

Otsu 是一种自动阈值化方法&#xff0c;用于将图像分割为前景和背景。它通过最小化图像的类内方差或等价地最大化类间方差来选择最佳阈值。这种方法特别适用于图像的二值化处理&#xff0c;能够自动确定一个阈值&#xff0c;将图像中的像素分为黑色和白色两类。 Otsu 方法的原…...

云原生安全实战:API网关Kong的鉴权与限流详解

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、基础概念 1. API网关&#xff08;API Gateway&#xff09; API网关是微服务架构中的核心组件&#xff0c;负责统一管理所有API的流量入口。它像一座…...

GitHub 趋势日报 (2025年06月06日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...

k8s从入门到放弃之HPA控制器

k8s从入门到放弃之HPA控制器 Kubernetes中的Horizontal Pod Autoscaler (HPA)控制器是一种用于自动扩展部署、副本集或复制控制器中Pod数量的机制。它可以根据观察到的CPU利用率&#xff08;或其他自定义指标&#xff09;来调整这些对象的规模&#xff0c;从而帮助应用程序在负…...

macOS 终端智能代理检测

&#x1f9e0; 终端智能代理检测&#xff1a;自动判断是否需要设置代理访问 GitHub 在开发中&#xff0c;使用 GitHub 是非常常见的需求。但有时候我们会发现某些命令失败、插件无法更新&#xff0c;例如&#xff1a; fatal: unable to access https://github.com/ohmyzsh/oh…...

CppCon 2015 学习:Reactive Stream Processing in Industrial IoT using DDS and Rx

“Reactive Stream Processing in Industrial IoT using DDS and Rx” 是指在工业物联网&#xff08;IIoT&#xff09;场景中&#xff0c;结合 DDS&#xff08;Data Distribution Service&#xff09; 和 Rx&#xff08;Reactive Extensions&#xff09; 技术&#xff0c;实现 …...

五、jmeter脚本参数化

目录 1、脚本参数化 1.1 用户定义的变量 1.1.1 添加及引用方式 1.1.2 测试得出用户定义变量的特点 1.2 用户参数 1.2.1 概念 1.2.2 位置不同效果不同 1.2.3、用户参数的勾选框 - 每次迭代更新一次 总结用户定义的变量、用户参数 1.3 csv数据文件参数化 1、脚本参数化 …...

职坐标物联网全栈开发全流程解析

物联网全栈开发涵盖从物理设备到上层应用的完整技术链路&#xff0c;其核心流程可归纳为四大模块&#xff1a;感知层数据采集、网络层协议交互、平台层资源管理及应用层功能实现。每个模块的技术选型与实现方式直接影响系统性能与扩展性&#xff0c;例如传感器选型需平衡精度与…...