在帮助朋友搭建SpringBoot框架的契机,整理了此篇博客,照着我的步骤依次进行,我保证你会成功的!
一:首选,我们去官网现在 sts (SpringToolSuites)编译软件
地址:https://spring.io/tools 可以选择Idea or eclipse (本博客采用eclipse)
二:下载好了之后,打开编译编译软件,如图所示,点击左上角,file — new project 选择 Spring Starter Project
三 :子页面介绍
四:直接点击 Next 进入 版本管理及Jar包 选择框
注:(此博客介绍的是 springBoot版本 为 2.1.6的搭建过程,如果同学切换不了2.1.6 请查阅博客地址:https://blog.csdn.net/weixin_43975867/article/details/89553311版本为 2.1.4)
其他:(若同学不了解什么是 pom.xml,及Jar配置文件,可自行学习下 SpringBoot之主配置文件 pom.xml)
五:finish之后,我们的原始项目就创建好了
六:修改 pom.xml配置文件
1 基础部分:
七: jar包 部分配置
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</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-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
</dependencies>
3 扫描配置部分
注 2: 以 <dependencies> 为开头, </dependencies>为结尾 中间的内容 替换到你的 pom.xml文件
注 3: 以<build> 开头,</build>结尾 的片段 为扫描资源文件的过程,不可缺少
八:配置本地数据库链接文件
#服务端口号
server.port=8080
#以Tomcat为web容器时的字符编码
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.force=true
spring.http.encoding.enabled=true
#若出现时间乱码问题 ,url后+ &serverTimezone=UTC
spring.datasource.url=jdbc:mysql://localhost:3306/chenpengfei?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
#配置mybatis 扫描mapper.xml文件
mybatis.mapper-locations=classpath*:com/example/demo/mapper/*.xml
8:创建基础文件路径
九:配置启动类扫描文件
十:实例代码
1:mapper.xml
2: dao接口
3:service
4:controller
运行springBoot
postMan模拟客户端调用接口,返回数据,结束。
以上!