Spring Boot與mybatis整合

完整的項目截圖web

 

 一:pom依賴

新增ojdbc6及batis-spring-boot-starter依賴spring

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>



<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>

完整的依賴以下
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- 打成war的時候打開註釋,本地開發用內嵌tomcat時加上註釋 -->
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>



<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

二:編寫配置文件

1.Student實體類tomcat

 

 2.BootApplication類mybatis

 

 3,控制層oracle

 

 4:dao層app

注意類上的Mapper註釋maven

 

 5.service層ide

 

 6.XML映射文件spring-boot

 

 7.properties文件測試

 

 

三:測試

根據上篇文章打包成war包放入tomcat下,啓動tomcat(必定要注意idea自帶的tomcat與本地tomcat版本)

 

 

 

注意:

可能會報missing artface com.oracle:ojdbc...錯誤,這是因爲oracle驅動是收費驅動,不能直接下載,解決方案

oracle驅動先去官網下載,下載下來後,須要安裝到maven本地倉庫,而後再pom中添加依賴.

1下載oracle驅動包

ojdbc6-11.2.0.3.jar

2命令行安裝到maven倉庫

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3.0 -Dpackaging=jar -Dfile=E:\oracle-lib\ojdbc6-11.2.0.3.jar

3添加依賴

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>
相關文章
相關標籤/搜索