搭建springBoot框架,并简单实现连接本地数据库进行查询 (不好使,你找我)

在帮助朋友搭建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模拟客户端调用接口,返回数据,结束。

以上!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值