Java 调用存储过程 返回结果集

1,效果图

在这里插入图片描述

2,需求:

做一个通知页,通知页数据显示存储过程的结果集

3,存储过程:

一组为了完成特定功能的SQL 语句集,它存储在数据库中,一次编译后永久有效,
用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。

我的存储过程:

--参数+执行语句
	alter PROCEDURE [dbo].[homepagenotification]
	  @uid AS nvarchar(512) ,
	  @uname AS nvarchar(512)
	AS
	BEGIN
	select 'hello world' notification
	END

4,前端弹窗代码:

   function homepagenotifi() {
        layer.open({
            type: 2,
            title: '通知',
            area: ['800px', '500px'],
            content: '/**/homepagenotifipage'
        });
    }
5,后端代码:

    @RequestMapping(value = "homepagenotifipage")
    public String homepagenotifipage(@RequestParam HashMap<String, String> paraMap,Model model, HttpServletRequest request) {
        SessionUserInfoEntity sessionUserInfoEntity = RightUtil.getCurrentUser(request);
        String uid=sessionUserInfoEntity.getUid();
        String uname=sessionUserInfoEntity.getUname();
        
        String querypatients = "{call homepagenotification(?,?)}";
        log.info("start homepagenotification "+querypatients);
        String notification=jdbcTemplate.execute(new CallableStatementCreator(){
            @Override
            public CallableStatement createCallableStatement(Connection connection) throws SQLException {
                CallableStatement callableStatement = connection.prepareCall(querypatients); //sql语句
                callableStatement.setString(1,uid); //参数注入
                callableStatement.setString(2,uname);
                return callableStatement;
            }
        }, new CallableStatementCallback<String>() {
            @Override
            public String doInCallableStatement(CallableStatement callableStatement) throws SQLException, DataAccessException {
                callableStatement.execute(); //执行sql
                String result="";
                do {
                    ResultSet sqlRowSet = callableStatement.getResultSet(); //获取数据结果集
                    if (sqlRowSet != null) {
                        while(sqlRowSet.next()){
                            result=sqlRowSet.getString(1); //获取最后一条结果集
                        }
                    }
                } while(callableStatement.getMoreResults() || callableStatement.getUpdateCount() != -1);
                return result;
            }
        });
        
        model.addAttribute("notification",notification); //传送结果给前端
        return "basedata/Homepage_notification_List";
    }

6,前端代码:

注意:**样式 position: fixed;bottom:0; 可以固定按钮位置


	<div class=" addwrap">
        <div class="layui-form">
            <div style="padding: 50px; line-height: 22px;  font-weight: 300;">${notification}</div>
            <div class="layui-form-item" style="margin-top: 20px;margin-left:250px;position: fixed;bottom:0;">
                <div class="flex flex-jusity-center flex-align-center height26" >
                    <div class=" flex  layui-input-block flex flex-jusity-around  tjbtn" >
                        <button class="layui-btn layui-btn-radius layui-btn-sm layui-btn-primary qx">取消</button>
                        <button class="layui-btn layui-btn-radius layui-btn-sm layui-btn-primary qx" style="background: #2d8586;">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    

其他链接:

Java 调用存储过程 返回结果集

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值