角色的删除

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 info = new HashMap();

	public Integer getId() {
		return id;
	}

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

	public Map getInfo() {
		return info;
	}

	public void setInfo(Map info) {
		this.info = info;
	}
	
}

struts.xml



	
		findRole
	

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);
		}
	);
}


你可能感兴趣的:(Java)