$("#showAddModalBtn").click(function () {$("#addModal").modal("show");
});
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<div id="addModal" class="modal fade" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">聚星系统弹窗</h4></div><div class="modal-body"><form class="form-signin" role="form"><div class="form-group has-success has-feedback"><input type="text" name="roleName"class="form-control" placeholder="请输入角色名称" autofocus></div></form></div><div class="modal-footer"><button id="saveRoleBtn" type="button" class="btn btn-primary">保存</button></div></div></div>
</div>
<%@include file="/WEB-INF/modal-role-add.jsp" %>
$("#saveRoleBtn").click(function () {// 获取文本框新的角色名称var roleName = $.trim(// 匹配 name 属性等于 roleName 的元素$("#addModal [name=roleName]").val());// 发送 ajax 请求执行更新$.ajax({"url": "role/save.json","type": "post","data": {"name": roleName},"dataType": "json","success": function (response) {console.log(response)var result = response.operationResult;if(result == "SUCCESS") {layer.msg("添加成功!");// 将页码定位到最后一页window.pageNum = 99999999;// 重新加载分页数据generatePage();}if(result == "FAILED") {layer.msg("添加失败失败!" + response.operationMessage);}},"error": function (response) {layer.msg(response.status + " " + response.statusText);}});// 关闭模态框$("#addModal").modal("hide");// 清理模态框$("#addModal [name=roleName]").val("");
});
@ResponseBody
@RequestMapping("role/save.json")
public ResultEntity<String> saveRole(Role role){roleService.saveRole(role);return ResultEntity.successWithoutData();
}
void saveRole(Role role);
public void saveRole(Role role) {roleMapper.insert(role);
}
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<div id="editModal" class="modal fade" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title">修改角色</h4></div><div class="modal-body"><form class="form-signin" role="form"><div class="form-group has-success has-feedback"><input type="text" name="roleName"class="form-control" placeholder="请输入角色名称" autofocus></div></form></div><div class="modal-footer"><button id="updateRoleBtn" type="button" class="btn btn-success">更新</button></div></div></div>
</div>
<%@include file="/WEB-INF/modal-role-edit.jsp" %>
$("#rolePageBody").on("click",".pencilBtn",function(){// 打开模态框$("#editModal").modal("show");// 获取当前行的角色名称var roleName = $(this).parent().prev().text();// 获取当前角色的 id,并设置为全局变量leId = this.id;// 数据回填,使用 roleName 的值设置模态框中的文本框$("#editModal [name=roleName]").val(roleName);
});
$("#updateRoleBtn").click(function(){// 从文本框中获取新的角色名称var roleName = $("#editModal [name=roleName]").val();// 发送 Ajax 请求执行更新$.ajax({"url":"role/update.json","type":"post","data":{"id":leId,"name":roleName},"dataType":"json","success":function(response){var result = response.operationResult;if(result == "SUCCESS") {layer.msg("修改成功!");// 重新加载分页数据generatePage();}if(result == "FAILED") {layer.msg("修改失败!" + response.operationMessage);}},"error":function(response){layer.msg(response.status+" " + response.statusText);}});// 关闭模态框$("#editModal").modal("hide");
});
@ResponseBody
@RequestMapping("role/update.json")
public ResultEntity<String> updateRole(Role role){roleService.updateRole(role);return ResultEntity.successWithoutData();
}
void updateRole(Role role);
public void updateRole(Role role) {roleMapper.updateByPrimaryKey(role);
}
本文发布于:2024-02-08 20:15:52,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170739481968800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |