当前位置: 代码迷 >> 综合 >> springboot项目使用注解法整合mybatis的具体步骤
  详细解决方案

springboot项目使用注解法整合mybatis的具体步骤

热度:7   发布时间:2024-01-17 04:47:54.0
1.properties文件添加如下配置
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=boot_user
spring.datasource.password=boot_user

mybatis.config-location=classpath: configs/mybatis-config.xml
mybatis.mapper-locations=classpath: com/study/bootstudy/mapper/*.xml
mybatis.type-aliases-package= com.study.bootstudy.model

2.pom.xml文件添加如下配置
<dependency>
  <groupId>org.mybatis.spring.boot</groupId>
  <artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>  
    <groupId>com.oracle</groupId> 
    <artifactId>ojdbc14</artifactId>  
    <version>11.1.0.6.0</version>  
</dependency>
注意: maven仓库不支持,ojdbc14未授权,需下载后,使用cmd手动导入本地仓库

3.application.java类添加以下注解,扫描DAO层(mapper接口)接口类,并注入上下文

@MapperScan("com.study.bootstudy.dao")

与properties文件中的*mapper.xml文件sql相匹配,实现sql和java代码分离

  相关解决方案