1、删除角色对应的权限数据,即中间表数据
Action:
struts.xml
Jsp:
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);
}
);
}