添加 pom.xml jar
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<!-- oracle -->
<dependency>
<groupId>org.clojars.zentrope</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.3.0</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
配置文件添加
mybatis:
mapper-locations: classpath:dao/*.xml
spring:
datasource:
url: jdbc:oracle:thin:@10.20.133.129:1521:gfzsh
username: icf
password: icf
在spring boot启动实体类中添加@MapperScan(“com.dao”)注解
接下来在创建Ctroller层Service层Dao层即可
本文详细介绍了如何在SpringBoot项目中引入MyBatis框架,包括添加依赖、配置数据源、设置MyBatis配置文件及使用@MapperScan注解。通过示例展示了针对Oracle和MySQL数据库的操作。

321

被折叠的 条评论
为什么被折叠?



