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>
其他链接: