• 前端传参数进行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;

    因为这个没有返回值所以需要先传参调用执行,再查询

    前端代码:

    1. <template>
    2. <div class="app-container">
    3. <el-form
    4. :model="queryParams"
    5. ref="queryForm"
    6. :inline="true"
    7. v-show="showSearch"
    8. label-width="68px"
    9. >
    10. <el-form-item label="参数输入" prop="a">
    11. <el-input
    12. v-model="queryParams.a"
    13. placeholder="请输入第一参数"
    14. clearable
    15. size="small"
    16. @keyup.enter.native="handleQuery"
    17. />
    18. el-form-item>
    19. <el-form-item label="参数输入" prop="b">
    20. <el-input
    21. v-model="queryParams.b"
    22. placeholder="请输入第二参数"
    23. clearable
    24. size="small"
    25. @keyup.enter.native="handleQuery"
    26. />
    27. el-form-item>
    28. <el-form-item label="参数输入" prop="c">
    29. <el-input
    30. v-model="queryParams.c"
    31. placeholder="请输入第三参数"
    32. clearable
    33. size="small"
    34. @keyup.enter.native="handleQuery"
    35. />
    36. el-form-item>
    37. <el-form-item label="参数输入" prop="d">
    38. <el-input
    39. v-model="queryParams.d"
    40. placeholder="请输入第四参数"
    41. clearable
    42. size="small"
    43. @keyup.enter.native="handleQuery"
    44. />
    45. el-form-item>
    46. <el-form-item label="参数输入" prop="e">
    47. <el-input
    48. v-model="queryParams.e"
    49. placeholder="请输入第五参数"
    50. clearable
    51. size="small"
    52. @keyup.enter.native="handleQuery"
    53. />
    54. el-form-item>
    55. <el-form-item label="参数输入" prop="f">
    56. <el-input
    57. v-model="queryParams.f"
    58. placeholder="请输入第六参数"
    59. clearable
    60. size="small"
    61. @keyup.enter.native="handleQuery"
    62. />
    63. el-form-item>
    64. <el-form-item label="参数输入" prop="g">
    65. <el-input
    66. v-model="queryParams.g"
    67. placeholder="请输入第七参数"
    68. clearable
    69. size="small"
    70. @keyup.enter.native="handleQuery"
    71. />
    72. el-form-item>
    73. <el-form-item label="参数输入" prop="h">
    74. <el-input
    75. v-model="queryParams.h"
    76. placeholder="请输入第八参数"
    77. clearable
    78. size="small"
    79. @keyup.enter.native="handleQuery"
    80. />
    81. el-form-item>
    82. <el-form-item label="参数输入" prop="abc">
    83. <el-input
    84. v-model="queryParams.abc"
    85. placeholder="请输入第九参数"
    86. clearable
    87. size="small"
    88. @keyup.enter.native="handleQuery"
    89. />
    90. el-form-item>
    91. <el-form-item>
    92. <el-button
    93. type="primary"
    94. icon="el-icon-top-right"
    95. size="mini"
    96. @click="handleQuery"
    97. >传值/执行
    98. >
    99. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
    100. >重置
    101. >
    102. <el-button
    103. type="primary"
    104. icon="el-icon-search"
    105. size="mini"
    106. @click="returnQuery"
    107. >返回/查询
    108. >
    109. el-form-item>
    110. el-form>
    111. <el-row :gutter="10" class="mb8">
    112. <right-toolbar
    113. :showSearch.sync="showSearch"
    114. @queryTable="getProcList"
    115. >right-toolbar>
    116. el-row>
    117. <el-table
    118. v-loading="loading"
    119. :data="returnprocList"
    120. @selection-change="handleSelectionChange"
    121. >
    122. <el-table-column
    123. label="序号"
    124. align="center"
    125. prop=""
    126. type="index"
    127. width="60"
    128. />
    129. <el-table-column label="记录id" align="center" prop="Id" />
    130. <el-table-column
    131. label="第一参数趟次"
    132. align="center"
    133. prop="a"
    134. width="200"
    135. />
    136. <el-table-column label="第二参数趟次" align="center" prop="b" />
    137. <el-table-column label="第三参数趟次" align="center" prop="c" />
    138. <el-table-column label="第四参数趟次" align="center" prop="d" />
    139. <el-table-column label="第五参数趟次" align="center" prop="e" />
    140. <el-table-column label="第六参数趟次" align="center" prop="f" />
    141. <el-table-column label="第七参数趟次" align="center" prop="g" />
    142. <el-table-column label="第八参数趟次" align="center" prop="h" />
    143. <el-table-column label="趟次总金额" align="center" prop="abc" />
    144. <pagination
    145. v-show="total > 0"
    146. :total="total"
    147. :page.sync="queryparameters.pageNum"
    148. :limit.sync="queryparameters.pageSize"
    149. @pagination="getProcList"
    150. />
    151. template>

     端js代码:

     接口代码:

     

    1. import request from '@/utils/request'
    2. // 查询列表
    3. export function listProc(query) {
    4. return request({
    5. url: '/stock/proc/list',
    6. method: 'get',
    7. params: query
    8. })
    9. }
    10. // 查询
    11. export function returnProc(query) {
    12. return request({
    13. url: '/stock/proc/query',
    14. method: 'get',
    15. parameters: query
    16. })
    17. }

    Java代码:

    controller:

    1. @RestController
    2. @RequestMapping("/stock/proc")
    3. public class StockProcController extends BaseController
    4. {
    5. @Autowired
    6. private IStockProcService stockProcService;
    7. /**
    8. * 查询列表
    9. */
    10. //@PreAuthorize("@ss.hasPermi('stock:proc:list')")
    11. @GetMapping("/list")
    12. public TableDataInfo list(StockProc stockProc)
    13. {
    14. startPage();
    15. List paramlist = stockProcService.selectStockProcParamList(stockProc);
    16. //return getDataTable(paramlist);
    17. return null;
    18. }
    19. /**
    20. * 获取外出申请详细信息
    21. */
    22. @PreAuthorize("@ss.hasPermi('stock:Proc:query')")
    23. @GetMapping("/query")
    24. public TableDataInfo getInfo(StockProc stockProc)
    25. {
    26. startPage();
    27. List list = stockProcService.selectStockProcList(stockProc);
    28. return getDataTable(list);
    29. }
    30. }

    实体层:

    dao/dto

    1. package com.ruoyi.stock.domain;
    2. import com.fasterxml.jackson.annotation.JsonFormat;
    3. import com.ruoyi.common.annotation.Excel;
    4. import com.ruoyi.common.core.domain.BaseEntity;
    5. import org.springframework.format.annotation.DateTimeFormat;
    6. import java.util.Date;
    7. /**
    8. * 存储过程页面
    9. *
    10. */
    11. public class StockProc extends BaseEntity {
    12. private static final long serialVersionUID = 1L;
    13. @Excel(name = "序号")
    14. // @NotBlank(message = "该字段不能为空")
    15. private int id;
    16. /** 第一编号 */
    17. @Excel(name = "第一参数趟次")
    18. private int a;
    19. /** 第一编号 */
    20. @Excel(name = "第二参数趟次")
    21. private int b ;
    22. /** 第一编号 */
    23. @Excel(name = "第三参数趟次")
    24. private int c;
    25. /** 第一编号 */
    26. @Excel(name = "第四参数趟次")
    27. private int d;
    28. /** 第一编号 */
    29. @Excel(name = "第五参数趟次")
    30. private int e;
    31. /** 第一编号 */
    32. @Excel(name = "第六参数趟次")
    33. private int f;
    34. /** 第一编号 */
    35. @Excel(name = "第七参数趟次")
    36. private int g;
    37. /** 第一编号 */
    38. @Excel(name = "第八参数趟次")
    39. private int h;
    40. /** 第一编号 */
    41. @Excel(name = "趟次总金额")
    42. private int abc;
    43. /** 第一编号 */
    44. @Excel(name = "趟")
    45. private int t;
    46. /** 第一编号 */
    47. @Excel(name = "趟次")
    48. private int tc;
    49. /** 第一编号 */
    50. @Excel(name = "小计")
    51. private int min1;
    52. public int getId() {
    53. return id;
    54. }
    55. public void setId(int id) {
    56. this.id = id;
    57. }
    58. public int getA() {
    59. return a;
    60. }
    61. public void setA(int a) {
    62. this.a = a;
    63. }
    64. public int getB() {
    65. return b;
    66. }
    67. public void setB(int b) {
    68. this.b = b;
    69. }
    70. public int getC() {
    71. return c;
    72. }
    73. public void setC(int c) {
    74. this.c = c;
    75. }
    76. public int getD() {
    77. return d;
    78. }
    79. public void setD(int d) {
    80. this.d = d;
    81. }
    82. public int getE() {
    83. return e;
    84. }
    85. public void setE(int e) {
    86. this.e = e;
    87. }
    88. public int getF() {
    89. return f;
    90. }
    91. public void setF(int f) {
    92. this.f = f;
    93. }
    94. public int getG() {
    95. return g;
    96. }
    97. public void setG(int g) {
    98. this.g = g;
    99. }
    100. public int getH() {
    101. return h;
    102. }
    103. public void setH(int h) {
    104. this.h = h;
    105. }
    106. public int getAbc() {
    107. return abc;
    108. }
    109. public void setAbc(int abc) {
    110. this.abc = abc;
    111. }
    112. public int getT() {
    113. return t;
    114. }
    115. public void setT(int t) {
    116. this.t = t;
    117. }
    118. public int getTc() {
    119. return tc;
    120. }
    121. public void setTc(int tc) {
    122. this.tc = tc;
    123. }
    124. public int getMin1() {
    125. return min1;
    126. }
    127. public void setMin1(int min1) {
    128. this.min1 = min1;
    129. }
    130. @Override
    131. public String toString() {
    132. return "StockProc{" +
    133. "id=" + id +
    134. ", a=" + a +
    135. ", b=" + b +
    136. ", c=" + c +
    137. ", d=" + d +
    138. ", e=" + e +
    139. ", f=" + f +
    140. ", g=" + g +
    141. ", h=" + h +
    142. ", abc=" + abc +
    143. ", t=" + t +
    144. ", tc=" + tc +
    145. ", min1=" + min1 +
    146. '}';
    147. }
    148. }

    server层:

    1. public interface IStockProcService
    2. {
    3. /**
    4. * 查询列表
    5. * @return 记录集合
    6. */
    7. public List selectStockProcList(StockProc stockProc);
    8. public List selectStockProcParamList(StockProc stockProc);
    9. }

    Impl代码:

    1. @Service
    2. public class StockProcImpl implements IStockProcService {
    3. @Autowired
    4. private StockProcMapper stockProcMapper;
    5. /**
    6. *
    7. * @param 列表记录
    8. * @return
    9. */
    10. @Override
    11. public List selectStockProcList(StockProc stockProc) {
    12. //return stockProcMapper.selectStockProcList(stockProc);
    13. return stockProcMapper.selectStockProcList(stockProc);
    14. }
    15. @Override
    16. public List selectStockProcParamList(StockProc stockProc) {
    17. return stockProcMapper.selectStockProcParamList(stockProc);
    18. //return null;
    19. }
    20. }

    mapper代码:

    1. public interface StockProcMapper
    2. {
    3. /**
    4. * 查询列表
    5. *
    6. * @param stockProc 记录
    7. * @return 集合
    8. */
    9. public List selectStockProcList(StockProc stockProc);
    10. public List selectStockProcParamList(StockProc stockProc);
    11. }

    mybatis的xml文件:

    1. mapper
    2. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    4. <mapper namespace="com.ruoyi.stock.mapper.StockProcMapper">
    5. <resultMap type="StockProc" id="StockProcResult">
    6. <result property="Id" column="id"/>
    7. <result property="a" column="a"/>
    8. <result property="b" column="b"/>
    9. <result property="c" column="c"/>
    10. <result property="d" column="d"/>
    11. <result property="e" column="e"/>
    12. <result property="f" column="f"/>
    13. <result property="g" column="g"/>
    14. <result property="h" column="h"/>
    15. <result property="abc" column="abc"/>
    16. <result property="t" column="t"/>
    17. <result property="tc" column="tc"/>
    18. <result property="min1" column=" min1"/>
    19. resultMap>
    20. <sql id="selectStockProcVo">
    21. SELECT
    22. a,b,c,d,e,f,g,h,abc,t,tc,min1
    23. FROM
    24. a_tmp
    25. sql>
    26. <select id="selectStockProcParamList" parameterType="StockProc" resultMap="StockProcResult" statementType="CALLABLE">
    27. call bill_a_forbusiness(#{a},#{b},#{c},#{d},#{e},#{f},#{g},#{h},#{abc})
    28. select>
    29. <select id="selectStockProcList" parameterType="StockProc" resultMap="StockProcResult">
    30. <include refid="selectStockProcVo"/>
    31. select>
    32. mapper>

    最后便可以通过页面输入框的参数进行调用存储过程执行,然后点击查询返回结果列表。

  • 相关阅读:
    Java基础-static关键字
    grafana api创建dashboard 记录
    成人自考-英语二-连词
    Git分支与Git标签的介绍及其场景应用
    面试八股 | 计算机网络 | TCP三次握手
    2024年腾讯云优惠政策_腾讯云TOP10优惠活动
    Session会话机制的应用(用户登录)
    KF、EKF、IEKF、UKF卡尔曼滤波器
    配置高级 --------打包与运行---配置高级---多环境开发---日志
    进度条小程序
  • 原文地址:https://blog.csdn.net/qq_45637260/article/details/126288734