1. 程式人生 > >SpringBoot+MyBatis+Oracle增、刪、改、查、批處理及儲存過程Demo

SpringBoot+MyBatis+Oracle增、刪、改、查、批處理及儲存過程Demo

    本文著重偏重於:SpringBoot+MyBatis+Oracle的,增刪改查、批處理及儲存過程的Demo,原始碼見文末章節。

Demo概述

    使用SpringBoot和MyBatis,對Oracle資料的增、刪、改、查、批處理、及呼叫儲存過程,都做了示例程式碼及SQL的配置示例,對於各種引數傳遞方法,出入參型別等,也都做了示例或備註。

    本Demo使用資料庫為Scott/Tiger使用者自帶的EMP員工表,進行操作,所以資料庫建表等SQL不再貼出,只給出了分頁查詢的儲存過程SQL。

    專案結構截圖如下:

要點講解

呃,好吧,現在發現沒什麼可以講解了。

    好歹自己也是搞了近一個星期,配置SQL時候也是遇到各種問題,現在竟然發現也沒什麼難點、注意點需要著重講解了。可能是已經把關鍵點都添加了註釋吧。

  • 那就就你們看程式碼吧,要點都有註釋,著重看dbMapper.xml、DataMapper.java以及SQLTest.java檔案。
  • 定義了Employee類,對應資料庫scott.emp表結構。
  • 測試函式SQLTest.run()使用@Autowired註解,這樣在專案啟動時候,就自動載入運行了。
  • 多數人都會踏的坑:單句SQL後面不能有分號(語句塊則需要),不然ORA-00911異常,再強調下。

編譯執行

如何執行

  1. 專案右鍵->Run As -> Maven Clean;  
  2. Run As -> Maven Install;
  3. Spring Boot App;
  4. 檢視Console輸出結果。    

執行截圖

簡單查詢

    先查一下,工號大於7788的員工,一共7條資料。


插入後查詢

    插入工號為7979的員工資訊,JOB取值為JOB(批插會更新),COMM取值為235.65(更新操作會更新)。插入後,查詢出工號大於7788的員工,一共8條資料。


更新後查詢

    更新工號為7979的員工獎金數為555.25,之後查詢,除了獎金數其他未變動。


批量查詢

    查詢部門號為20和30的員工資訊。得到12條資料。


批插後查詢

    批量插入3條資料,其中工號7979的員工資訊為更新操作,其他插入的資料為新增操作。即新增了12+2條資料。


刪除後查詢

    刪除7979號員工資訊,再查工號大於7788的員工資訊,得到9
條,即原8+7980號和7981號員工的條資料,已經刪除的資料沒有查到。


批刪後查詢

    批量查詢得到12條資料(包括新增的7979),刪掉7979後,再批刪掉7980和7981後,得到11條,沒錯。


儲存過程分頁查詢

    每頁5條,查詢第3頁的資料。得到一共14條資料,分了3頁,並返回了第3頁的資料,4條,沒錯。

    兩個儲存過程結果一致。


原始碼福利

    先奉上專案原始碼下載地址:請點選我~~~然後每個檔案程式碼貼一下。

Application.java

package com.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

//Spring Boot 應用的標識
@ComponentScan(basePackages = {"com.demo"})
@SpringBootApplication
public class Application {

	public static void main(String[] args) {
		// 啟動嵌入式的 Tomcat 並初始化 Spring 環境及其各 Spring 元件
		SpringApplication.run(Application.class, args);
	}
}

DataMapper.java

package com.demo;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;


//對映Sql,定義介面
public interface DataMapper {	

	//查詢。@Param對應引數屬性註解,There is no getter for property named 'xx' in 'class java.lang.Integer
	List<Employee> test_query(@Param("EMPNO")Integer EMPNO);

	//插入
	void test_insert(Employee employee);

	//更新
	void test_update(@Param("EMPNO")Integer EMPNO, @Param("COMM")double COMM);

	//刪除
	void test_delete(Integer EMPNO);

	//批量插入
	void test_multi_insert(List<Employee> results);

	//批量查詢
	List<Employee> test_multi_query(int[] DEPTNOArr);

	//批量刪除
	void test_multi_delete(List<Integer> EMPNOList);

	//儲存過程
	void test_exe_procedure1(Map<String, Object> params);
	void test_exe_procedure2(Map<String, Object> params);
}

DataSourceConfig.java

package com.demo;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

@Configuration
//指定掃描的mapper介面所在的包
@MapperScan(basePackages = "com.demo", sqlSessionFactoryRef = "DBDataSqlSessionFactory")
public class DataSourceConfig {
	@Bean(name = "DBDataSource")	
	@ConfigurationProperties(prefix="spring.datasource") //告訴自動載入配置的屬性
	public DataSource dataSource() {
		return DataSourceBuilder.create().build();
	}

	@Bean(name = "DBDataSqlSessionFactory")
	public SqlSessionFactory  sqlSessionFactory(@Qualifier("DBDataSource") DataSource dataSource)
			throws Exception {
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		bean.setDataSource(dataSource);
		bean.setMapperLocations(
				new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/dbMapper.xml"));
		return bean.getObject();
	}

	@Bean(name = "DBDataTransactionManager")
	public DataSourceTransactionManager transactionManager(@Qualifier("DBDataSource") DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}

	@Bean(name = "DBDataSqlSessionTemplate")
	public SqlSessionTemplate sqlSessionTemplate(
			@Qualifier("DBDataSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
		return new SqlSessionTemplate(sqlSessionFactory);
	}
}

Employee.java

package com.demo;

import java.util.Date;
import java.util.List;

//使用資料庫系統自帶的資料表,對應scott.emp表
public class Employee {
	private Integer EMPNO;   //員工號
	private String  ENAME;   //員工名
	private String  JOB;     //工種
	private Integer MGR;     //上級
	private Date    HIREDATE;//入職日期
	private double  SAL;     //工資
	private double  COMM;    //獎金
	private Integer DEPTNO;  //部門號


	public String toString()
	{		
		String info = String.format("EMPNO[%d], ENAME[%s], JOB[%s], MGR[%d], HIREDATE[%tF], SAL[%.2f], COMM[%.2f], DEPTNO[%d]", EMPNO, ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO);
		return info;
	}

	public static void Print(List<Employee> empList)
	{
		int count = empList.size();	
		String format = String.format("Employee[%%%dd]: %%s", String.valueOf(count).length());
		String info = String.format("%5s, %7s, %10s, %4s, %10s, %7s, %7s, %s","EMPNO", "ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO");
		System.out.println(String.format(format, count,info));	
		for(int i=0;i<count;i++){
			Employee emp = empList.get(i);
			info = String.format("%5d, %7s, %10s, %4d, %tF, %7.2f, %7.2f, %d", emp.EMPNO, emp.ENAME,emp.JOB,emp.MGR,emp.HIREDATE,emp.SAL,emp.COMM,emp.DEPTNO);
			System.out.println(String.format(format, i,info));	
		}	
		return;
	}

	public Integer getEMPNO() {
		return EMPNO;
	}

	public void setEMPNO(Integer eMPNO) {
		EMPNO = eMPNO;
	}

	public String getENAME() {
		return ENAME;
	}

	public void setENAME(String eNAME) {
		ENAME = eNAME;
	}

	public String getJOB() {
		return JOB;
	}

	public void setJOB(String jOB) {
		JOB = jOB;
	}

	public Integer getMGR() {
		return MGR;
	}

	public void setMGR(Integer mGR) {
		MGR = mGR;
	}

	public Date getHIREDATE() {
		return HIREDATE;
	}

	public void setHIREDATE(Date hIREDATE) {
		HIREDATE = hIREDATE;
	}

	public double getSAL() {
		return SAL;
	}

	public void setSAL(double sAL) {
		SAL = sAL;
	}

	public double getCOMM() {
		return COMM;
	}

	public void setCOMM(double cOMM) {
		COMM = cOMM;
	}

	public Integer getDEPTNO() {
		return DEPTNO;
	}

	public void setDEPTNO(Integer dEPTNO) {
		DEPTNO = dEPTNO;
	}


}

SQLTest.java

package com.demo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.demo.DataMapper;

@Component
public class SQLTest {

	@Autowired
	DataMapper dataMapper;

	//自動載入,程式啟動時候就執行啦。。。。
	@Autowired
	public void run() {
		test_query();

		test_insert();
		test_query();

		test_update();
		test_query();

		test_multi_query();

		test_multi_insert();
		test_multi_query();		

		test_delete();
		test_query();

		test_multi_delete();
		test_multi_query();

		test_exe_procedure(true);
		test_exe_procedure(false);
	}

	private void test_query()
	{
		System.out.println("test_query...");	
		Integer EMPNO =7788;
		List<Employee> empList =dataMapper.test_query(EMPNO);
		Employee.Print(empList);
		return;
	}

	private void test_insert()
	{
		System.out.println("test_insert...");	
		Employee emp = new Employee();
		emp.setEMPNO(7979);
		emp.setENAME("ENAME");
		emp.setJOB("JOB");
		emp.setMGR(7566);
		emp.setHIREDATE(new Date());
		emp.setSAL(8799.76);
		emp.setCOMM(235.65);
		emp.setDEPTNO(20);
		dataMapper.test_insert(emp);
	}

	private void test_update()
	{
		System.out.println("test_update...");	
		dataMapper.test_update(7979, 555.25);
	}

	private void test_delete()
	{
		System.out.println("test_delete...");
		dataMapper.test_delete(7979);
	}

	private void test_multi_insert()
	{
		System.out.println("test_multi_insert...");	
		Employee emp1 = new Employee();
		emp1.setEMPNO(7980);
		emp1.setENAME("ENAME1");
		emp1.setJOB("JOB1");
		emp1.setMGR(7566);
		emp1.setHIREDATE(new Date());
		emp1.setSAL(8799.76);
		emp1.setCOMM(235.65);
		emp1.setDEPTNO(30);

		Employee emp2 = new Employee();
		emp2.setEMPNO(7981);
		emp2.setENAME("ENAME2");
		emp2.setJOB("JOB2");
		emp2.setMGR(7566);
		emp2.setHIREDATE(new Date());
		emp2.setSAL(8799.76);
		emp2.setCOMM(235.65);
		emp2.setDEPTNO(30);

		Employee emp3 = new Employee();
		emp3.setEMPNO(7979);
		emp3.setENAME("ENAME");
		emp3.setJOB("JOB2");
		emp3.setMGR(7566);
		emp3.setHIREDATE(new Date());
		emp3.setSAL(8799.76);
		emp3.setCOMM(235.65);
		emp3.setDEPTNO(20);

		List<Employee> empList = new ArrayList<Employee>();
		empList.add(emp1);
		empList.add(emp2);
		empList.add(emp3);
		dataMapper.test_multi_insert(empList);
	}

	private void test_multi_query()
	{
		System.out.println("test_multi_query...");	
		int[] DEPTNOArr = { 20, 30 };
		List<Employee> empList  =  dataMapper.test_multi_query(DEPTNOArr);
		Employee.Print(empList);
		return;		
	}

	private void test_multi_delete()
	{
		System.out.println("test_multi_delete...");	
		List<Integer> EMPNOList = new ArrayList<Integer>();		
		EMPNOList.add(7980);
		EMPNOList.add(7981);
		dataMapper.test_multi_delete(EMPNOList);
		return;		
	}

	private void test_exe_procedure(boolean bTestProcedure1)
	{
		int in_PAGE = 3;
		int in_ROWS =5;
		int inout_TOTAL_RECORDS=0;		
		int inout_TOTAL_PAGES = 0;

		HashMap<String,Object> mm=new HashMap<String,Object>();  
		mm.put("in_PAGE", in_PAGE);
		mm.put("in_ROWS", in_ROWS);
		mm.put("inout_TOTAL_RECORDS", inout_TOTAL_RECORDS);
		mm.put("inout_TOTAL_PAGES", inout_TOTAL_PAGES);
		mm.put("out_SYSCURSOR", new ArrayList<Employee>());

		if(bTestProcedure1)
		{
			System.out.println("test_exe_procedure1...");
			dataMapper.test_exe_procedure1(mm);
		}
		else
		{			
			System.out.println("test_exe_procedure2...");
			mm.put("in_SQL", "select t.EMPNO, t.ENAME, t.JOB, t.MGR, t.HIREDATE, t.SAL, t.COMM, t.DEPTNO from scott.emp t");
			dataMapper.test_exe_procedure2(mm);
		}

		System.out.println("Get in_PAGE: "+ mm.get("in_PAGE"));	
		System.out.println("Get in_ROWS: "+ mm.get("in_ROWS"));	
		System.out.println("Get inout_TOTAL_RECORDS: "+ mm.get("inout_TOTAL_RECORDS"));	
		System.out.println("Get inout_TOTAL_PAGES: "+ mm.get("inout_TOTAL_PAGES"));	
		List<Employee> empList = (List<Employee>)mm.get("out_SYSCURSOR");
		Employee.Print(empList);
		return;
	}	

}

db.sql

CREATE OR REPLACE procedure P_TEST_PAGING_QUERY
(
    p_pagesql   in varchar2,     --sql
    p_curPage     in out Number ,  --當前頁
    p_pageSize    in out Number ,  --每頁顯示記錄的條數
    p_totalRecords out Number,    --總記錄數
    p_totalPages out Number  ,    -- 總頁數 
    pageResultSet out  SYS_REFCURSOR              -- 輸出結果集遊標
)
as
  v_sql       varchar2(2000):='';  --sql語句
  v_startRecord Number;         --開始顯示的記錄數
  v_endRecord   Number;         --結束顯示的記錄條數

begin
   --記錄總記錄條數       
               v_sql:='select count(*) FROM (' || p_pagesql || ')';
               execute IMMEDIATE v_sql INTO p_totalRecords;
 
                        IF MOD(p_totalRecords,p_pageSize)=0 THEN
                          --得到整數則直接取得到的頁碼數否在原來的基礎上增加一個頁碼
                          p_totalPages:=p_totalRecords/p_pageSize;
                        ELSE
                          p_totalPages:=p_totalRecords/p_pageSize+1;
                        END IF;
                       
                        --驗證頁號
                        IF p_curPage<1 THEN
                          p_curPage:=1;
                        END IF;
                       
                        --如果取的當前頁大於總頁數則取最大頁數的資料
                        IF p_curPage>p_totalPages THEN
                          p_curPage:=p_totalPages;
                        END IF;
                       --實現分頁查詢
                        v_startRecord :=(p_curPage - 1) * p_pageSize + 1;
                        v_endRecord   :=p_curPage * p_pageSize;	
                        v_sql           := 'select * from (SELECT t.*, ROWNUM RN from (' || p_pagesql || ') t where rownum<=' || v_endRecord || ' ) where RN>=' ||v_startRecord;						
                        p_totalPages:=floor(p_totalPages);  --去整數總頁
                        OPEN pageResultSet FOR v_sql;
             exception
                when others then
                     CLOSE pageResultSet;					

end P_TEST_PAGING_QUERY;
/



 

dbMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!-- 對映檔案,對映到對應的SQL介面 -->
<mapper namespace="com.demo.DataMapper">

	<!--返回的結果集,用於關聯實體類屬性和資料庫欄位 -->
	<!--如果實體類屬性和資料庫屬性名保持一致,就不需要javaType和jdbcType(必須大寫)屬性 -->
	<resultMap id="Employee_resultMap" type="com.demo.Employee">
		<result column="EMPNO" property="EMPNO" javaType="java.lang.Integer" jdbcType="INTEGER" />
		<result column="ENAME" property="ENAME" javaType="java.lang.String" jdbcType="VARCHAR" />
		<result column="JOB" property="JOB" javaType="java.lang.String" jdbcType="VARCHAR" />
		<result column="MGR" property="MGR" javaType="java.lang.Integer" jdbcType="INTEGER" />
		<result column="HIREDATE" property="HIREDATE" javaType="java.util.Date" jdbcType="DATE"/>
		<result column="SAL" property="SAL" javaType="java.lang.Double" jdbcType="DOUBLE" />
		<result column="COMM" property="COMM" javaType="java.lang.Double" jdbcType="DOUBLE" />
		<result column="DEPTNO" property="DEPTNO" javaType="java.lang.Integer" jdbcType="INTEGER" />
	</resultMap>
	
	<!-- 查詢資料 -->
	<!-- 入參定義:在介面定義中使用@Param註解(單參/多參都可使用) -->
	<!-- 語句末尾不能有分號:ORA-00911: invalid character -->
	<select id="test_query" resultMap="Employee_resultMap">
		select t.EMPNO, t.ENAME, t.JOB, t.MGR, t.HIREDATE, t.SAL, t.COMM, t.DEPTNO from scott.emp t where 1=1 
		<if test="EMPNO != null">
			and t.EMPNO >= #{EMPNO}
		</if>	
		order by t.EMPNO
	</select>

	<!-- 插入資料 -->
	<!-- 入參定義:實體類,會自動解析屬性到對應的值-->
	<insert id="test_insert" parameterType="com.demo.Employee">
		insert into scott.emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
		values (#{EMPNO}, #{ENAME}, #{JOB}, #{MGR}, #{HIREDATE}, #{SAL}, #{COMM}, #{DEPTNO})
	</insert>
	
	<!-- 更新資料 -->
	<!-- 入參定義:在介面定義中使用@Param註解(多參情況,只能使用這種形式) -->
	<update id="test_update">
		UPDATE scott.emp SET COMM = #{COMM}
		WHERE EMPNO = #{EMPNO}
	</update>
	
	<!-- 刪除資料 -->
	<!-- 入參定義:parameterType指定輸入引數(單參情況,亦可@Param註解) -->
	<delete id="test_delete" parameterType="java.lang.Integer">
		DELETE FROM scott.emp t WHERE t.EMPNO =#{EMPNO}
	</delete>

	<!-- 批量查詢 -->
	<!-- 入參定義:使用[]陣列array -->
	<select id="test_multi_query"  parameterType="int[]" resultMap="Employee_resultMap">
		select t.EMPNO, t.ENAME, t.JOB, t.MGR, t.HIREDATE, t.SAL, t.COMM, t.DEPTNO from scott.emp t where t.DEPTNO in
		<!-- arr:array中的具體值 -->
		<foreach collection="array" item="arr" index="no" open="(" separator="," close=")">  
            #{arr}  
        </foreach>
	</select>	
	
	<!-- 批量插入 -->
	<!-- 入參定義:使用List集合物件 -->
	<insert id="test_multi_insert" parameterType="java.util.List">
		merge into scott.emp r 
		    <!-- insert 和update中所有的資料都需要從using中獲取 -->
			using(
			<!-- item:list中的具體物件 -->
			<foreach collection="list" index="index" item="item" open="" close="" separator="union">
				select
					#{item.EMPNO,jdbcType=INTEGER} as EMPNO,
					#{item.ENAME,jdbcType=VARCHAR} as ENAME,
					#{item.JOB,jdbcType=VARCHAR} as JOB,
					#{item.MGR,jdbcType=INTEGER} as MGR,
					#{item.HIREDATE,jdbcType=DATE} as HIREDATE,
					#{item.SAL,jdbcType=DOUBLE} as SAL,
					#{item.COMM,jdbcType=DOUBLE} as COMM,
					#{item.DEPTNO,jdbcType=INTEGER} as DEPTNO
				from dual
			</foreach>
			) tmp 
			<!-- on後面的括弧不能省 -->
			on ( tmp.EMPNO = r.EMPNO)
		when matched THEN
			update set
			<!-- ORA-38104: 在on條件中的列是不可以更新的 -->
			<!-- r.EMPNO = tmp.EMPNO, -->
			r.ENAME = tmp.ENAME,
			r.JOB = tmp.JOB,
			r.MGR = tmp.MGR,
			r.HIREDATE = tmp.HIREDATE,
			r.SAL = tmp.SAL,
			r.COMM = tmp.COMM,
			r.DEPTNO = tmp.DEPTNO
		when not matched THEN
			insert
			<trim prefix="(" suffix=")" suffixOverrides=",">
				EMPNO,
				ENAME,
				JOB,
				MGR,
				HIREDATE,
				SAL,
				COMM,
				DEPTNO
			</trim>
			<trim prefix="values (" suffix=")" suffixOverrides=",">
				tmp.EMPNO,
				tmp.ENAME,
				tmp.JOB,
				tmp.MGR,
				tmp.HIREDATE,
				tmp.SAL,
				tmp.COMM,
				tmp.DEPTNO
			</trim>
	</insert>

	<!-- 批量刪除 -->
	<delete id="test_multi_delete">
		<!-- delete from emp where empno in(7980,7981) --> 
		delete from scott.emp t where t.empno in
		 <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
			  #{item}  
 			</foreach>
	</delete>
	
	<!-- 執行儲存過程。語句型別statementType一定要為CALLABLE-->
	<!-- 入參定義:佔位符形式寫入SQL,然後介面中使用MAP傳入 -->
	<!-- 引數模式:共IN、OUT、INOUT三種,如果是IN參可不寫,此外IN存在 null的情況,必須指定 jdbcType,還有 OUT時必須指定 jdbcType -->
	<select id="test_exe_procedure1" statementType="CALLABLE">
		{CALL
		P_TEST_PAGING_QUERY(
		'select t.EMPNO, t.ENAME, t.JOB, t.MGR, t.HIREDATE, t.SAL, t.COMM, t.DEPTNO from scott.emp t',
		#{in_PAGE, mode=IN, jdbcType=INTEGER},
		#{in_ROWS, mode=IN, jdbcType=INTEGER},
		#{inout_TOTAL_RECORDS,mode=INOUT, jdbcType=INTEGER},
		#{inout_TOTAL_PAGES, mode=INOUT, jdbcType=INTEGER},
		#{out_SYSCURSOR, mode=OUT, jdbcType=CURSOR, javaType=java.sql.ResultSet, resultMap=Employee_resultMap}
		)}
	</select>
	
	<!-- 執行儲存過程2-->
	<!-- 入參定義:使用parameterMap進行引數對映,這時候儲存過程引數佔位符為:? -->
	<!-- 注意:呼叫儲存過程的兩個大括號和中間的內容不要換行!可能會出問題的。正確姿勢:{CALL xxx(?,?...)} -->
	<parameterMap type="java.util.Map" id="test_exe_procedure2_param">
		<parameter property="in_SQL" mode="IN" jdbcType="INTEGER" />
		<parameter property="in_PAGE" mode="IN" jdbcType="INTEGER" />
		<parameter property="in_ROWS" mode="IN" jdbcType="INTEGER" />
		<parameter property="inout_TOTAL_RECORDS" mode="INOUT" jdbcType="INTEGER" />
		<parameter property="inout_TOTAL_PAGES" mode="INOUT" jdbcType="INTEGER" />
		<parameter property="out_SYSCURSOR" mode="OUT" jdbcType="CURSOR" javaType="java.sql.ResultSet" resultMap="Employee_resultMap" />
	</parameterMap>
	<select id="test_exe_procedure2" statementType="CALLABLE" parameterMap="test_exe_procedure2_param">
		{CALL P_TEST_PAGING_QUERY(?,?,?,?,?,?)}
	</select>

</mapper>

application.properties

server.port=18077
server.address=127.0.0.1
server.contextPath=/
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:dev2018
spring.datasource.username=system
spring.datasource.password=oracle
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>come.demo.SpringBootMyBatis</groupId>
	<artifactId>SpringBootMyBatis</artifactId>
	<version>1.0.0</version>
	<packaging>jar</packaging>

	<name>SpringBootMyBatis</name>
	<description>SpringBootMyBatis</description>

	<!-- lookup parent from repository -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
		<relativePath />
	</parent>
		
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-aop</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.3.1</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>
		</dependency>

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

	<build>
		<plugins>	
			<plugin>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-maven-plugin</artifactId>
					<configuration>
						<maimClass>com.demo.Application</maimClass>
					</configuration>
					<executions>
						<execution>
							<goals>
								<goal>repackage</goal>
							</goals>
						</execution>
					</executions>
				</plugin>		
			<!-- Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<testFailureIgnore>true</testFailureIgnore>
				</configuration>
			</plugin>
			
			<!-- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1: -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<verbose>true</verbose>
					<fork>true</fork>
					<executable>${JAVA8_HOME}/bin/javac</executable>
				</configuration>
			</plugin>  
		</plugins>
		<defaultGoal>compile</defaultGoal>
	</build>


</project>

    所以最後,再貼一遍原始碼地址:https://github.com/deargo/SpringBootMyBatis

    最後,大家互相學習吧!