java使用mybatis調(diào)用存儲(chǔ)過(guò)程返回一個(gè)游標(biāo)結(jié)果集方式
環(huán)境
- 系統(tǒng)平臺(tái):IBM:Linux on System z Red Hat Enterprise Linux 7
- 版本:6.0,4.5
文檔用途
- mybatis調(diào)用存儲(chǔ)過(guò)程返回游標(biāo)接收結(jié)果集。
詳細(xì)信息
1.service實(shí)現(xiàn)類(lèi)
@Override @Transactional public List<HighgoFunOneRefcursorEntity> getOneRefcursor(Integer id) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("id", id); highgoFunOneRefcursorDao.getOneRefcursor(map); List<HighgoFunOneRefcursorEntity> list = (List<HighgoFunOneRefcursorEntity>)map.get("result"); return list; }
2.dao層
@Mapper public interface HighgoProOneRefcursorDao extends BaseMapper<HighgoProOneRefcursorEntity> { ArrayList<Map<String, Object>> getProOneRefcursor(HashMap map); }
3.mapper
<?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"> <mapper namespace="com.database.mybatisplus.modules.demo.dao.HighgoProOneRefcursorDao"> <!-- 可根據(jù)自己的需求,是否要使用 --> <resultMap type="com.database.mybatisplus.modules.demo.entity.HighgoProOneRefcursorEntity" id="highgoProOneRefcursorMap"> <result property="hanzi" column="hanzi"/> <result property="quanpin" column="quanpin"/> <result property="szm" column="szm"/> <result property="duyin" column="duyin"/> <result property="numbersd" column="numbersd"/> <result property="sd" column="sd"/> <result property="repsd" column="repsd"/> <result property="hzascii" column="hzascii"/> </resultMap> <!-- 調(diào)用存儲(chǔ)過(guò)程返回一個(gè)游標(biāo) --> <select id="getProOneRefcursor" parameterType="map" statementType="CALLABLE" resultType="java.util.Map"> {call sp_one_refcursor(#{id,mode=IN},null,#{result,mode=OUT,jdbcType=OTHER,javaType=ResultSet,resultMap=highgoFunOneRefcursorMap})} </select> </mapper>
4.數(shù)據(jù)庫(kù)過(guò)程
CREATE OR REPLACE PROCEDURE test.sp_one_refcursor(integer, INOUT refcursor) LANGUAGE plpgsql AS $procedure$ begin if $1 = 1 then open $2 for select * from hzpyszm limit 100; elseif $1 = 2 then open $2 for select hanzi,quanpin,szm,duyin from hzpyszm limit 100; else open $2 for select hanzi,quanpin from hzpyszm limit 100; end if; exception when others then raise exception 'sql exception--%',sqlerrm; end; $procedure$ ;
5.jdbc參數(shù)
url: jdbc:highgo://192.168.21.138:5870/test?escapeSyntaxCallMode=callIfNoReturn
6.數(shù)據(jù)庫(kù)表
CREATE TABLE hzpyszm ( hanzi varchar(4) NULL, quanpin varchar(10) NULL, szm varchar(5) NULL, duyin varchar(10) NULL, numbersd varchar(1) NULL, sd varchar(5) NULL, repsd varchar(5) NULL, hzascii int8 NULL ); CREATE INDEX hzpyszm_hanzi_idx ON test.hzpyszm USING btree (hanzi varchar_pattern_ops); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('唔', 'ngn', 'n', 'ńgń', '2', NULL, NULL, 21780); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匌', 'ge', 'g', 'gé', '2', 'é', 'e', 21260); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匍', 'pu', 'p', 'pú', '2', 'ú', 'u', 21261); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匎', 'e', 'e', 'è', '4', 'è', 'e', 21262); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匏', 'pao', 'p', 'páo', '2', 'á', 'a', 21263); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匐', 'fu', 'f', 'fú', '2', 'ú', 'u', 21264); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匑', 'gong', 'g', 'gōng', '1', 'ō', 'o', 21265); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匒', 'da', 'd', 'dá', '2', 'á', 'a', 21266); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匓', 'jiu', 'j', 'jiù', '4', 'ù', 'u', 21267); INSERT INTO hzpyszm (hanzi, quanpin, szm, duyin, numbersd, sd, repsd, hzascii) VALUES('匔', 'gong', 'g', 'gōng', '1', 'ō', 'o', 21268);
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
springboot集成nacos報(bào)錯(cuò):get data from Nacos
這篇文章給大家介紹了springboot集成nacos報(bào)錯(cuò):get data from Nacos error,dataId:null.yaml的原因及解決方法,如果又遇到相同問(wèn)題的朋友可以參考閱讀本文2023-10-10springboot yml定義屬性,下文中${} 引用說(shuō)明
這篇文章主要介紹了springboot yml定義屬性,下文中${} 引用說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04Spring?框架的?MethodInterceptor?簡(jiǎn)介及示例代碼
MethodInterceptor接口定義了一個(gè)方法Object?intercept(Object?obj,?Method?method,?Object[]?args,?MethodProxy?proxy)?,該方法在代理對(duì)象的方法被調(diào)用時(shí)被觸發(fā),這篇文章主要介紹了Spring?框架的?MethodInterceptor?簡(jiǎn)介及示例代碼,需要的朋友可以參考下2023-09-09IntelliJ-Idea導(dǎo)出可執(zhí)行Jar流程解析
這篇文章主要介紹了IntelliJ-Idea導(dǎo)出可執(zhí)行Jar流程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12Java實(shí)現(xiàn)Redis延時(shí)消息隊(duì)列
本文主要介紹了Java實(shí)現(xiàn)Redis延時(shí)消息隊(duì)列,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Springboot實(shí)現(xiàn)Excel批量導(dǎo)入數(shù)據(jù)并保存到本地
這篇文章主要為大家詳細(xì)介紹了Springboot實(shí)現(xiàn)Excel批量導(dǎo)入數(shù)據(jù)并將文件保存到本地效果的方法,文中的示例代講解詳細(xì),需要的可以參考一下2022-09-09Springboot+TCP監(jiān)聽(tīng)服務(wù)器搭建過(guò)程圖解
這篇文章主要介紹了Springboot+TCP監(jiān)聽(tīng)服務(wù)器搭建過(guò)程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10