1.EXT批量删除:JS前端
new Ext.Button({
id:'btDelete',
text:'删除',
iconCls:'btDelete',
minWidth:60,
handler: function(){
var selectedKeys = grid.selModel.selections.keys;
if(selectedKeys.length > 0)
{
if (confirm("确定删除所选数据吗?"))
{
var records = grid.selModel.selections.items;//得到被选择的行的数组
var recordsLen = records.length;//得到行数组的长度
var arrayObj = new Array(); //创建一个数组
for(var i = 0;i<recordsLen;i++){
var jsonObj={};
jsonObj.rowid=records[i].data.DEVNEROWID;
jsonObj.equit_ip=records[i].data.EQUIT_IP;
jsonObj.bas_ip=records[i].data.BAS_IP;
jsonObj.bas_port=records[i].data.BAS_PORT;
jsonObj.pvlan=records[i].data.PVLAN;
jsonObj.cvlan_start=records[i].data.CVLAN_START;
jsonObj.cvlan_stop=records[i].data.CVLAN_STOP;
jsonObj.devnbe_sta=records[i].data.DEVNBE_STA;
jsonObj.devnbe_sto=records[i].data.DEVNBE_STO;
jsonObj.ne_id="";
arrayObj.push(jsonObj);
// alert(arrayObj[i].ne_id);
//alert(arrayObj[i].devnbe_sto);
}
//alert(arrayObj.toJSONString());
//var arrayObjJson=escape(arrayObj.toJSONString());
var arrayObjJson=(arrayObj.toJSONString());//转换成JSON数组
Ext.Ajax.request({
url: "<%=request.getContextPath() %>/inck/query/inckAdslDevNeAction.do?method=deleteInckAdslDevNeVolume",
params: {ROWID: arrayObjJson},
method: 'POST',
callback: function(opts, success, response){
if (success) {
var aText = response.responseText;
var aTextArray = aText.split("|");
if (aTextArray[0] != "1"){
alert(aTextArray[1]);
return ;
}
pPagingToolbar.doLoad(pPagingToolbar.cursor);
} else {
alert("删除数据失败!");
}
}
});
}else{
//EnableControl(true);
simple.getForm().reset();
iState = 0;
};
} else {
alert('请选择要删除的数据!');
}
}
})
2.java后台处理:
public ActionForward deleteInckAdslDevNeVolume(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException{
String rowidString = request.getParameter("ROWID");
// log.info("rowidArray="+rowidString);
// ServletContext context = servlet.getServletContext();
UserVO currUserVO = (UserVO) request.getSession().getAttribute("CurrentUser");
String loginid = (String)currUserVO.getLoginName();
String operID = (String)currUserVO.getLoginName();
String operName = (String)currUserVO.getUserName();
ArrayList<String> listUser = new ArrayList<String>();
if(null!=loginid){
listUser.add(0, loginid);
}else{
listUser.add(0, "");
}
if(null!=operID){
listUser.add(1, operID);
}else{
listUser.add(1, "");
}
if(null!=operName){
listUser.add(2, operName);
}else{
listUser.add(2, "");
}
// log.info("jarr="+array.size());
List equit_ip_list = new ArrayList();
JSONArray array = JSONArray.fromObject(rowidString);
for(int i=0;i<array.size();i++){
JSONObject jsonObject = array.getJSONObject(i);
equit_ip_list.add(jsonObject.get("equit_ip"));
}
ArrayList userOfficeRight=(ArrayList) userOfficeRight(loginid,(ArrayList) equit_ip_list);
String aError="1|删除成功!";
if(userOfficeRight.size()==0){
try{
dao.deleteInckAdslDevNeBatch(listUser,rowidString);//这里进行批量删除
}catch(Exception ex){
aError="2|删除失败!";
}
}else{
String aErrorString = "3|";
for(int i=0;i<userOfficeRight.size();i++){
// log.info("userOfficeRight.get(i).toString()"+userOfficeRight.get(i).toString());
aErrorString+=(userOfficeRight.get(i).toString()+",");
// log.info("aErrorString======"+aErrorString);
// =","+userOfficeRight.get(i).toString();
}
// log.info("aErrorString======"+aErrorString);
aError=aErrorString+"您没有权限!";
}
response.setContentType("text/html; charset=GB2312");
PrintWriter out = response.getWriter();
response.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
response.setHeader("Cache-Control", "no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");
out.print(aError);
out.flush();
out.close();
return null;
}
3.批量删除以及解析JSON数组:
public void deleteInckAdslDevNeBatch(ArrayList listUser,String rowidArray)throws Exception{
System.out.println("rowidArray="+rowidArray);
JSONArray array = JSONArray.fromObject(rowidArray);
Object[] obj = new Object[array.size()];
List listSql = new ArrayList();
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
for(int i=0;i<array.size();i++){
JSONObject jsonObject = array.getJSONObject(i);
Map map = new HashMap();
try {
String sql ="delete inck_t_adsl_devnbr_ne where ROWID= CHARTOROWID('"+ jsonObject.get("rowid")+"')";
StringBuffer sqlLog = new StringBuffer();
sqlLog.append("insert into INCK_T_ADSL_DEVNBR_NE_LOG (operaId,operaName,") ;
sqlLog.append("loginID,operaTime,operaType,EQUIT_NAME,EQUIT_IP,BAS_NAME,BAS_PORT");
sqlLog.append(",BAS_IP,PVLAN,CVLAN_START,DEVNBE_STA,DEVNBE_STO,CVLAN_STOP");
sqlLog.append(") values('"+listUser.get(1).toString()+"','"+listUser.get(2).toString()+"','"
+listUser.get(0).toString()+"','"+dateString+"','"+"被删除"+"','"+"未知"+"','"+jsonObject.get("equit_ip")+"','"
+"未知"+"','"+jsonObject.get("bas_port")+"','"+jsonObject.get("bas_ip")+"','"+jsonObject.get("pvlan")+"','"
+jsonObject.get("cvlan_start")+"','"+jsonObject.get("devnbe_sta")+"','"+jsonObject.get("devnbe_sto")+"','"
+jsonObject.get("cvlan_stop")+"')");
// jsonObject.get("cvlan_stop")+"','"+jsonObject.get("ne_id")+"')");
listSql.add(sql.toString());
listSql.add(sqlLog.toString());
log.info(listSql.get(i).toString());
// log.info(listSql.get(i+1).toString());
} catch (JSONException e) {
e.printStackTrace();
} //从数组中得到JSONObject对象
}
log.info("listSql.size()="+listSql.size());
int ret = dbInck.updateBatchSql(listSql);
if (ret == -1){
throw new Exception();
}
}
4.需要导入的包;
* jakarta commons-lang 2.4
* jakarta commons-beanutils 1.7.0
* jakarta commons-collections 3.2
* jakarta commons-logging 1.1.1
* ezmorph 1.0.6