1、pom文件加入依赖
<!--加入mybatis依赖--> <!--引入satrter--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.2</version> </dependency> <!--mysql的jdbc驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--引入第三方数据源--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.8</version> </dependency>
2、application.properties配置文件
#===============================数据库相关====================================== #数据库驱动(可以自动识别) #spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC spring.datasource.username=username spring.datasource.password=password #修改数据源(com.zaxxer.hikari.HikariDataSource) spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
useUnicode=true&characterEncoding=UTF-8:防止中文乱码serverTimezone=UTC:设置时间,UTC是世界标准时间未设置时间报数据库连接错误:The server time zone value ‘?й???????‘ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
3、添加mapper扫描
@MapperScan("mapper包路径")
4、开发mapper
原文地址:https://www.cnblogs.com/jwmdlm/p/12591854.html
时间: 2024-10-07 11:45:02