角色的删除

1、删除角色对应的权限数据,即中间表数据

2、再删除角色数据


DAO:

public void delete(Integer id) throws DAOException {
	if(id == null){
		return;
	}
	
	String sql = "delete from role_privilege where role_id=?";
	Connection con = DBUtil.getConnection();
	try {
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, id);
		ps.executeUpdate();
		
		String sql2 = "delete from role_info where id=?";
		PreparedStatement ps2 = con.prepareStatement(sql2);
		ps2.setObject(1, id);
		ps2.executeUpdate();
		
	} catch (SQLException e) {
		e.printStackTrace();
		throw new DAOException("删除角色失败", e);
	} finally{
		DBUtil.close();
	}
}

Action:

public class DeleteRoleAction {
	
	public String execute(){
		IRoleDAO dao = DAOFactory.getRoleDAO();
		try {
			dao.delete(id);
			info.put("success", true);
			info.put("message", "删除业务账号成功");
		} catch (DAOException e) {
			e.printStackTrace();
			info.put("success", false);
			info.put("message", "删除业务账号失败");
		}
		return "success";
	}
	
	//input
	private Integer id;
	//output
	private Map<String, Object> info = new HashMap<String, Object>();

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Map<String, Object> getInfo() {
		return info;
	}

	public void setInfo(Map<String, Object> info) {
		this.info = info;
	}
	
}

struts.xml

<!-- 删除角色Action -->
<action name="deleteRole" class="netctoss.action.role.DeleteRoleAction">
	<result name="success" type="redirectAction">
		findRole
	</result>
</action>

Jsp:

function deleteRole(id){           
	var r = window.confirm("确定要删除业务账号吗?");
	if(!r){
		return;
	}    
	      
	$.post(
		"deleteRole",
		{"id": id},
		function(data){
			var info = data;
			$("#operate_msg").text(info.message);
			$("#operate_result_info").show();
			setTimeout(function(){
				toPage($("#page").val());
			},1000);
		}
	);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue 项目中进行角色删除前校验的方法有很多种,以下是其中一种: 1. 在角色删除按钮的点击事件中,先判断当前角色是否存在关联的用户或权限等信息,如果存在,则弹出提示框,询问用户是否继续删除操作。 ``` <template> <div> <button @click="handleDelete">删除角色</button> </div> </template> <script> export default { methods: { handleDelete() { // 判断当前角色是否存在关联信息,如果存在,则弹出提示框 if (this.isRoleRelated()) { if (confirm('当前角色存在关联用户或权限等信息,是否继续删除?')) { this.deleteRole() } } else { this.deleteRole() } }, isRoleRelated() { // 判断当前角色是否存在关联信息,返回 true 或 false }, deleteRole() { // 执行删除角色操作 } } } </script> ``` 2. 在角色中,为每个角色都设置一个删除按钮,点击删除按钮时,先判断该角色是否存在关联的用户或权限等信息,如果存在,则禁用删除按钮。 ``` <template> <div> <table> <thead> <tr> <th>角色名称</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="role in roles" :key="role.id"> <td>{{ role.name }}</td> <td> <button :disabled="isRoleRelated(role)">删除</button> </td> </tr> </tbody> </table> </div> </template> <script> export default { data() { return { roles: [] } }, methods: { isRoleRelated(role) { // 判断该角色是否存在关联信息,返回 true 或 false } } } </script> ``` 以上是两种角色删除前校验的方法,在实际开发中,具体的实现方式可能会根据项目需求和业务逻辑的不同而有所差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值