您好,登錄后才能下訂單哦!
這篇“前端傳參數進行Mybatis調用mysql存儲過程執行返回值實例分析”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“前端傳參數進行Mybatis調用mysql存儲過程執行返回值實例分析”文章吧。
查詢數據庫中的存儲過程:
方法一:
select `name` from mysql.proc where db = 'your_db_name' and `type`; = 'PROCEDURE'
方法二:
show procedure status;
你要先在數據庫中建一個表,然后創建存儲過程
我建的表a_tmp,存儲過程名稱bill_a_forbusiness
執行語句: CALL bill_a_forbusiness(44,44,52,47,44,46,52,52,349171)
存儲過程調用方式:
CALL Pro_Get_CO2('2018','','',''); CALL Pro_Get_EnergyData('2017'); CALL Pro_Get_Carbon_OrgType('2014'); CALL 存儲過程名(參數);
查看存儲過程或函數的創建代碼:
show create procedure proc_name; show create function func_name;
因為這個沒有返回值所以需要先傳參調用執行,再查詢
前端代碼:
<template> <div class="app-container"> <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" > <el-form-item label="參數輸入" prop="a"> <el-input v-model="queryParams.a" placeholder="請輸入第一參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="b"> <el-input v-model="queryParams.b" placeholder="請輸入第二參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="c"> <el-input v-model="queryParams.c" placeholder="請輸入第三參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="d"> <el-input v-model="queryParams.d" placeholder="請輸入第四參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="e"> <el-input v-model="queryParams.e" placeholder="請輸入第五參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="f"> <el-input v-model="queryParams.f" placeholder="請輸入第六參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="g"> <el-input v-model="queryParams.g" placeholder="請輸入第七參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="h"> <el-input v-model="queryParams.h" placeholder="請輸入第八參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="參數輸入" prop="abc"> <el-input v-model="queryParams.abc" placeholder="請輸入第九參數" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <!-- <el-form-item label="錄入人" prop="userName"> <el-input v-model="queryParams.userName" placeholder="請輸入辦理人名字" clearable size="small" @keyup.enter.native="handleQuery" /> </el-form-item> <el-form-item label="操作日期" prop="recordDate"> <el-date-picker clearable size="small" v-model="queryParams.recordDate" type="date" value-format="yyyy-MM-dd" placeholder="選擇操作日期"> </el-date-picker> </el-form-item> --> <el-form-item> <el-button type="primary" icon="el-icon-top-right" size="mini" @click="handleQuery" >傳值/執行</el-button > <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button > <el-button type="primary" icon="el-icon-search" size="mini" @click="returnQuery" >返回/查詢</el-button > </el-form-item> </el-form> <el-row :gutter="10" class="mb8"> <right-toolbar :showSearch.sync="showSearch" @queryTable="getProcList" ></right-toolbar> </el-row> <el-table v-loading="loading" :data="returnprocList" @selection-change="handleSelectionChange" > <!-- <el-table-column type="selection" width="55" align="center" /> --> <el-table-column label="序號" align="center" prop="" type="index" width="60" /> <el-table-column label="記錄id" align="center" prop="Id" /> <el-table-column label="第一參數趟次" align="center" prop="a" width="200" /> <el-table-column label="第二參數趟次" align="center" prop="b" /> <el-table-column label="第三參數趟次" align="center" prop="c" /> <el-table-column label="第四參數趟次" align="center" prop="d" /> <el-table-column label="第五參數趟次" align="center" prop="e" /> <el-table-column label="第六參數趟次" align="center" prop="f" /> <el-table-column label="第七參數趟次" align="center" prop="g" /> <el-table-column label="第八參數趟次" align="center" prop="h" /> <el-table-column label="趟次總金額" align="center" prop="abc" /> <!-- 刷新查詢 --> <pagination v-show="total > 0" :total="total" :page.sync="queryparameters.pageNum" :limit.sync="queryparameters.pageSize" @pagination="getProcList" /> </template>
端js代碼:
<script> import { listProc, getProc, delProc, addProc, updateProc, exportProc, returnProc, } from "@/api/stock/proc"; export default { name: "Proc", dicts: ["record_type"], data() { return { // 遮罩層 loading: true, // 顯示搜索條件 showSearch: true, // 總條數 total: 0, // 存儲過程表格數據 procList: [], returnprocList: [], // 查詢參數 queryParams: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null, abc: null, //C: null, }, queryparameters:{ pageNum: 1, pageSize: 10, recordType: 1, }, }; }, created() { this.getList(); this.getProcList(); }, methods: { /** 查詢執行數據 */ getList() { this.loading = true; listProc(this.queryParams).then((response) => { this.procList = response.rows; this.total = response.total; this.loading = false; }); }, /** 查詢返回列表 */ getProcList() { this.loading = true; returnProc(this.queryparameters).then((response) => { this.returnprocList = response.rows; this.total = response.total; this.loading = false; }); }, // 表單重置 reset() { this.form = { Id: null, recordType: null, a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null, abc: null, t: null, tc: null, min1: null, }; }, /** 搜索按鈕操作 */ handleQuery() { this.queryParams.pageNum = 1; this.getList(); }, /** 返回刷新按鈕操作 */ returnQuery() { this.queryparameters.pageNum = 1; this.getProcList(); }, /** 重置按鈕操作 */ resetQuery() { this.resetForm("queryForm"); this.handleQuery(); }, }; </script>
接口代碼:
import request from '@/utils/request' // 查詢列表 export function listProc(query) { return request({ url: '/stock/proc/list', method: 'get', params: query }) } // 查詢 export function returnProc(query) { return request({ url: '/stock/proc/query', method: 'get', parameters: query }) }
Java代碼:
controller:
@RestController @RequestMapping("/stock/proc") public class StockProcController extends BaseController { @Autowired private IStockProcService stockProcService; /** * 查詢列表 */ //@PreAuthorize("@ss.hasPermi('stock:proc:list')") @GetMapping("/list") public TableDataInfo list(StockProc stockProc) { startPage(); List<StockProc> paramlist = stockProcService.selectStockProcParamList(stockProc); //return getDataTable(paramlist); return null; } /** * 獲取外出申請詳細信息 */ @PreAuthorize("@ss.hasPermi('stock:Proc:query')") @GetMapping("/query") public TableDataInfo getInfo(StockProc stockProc) { startPage(); List<StockProc> list = stockProcService.selectStockProcList(stockProc); return getDataTable(list); } }
實體層:
dao/dto
package com.ruoyi.stock.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; /** * 存儲過程頁面 * */ public class StockProc extends BaseEntity { private static final long serialVersionUID = 1L; @Excel(name = "序號") // @NotBlank(message = "該字段不能為空") private int id; /** 第一編號 */ @Excel(name = "第一參數趟次") private int a; /** 第一編號 */ @Excel(name = "第二參數趟次") private int b ; /** 第一編號 */ @Excel(name = "第三參數趟次") private int c; /** 第一編號 */ @Excel(name = "第四參數趟次") private int d; /** 第一編號 */ @Excel(name = "第五參數趟次") private int e; /** 第一編號 */ @Excel(name = "第六參數趟次") private int f; /** 第一編號 */ @Excel(name = "第七參數趟次") private int g; /** 第一編號 */ @Excel(name = "第八參數趟次") private int h; /** 第一編號 */ @Excel(name = "趟次總金額") private int abc; /** 第一編號 */ @Excel(name = "趟") private int t; /** 第一編號 */ @Excel(name = "趟次") private int tc; /** 第一編號 */ @Excel(name = "小計") private int min1; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getA() { return a; } public void setA(int a) { this.a = a; } public int getB() { return b; } public void setB(int b) { this.b = b; } public int getC() { return c; } public void setC(int c) { this.c = c; } public int getD() { return d; } public void setD(int d) { this.d = d; } public int getE() { return e; } public void setE(int e) { this.e = e; } public int getF() { return f; } public void setF(int f) { this.f = f; } public int getG() { return g; } public void setG(int g) { this.g = g; } public int getH() { return h; } public void setH(int h) { this.h = h; } public int getAbc() { return abc; } public void setAbc(int abc) { this.abc = abc; } public int getT() { return t; } public void setT(int t) { this.t = t; } public int getTc() { return tc; } public void setTc(int tc) { this.tc = tc; } public int getMin1() { return min1; } public void setMin1(int min1) { this.min1 = min1; } @Override public String toString() { return "StockProc{" + "id=" + id + ", a=" + a + ", b=" + b + ", c=" + c + ", d=" + d + ", e=" + e + ", f=" + f + ", g=" + g + ", h=" + h + ", abc=" + abc + ", t=" + t + ", tc=" + tc + ", min1=" + min1 + '}'; } }
server層:
public interface IStockProcService { /** * 查詢列表 * @return 記錄集合 */ public List<StockProc> selectStockProcList(StockProc stockProc); public List<StockProc> selectStockProcParamList(StockProc stockProc); }
Impl代碼:
@Service public class StockProcImpl implements IStockProcService { @Autowired private StockProcMapper stockProcMapper; /** * * @param 列表記錄 * @return */ @Override public List<StockProc> selectStockProcList(StockProc stockProc) { //return stockProcMapper.selectStockProcList(stockProc); return stockProcMapper.selectStockProcList(stockProc); } @Override public List<StockProc> selectStockProcParamList(StockProc stockProc) { return stockProcMapper.selectStockProcParamList(stockProc); //return null; } }
mapper代碼:
public interface StockProcMapper { /** * 查詢列表 * * @param stockProc 記錄 * @return 集合 */ public List<StockProc> selectStockProcList(StockProc stockProc); public List<StockProc> selectStockProcParamList(StockProc stockProc); }
mybatis的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"> <mapper namespace="com.ruoyi.stock.mapper.StockProcMapper"> <resultMap type="StockProc" id="StockProcResult"> <result property="Id" column="id"/> <result property="a" column="a"/> <result property="b" column="b"/> <result property="c" column="c"/> <result property="d" column="d"/> <result property="e" column="e"/> <result property="f" column="f"/> <result property="g" column="g"/> <result property="h" column="h"/> <result property="abc" column="abc"/> <result property="t" column="t"/> <result property="tc" column="tc"/> <result property="min1" column=" min1"/> </resultMap> <sql id="selectStockProcVo"> SELECT a,b,c,d,e,f,g,h,abc,t,tc,min1 FROM a_tmp </sql> <!--使用數據庫存儲過程查詢--> <select id="selectStockProcParamList" parameterType="StockProc" resultMap="StockProcResult" statementType="CALLABLE"> call bill_a_forbusiness(#{a},#{b},#{c},#aegqsqibtmh,#{e},#{f},#{g},#{h},#{abc}) </select> <!--無參數查詢--> <select id="selectStockProcList" parameterType="StockProc" resultMap="StockProcResult"> <include refid="selectStockProcVo"/> </select> </mapper>
以上就是關于“前端傳參數進行Mybatis調用mysql存儲過程執行返回值實例分析”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。