在菜单栏添加黑名单页面,实现取消黑名单功能

1.在菜单栏添加黑名单的菜单选项left.jsp




黑名单管理




2.自己编写examineBlackList.html黑名单页面



 
    examineBlackList.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 criterions = new ArrayList();
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 jsonMap = new HashMap();
List 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 {


}

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 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{


}

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

你可能感兴趣的:(WifiDog项目)