前面两天介绍了vue前端的主体框架,并完成了相关页面的部分设置,接下来开始介绍springboot后端开发的过程,手把手实践。包括项目的初始构建以及集成mybatis、mybatis-plus实现增删改查,分页查询,集成swagger-ui测试,前后端联调等。敬请期待~~~~~~
目录
1、创建springboot工程:
2、配置pom文件
3、配置application.properties连接数据库
创建user表
5. pom.xml
6、SpringBoot启动配置
1、创建springboot工程:
-
点击 Spring Initializr , 选择 JDK 版本 ,选择 Default ,点击 Next;
-
填写Group 和 Artifact 信息,选择对应的开发语言,打包方式,Java 版本等 ,点击 Next;
-
选择 Web 依赖 和 Spring Boot 版本号,点击 Next;
-
选择项目的保存位置,点击 FINISH
具体可以参考博客中内容,详细介绍了如何搭建springboot项目!!!
(8条消息) 使用Idea搭建SpringBoot项目_idea发布springboot项目_Siobhan. 明鑫的博客-CSDN博客
2、配置pom文件
pom里配置阿里云仓库
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
3、配置application.properties连接数据库
# Web Application Configuration
server.port=8088
# Database Configuration
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/gra_project?characterEncoding=utf8&serverTimezone=GMT%2b8
# 北京时间==东八区时间!=北京当地时间 serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
也可改为yml形式,application.yml:(等号改为冒号+空格)使用 “key:(空格)value”格式配置属性,使用缩进控制层级关系。相比properties文件更简洁
server:
port: 8088
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/gra_project?serverTimezone=GMT%2b8
username: root
password: root
4、navicat创建数据库
创建user表
5. pom.xml
这里提供给大家我的pom文件,后续集成其他框架eg:mybatis、mybatis-plus、swagger等会再做补充!
<?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.7.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.smx</groupId>
<artifactId>gra-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gra-project</name>
<description>The graduate project management system designed by Shen Mingxin</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Mysql数据库驱动 -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!--修改版本-->
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
6、SpringBoot启动配置
下一节,我们更新springboot集成mybatis实现增删改查操作!