1.在菜单栏添加黑名单的菜单选项left.jsp
<s:if test="#session.hmdgl!=null">
<dd>
<div class="title">
<span><img src="../images/leftico04.png" /></span>黑名单管理
</div>
<ul class="menuson">
<s:if test="#session.hmdlb!=null">
<li id="yhlb">
<cite></cite><a href="Page_forWard?page=blackManage/examineBlackList.html" target="rightFrame">黑名单列表</a><i></i>
</li>
</s:if>
</ul>
</dd>
</s:if>
2.自己编写examineBlackList.html黑名单页面
<!DOCTYPE html>
<html>
<head>
<title>examineBlackList.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
<meta name="keywords" content="keyword1,keyword2,keyword3">
<link href="../css/login.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../css/themes/metro/easyui.css" />
<link rel="stylesheet" type="text/css" href="../css/base.css">
<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../js/jquery.json-2.4.js"></script>
<script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../js/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<table id="examineBlackList" fit="true" pagination="true"></table>
</body>
<script type="text/javascript">
$(function(){
function columnWidth(){
return 200;
}
var columns = [[{
field: "ck",
checkbox: "true"
}, {
field: 'id',
title: '黑名单ID',
width: columnWidth(),
sortable: true,
align: 'center',
}, {
field: 'mac',
title: 'mac地址',
width: columnWidth(),
sortable: true,
align: 'center',
},{
field: 'reason',
title: '加黑原因',
width: columnWidth(),
sortable: true,
align: 'center',
},{
field: 'creattime',
title: '创建时间',
width: columnWidth(),
sortable: true,
align: 'center',
}]];
function columnWidth() {
var width = $(window).width()-39;
return parseInt(width / 4);
}
// 加载全部数据
$('#examineBlackList').datagrid({
url: 'Black_getblackList',
columns: columns,
pageSize: 20,
showFooter:true,
});
// 设置分页控件
var p = $('#examineBlackList').datagrid('getPager');
$(p).pagination({
// 每页显示的记录条数,默认为10
pageList: [20, 50, 100],
// 可以设置每页记录条数的列表
beforePageText: '第',
// 页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
buttons: [{
iconCls: 'icon-cancel',
text : '取消黑名单',
handler: function(){
var selects = $('#examineBlackList').datagrid('getSelections');
if (selects == 0) {
alert("请选择需要取消黑名单的用户!");
return;
}
var ids="";
for (var i = 0; i < selects.length; i++) {
if (i == selects.length - 1) {
ids += selects[i].id;
}
else {
ids += selects[i].id + "-";
}
}
$.ajax({
type : "POST",
url : "Black_delblackList",
data :"ids="+ids,
success : function(msg) {
alert(msg);
if(msg=="删除黑名单成功!"){
$('#examineBlackList').datagrid('reload');
}
}
});
}
}]
});
});
</script>
</html>
3.实现黑名单页面的取消黑名单的功能BlackAction.java,并且把数据库中的信息显示到前台
package com.xerxes.action;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import com.xerxes.pojo.BlackList;
import com.xerxes.pojo.Nodes;
import com.xerxes.pojo.OpenTime;
import com.xerxes.pojo.Users;
import com.xerxes.pojo.UsersRole;
import com.xerxes.util.json.JsonUtil;
public class BlackAction extends BaseAction {
private static final long serialVersionUID = -5890416357610280287L;
private String blackListIds;// 设定为黑名单的节点id
private String reason;// 设定黑名单节点原因
private String macs;//设定mac地址
private String ids;
public String getIds() {
return ids;
}
public void setIds(String ids) {
this.ids = ids;
}
public String getMacs() {
return macs;
}
public void setMacs(String macs) {
this.macs = macs;
}
public void addblackList() {
try {
//根据mac判断是否加入黑名单(如果存在只更新)之间用-隔开
String[] nodesArray = macs.split("-");
for (int i = 0; i < nodesArray.length; i++){
List<Criterion> criterions = new ArrayList<Criterion>();
criterions.add(Restrictions.eq("mac", nodesArray[i]));
BlackList nodeBlack = blackListService.executeQueryUnique(criterions, null);
if(nodeBlack!=null){
nodeBlack.setReason(reason);
Timestamp creattime = new Timestamp(System.currentTimeMillis());
nodeBlack.setCreattime(creattime);
blackListService.update(nodeBlack);
}else{
BlackList blackList = new BlackList(this.reason, nodesArray[i]);
blackListService.saveOrUpdate(blackList);
}
}
/*BlackList blackList = new BlackList(this.reason, this.macs);
nodeBlackListService.saveOrUpdate(blackList);*/
outPrint("加入黑名单成功!");
} catch (Exception e) {
e.printStackTrace();
outPrint("加入黑名单失败!");
}
}
public void getblackList() {
Map<String, Object> jsonMap = new HashMap<String, Object>();
List<BlackList> list = blackListService.getListForPage(null, null, pageNumber,
pageSize, order, sort);
jsonMap.put("total", blackListService.getCount());
jsonMap.put("rows", list);
outPrint(JsonUtil.mapTojson(jsonMap));
jsonMap = null;
}
public void delblackList() {
try {
String[] nodesArray = ids.split("-");
for (int i = 0; i < nodesArray.length; i++){
blackListService.delete(nodesArray[i]);
}
outPrint("删除黑名单成功!");
} catch (Exception e) {
e.printStackTrace();
outPrint("删除黑名单失败!");
}
}
public String getBlackListIds() {
return blackListIds;
}
public void setBlackListIds(String blackListIds) {
this.blackListIds = blackListIds;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}
4.dao层:BlackListDao.java
package com.xerxes.dao;
import com.xerxes.pojo.BlackList;
/**
* @author zxt
*
*
*@version V1.1
* 创建时间:2014-4-15 下午4:39:56
*
*/
public interface BalckListDao extends BaseDao<BlackList> {
}
5.dao.impl:BlackListDaoImpl.java
package com.xerxes.dao.impl;
import org.springframework.stereotype.Repository;
import com.xerxes.dao.BalckListDao;
import com.xerxes.pojo.BlackList;
/**
* @author zxt
*
* @version V1.1 创建时间:2014-4-15 下午4:40:27
*
*/
@Repository(value = "balckListDao")
public class BlackListDaoImpl extends BaseDaoImpl<BlackList> implements BalckListDao {
}
6.service:blackListService.java
package com.xerxes.service;
import com.xerxes.pojo.BlackList;
/**
* @author zxt
*
*@version V1.1
* 创建时间:2014-4-15 下午4:41:01
*
*/
public interface blackListService extends BaseService<BlackList>{
}
7.service.impl:BlackListServiceImpl.java
package com.xerxes.service.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.xerxes.dao.BalckListDao;
import com.xerxes.pojo.BlackList;
import com.xerxes.service.blackListService;
/**
* @author zxt
*
* @version V1.1 创建时间:2014-4-15 下午4:41:22
*
*/
@Service(value = "blackListService")
public class BlackListServiceImpl extends BaseServiceImpl<BlackList> implements
blackListService {
@Resource
public void setBaseDao(BalckListDao balckListDao) {
super.setBaseDao(balckListDao);
}
}
8.pojo:BlackList.java
package com.xerxes.pojo;
import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* Nodes entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "blacklist", catalog = "wifidogauth")
public class BlackList implements java.io.Serializable {
private static final long serialVersionUID = -6449015708111921951L;
private int id;
private String reason;
private String mac;
private Timestamp creattime;
public BlackList() {
}
public BlackList(String reason, String mac, Timestamp creattime) {
this.reason = reason;
this.mac = mac;
this.creattime = creattime;
}
public BlackList(String reason, String mac) {
this.reason = reason;
this.mac = mac;
Timestamp creattime = new Timestamp(System.currentTimeMillis());
this.creattime=creattime;
}
9.在数据库中添加blacklist表:id mac reason creattime
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "reason", nullable = false, length = 200)
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@Column(name = "mac", nullable = false, length = 50)
public String getMac() {
return mac;
}
public void setMac(String mac) {
this.mac = mac;
}
@Column(name = "creattime", length = 19)
public Timestamp getCreattime() {
return creattime;
}
public void setCreattime(Timestamp creattime) {
this.creattime = creattime;
}
}
补充:
注意修改BaseAction.java
@Resource
protected blackListService blackListService;