springBoot-Mybatis
程序员文章站
2022-03-06 12:17:44
文章目录1. 前期准备1. 前期准备创建SpringBoot项目引入mysql驱动依赖和mybais依赖mysql爆红: mysql mysql-connector-java 解决问题:打开Settings -> Build,Execution,Dep...
文章目录
1. 前期准备
- 创建SpringBoot项目
- 引入mysql驱动依赖和mybais依赖
mysql报红:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
解决问题:
打开Settings -> Build,Execution,Deployment -> Build Tools -> Maven -> Ignored Files
:
打开:Settings -> Build,Execution,Deployment -> Build Tools -> Maven -> Importing
打开:File -> Maven ->
打开settings.xml
加入镜像:
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/
</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
删掉已经写好的依赖:
然后再写上即可
mybatis依赖
<!--Mybatis整合SpringBoot框架的起步依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
- 在
application.properties
添加数据库和mybatis配置或者配置application.yml
application.properties
# mysql
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
# mybatis
# 对应实体类的包名
mybatis.typeAliasesPackage=com.example.ewspace.enty
# mapper.xml文件所在位置,这里我放在resources下面
mybatis.mapperLocations=classpath:mapper/*Mapper.xml
application.yml
server:
port: 8081
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.example.ewspace.enty
- 可以写代码了
本文地址:https://blog.csdn.net/qq_45083168/article/details/112004079
上一篇: 快看点如何注销账号?快看点注销账号教程