ajax文件上传与下载 分布式

界面--

js提交代码

/* 页面初始加载项 */
onload = function pageload() {

};
/* 取消页面 */
function cancel() {
	closelayer();
}
/* 恢复项目默认样式 */
function gsrestorystyle(obj) {
	
	// 初始恢复所有样式表
	gspageobj(obj).className = "input-text";

}

/* 加载完成主页面加载背景 */
jQuery(document).ready(function() {
	enventkeydown();
	gsfocus("documentTitle");
	pagedata();
});

function enventkeydown() {
	/** 绑定 健盘事件区 */
	// 绑定 文件标题 健盘事件
	$("#documentTitle").keydown(function(event){
		if (event.keyCode == 13){
			 $("#documentDate").focus();
			 $("#documentDate").select();
		 }
	});
	$("#documentDate").keydown(function(event){
		 if (event.keyCode == 13){
			 $("#releaseDate").focus();
			 $("#releaseDate").select();
		 	}
		 });
	$("#releaseDate").keydown(function(event){
		 if (event.keyCode == 13){
			 $("#documentTypeName").focus();
			 $("#documentTypeName").select();
		 	}
		 });
	
	$("#documentTypeName").keydown(function(event){
		 if (event.keyCode == 13){
			 $("#documentRemak").focus();
			 $("#documentRemak").select();
		 	}
		 });
	
	$("#documentRemak").keydown(function(event){
		 if (event.keyCode == 13){
			 $("#a_post").focus();
			 $("#a_post").select();
		 	}
		 });
}
	
/** 初始化页面数据 * */
function pagedata() {
	// 获取编辑数据
	geteditdata();
}

/* 删除数据 */
function deletedata() {
	$.confirm({
		title : '询问',
		type : 'red',
		backgroundDismiss : true,
		content : '确定是否删除数据?',
		buttons : {
			确定 : function() {
				$.post("../../../controller/office/document/deleteID.gs", {
					ID : gsgetvalue("hide_ID"),
					documentID : gsgetvalue("hide_documentID")
				}, function(jsondata) {
					if (jsondata.errcode != 0) {
						$.alert({
							title : '错误!',
							backgroundDismiss : false,
							type : 'red',
							content : jsondata.errmsg,
						});
						return false;
					} else {

						$.confirm({
							title : '光融.云!',
							type : 'red',
							backgroundDismiss : false,
							content : '数据删除完成',
							buttons : {
								确定 : function() {
									adviseparent();
									closelayer();
								}
							}
						});

						return true;
					}
				}, "json");

			},
			取消 : function() {

			}
		}
	});
}

/* 关闭本页 */
function closelayer() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}

/* 下载编辑数据项 */
function geteditdata() {
	/* 获取传值ID */
	gssetvalue("hide_ID", gsgetparentvalue("hide_ID"));
	/* 检测是否为更新 */
	if (gsgetvalue("hide_ID") == "") {
		// 如果新增状态,屏蔽删除按钮
		gsobjdisplay("a_delete", 0);
		//设置默认文档发布日期 和文档日期 
		gssetvalue("documentDate",gsNowDate());
		gssetvalue("releaseDate",gsNowDate());
		//关闭下载列 
		closeDownColumn();
		return true;
	}
	$.post("../../../controller/office/document/getedit.gs", {
		ID : gsgetvalue("hide_ID")
	}, function(jsondata) {
		if (jsondata.errcode != 0) {
			$.alert({
				title : '错误!',
				backgroundDismiss : false,
				type : 'red',
				content : jsondata.errmsg,
			});
			return false;
		} else {
			if (jsondata.datacount == 1) {
				// 遍历数组数据
				$.each(jsondata.data, function(i, row) {
					gssetvalue("hide_ID", row.ID);
					/* 字段 文件ID值 */
					gssetvalue("hide_documentID", row.documentID);
					/* 字段 文件标题 值 */
					gssetvalue("documentTitle", row.documentTitle);
					/* 字段 文件日期值 */
					gssetvalue("documentDate", row.documentDate);
					/* 字段 文件类型ID值 */
					gssetvalue("hide_documentTypeID", row.documentTypeID);
					/* 字段 文件类型名称值 */
					gssetvalue("documentTypeName", row.documentTypeName);
					/* 字段 文件用户ID值 */
					gssetvalue("hide_documentUserID", row.documentUserID);
					/* 字段 文件用户名称值 */
					gssetvalue("hide_documentUserCnName",
							row.documentUserCnName);
					/* 字段 部门ID值 */
					gssetvalue("hide_branchID", row.branchID);
					/* 字段 部门名称值 */
					gssetvalue("hide_branchName", row.branchName);
					/* 字段 备注值 */
					gssetvalue("documentRemak", row.documentRemak);

					/* 字段 文件发布日期值 */
					gssetvalue("releaseDate", row.releaseDate);
					
					//下载附件部分
					/** 开始下载明细数据 * */
					$.post("../../../controller/office/document/listDocumentAttach.gs",
					{
						documentID : gsgetvalue("hide_documentID")
					}, function(jsondata) {
						if (jsondata.errcode != 0) {
							$.alert({
								title : '错误!',
								backgroundDismiss : false,
								type : 'red',
								content : jsondata.errmsg,
							});
							return false;
						} else 
						{
							var datacount=jsondata.datacount;
							if ( datacount> 0) 
						{
								// 遍历数组数据
								$.each(jsondata.data, function(i, row) 
							    {
									appendatt(row.attachNewName,row.attachOldName);
									gssethtml("td_name_"+(i+1), row.attachOldName);
									gssethtml("td_type_"+(i+1), gsFileTypeIco(row.attachType));
									gssethtml("td_size_"+(i+1), gsFileSize(row.attachSize));
									gssethtml("td_newName_"+(i+1), row.attachNewName);
									
									//设置隐藏文件输入框 的 sdata属性为1   attachid=原始附件ID
									gssetattribute("file_"+(i+1),"sdata","1");
									gssetattribute("file_"+(i+1),"attachID",row.attachID);
									
								});
								// 设置hide_detailID值
								gssetvalue("hide_attID",datacount);
								// 更新时要删除的IDS
								gssetvalue("hide_deleteAttIDS","");
							} else {
								$.alert({
									title : '错误!',
									backgroundDismiss : false,
									type : 'red',
									content : "附件表关健字下载记录为空",
								});
								return false;
							}
							return true;
						}
					}, "json");

				});
			} else {
				$.alert({
					title : '错误!',
					backgroundDismiss : false,
					type : 'red',
					content : "ID关健字下载记录为空或不唯一",
				});
				return false;
			}
			return true;
		}
	}, "json");
}

/* 通知父页面回执 */
function adviseparent() {
	parent.takechildadvice("document_edit");
	return true;
}

/* 提交数据项 */
function postdata() {
	// 恢复 文件标题 样式表
	gsrestorystyle("documentTitle");
	// 恢复 文件日期 样式表
	gsrestorystyle("documentDate");
	// 恢复 文件类型名称 样式表
	gsrestorystyle("documentTypeName");
	// 恢复 备注 样式表
	gsrestorystyle("documentRemak");
	// 检测 文件标题 不能为空
	if (gspageobj("documentTitle").value.length == 0) {
		gsfocus("documentTitle");

		$.alert({
			title : '警告!',
			backgroundDismiss : true,
			type : 'orange',
			content : '文件标题 不能为空',
		});
		gspageobj("documentTitle").className = "input-text form-error";
		return false;
	}

	// 检测 文件日期 不能为空
	if (gspageobj("documentDate").value.length == 0) {
		gsfocus("documentDate");

		$.alert({
			title : '警告!',
			backgroundDismiss : true,
			type : 'orange',
			content : '文件日期不能为空',
		});
		gspageobj("documentDate").className = "input-text form-error";
		return false;
	}
	// 检测 文件发布日期 不能为空
	if (gspageobj("releaseDate").value.length == 0) {
		gsfocus("releaseDate");

		$.alert({
			title : '警告!',
			backgroundDismiss : true,
			type : 'orange',
			content : '文件发布日期不能为空',
		});
		gspageobj("releaseDate").className = "input-text form-error";
		return false;
	}

	// 检测 文件类型名称 不能为空
	if (gspageobj("documentTypeName").value.length == 0) {
		gsfocus("documentTypeName");

		$.alert({
			title : '警告!',
			backgroundDismiss : true,
			type : 'orange',
			content : '文件类型名称不能为空',
		});
		gspageobj("documentTypeName").className = "input-text form-error";
		return false;
	}
	// 检测 备注 不能为空
	if (gspageobj("documentRemak").value.length == 0) {
		gsfocus("documentRemak");
		$.alert({
			title : '警告!',
			backgroundDismiss : true,
			type : 'orange',
			content : '备注不能为空',
		});
		gspageobj("documentRemak").className = "input-text form-error";
		return false;
	}
	/**** 开始检测附件部分  ****/
	var formData = new FormData();
	//循环获取文件名称
	var file_atts = gspageobjname("file_atts");
	var len=file_atts.length;
	var atts_file=null;
		
	/** 验证附件上传数量  **/
	var h=0; //上传附件数量
	for (var i=0;i<=gspageobj("tab_att").rows.length;i++)
		{
			if (gspageobj("td_name_"+i)!=null && gsgethtml("td_name_"+i)!="")
				{
					h++;
				}
		}
	
	if (h==0)
	{
		$.alert({
			title: '警告!',
			backgroundDismiss: true,
			type:'orange',
			content: '至少应该选择一个附件',
			});
		return true;
	}	
	/** 验证附件上传数量  **/
	
	
	/** 批量循环添加附件  **/
	for ( var i= 0; i<len; i++) 
	{
		atts_file=file_atts[i].files[0];
		//如果内容不为空则允许上传
		if (atts_file!=null && gsgetattribute(file_atts[i].id,"sdata")=="0")
		{
					//如果sdata为零 则重新上传
					formData.append("fileNameS",atts_file.name);
					formData.append("fileSizeS",atts_file.size);
					formData.append("fileS",atts_file);
		}
	}
	/** 批量循环添加附件  **/
	/**** 结束检测附件部分  ****/
	/**** 开始存储附件部分  ****/
	 $.ajax({  
	     url: "../../../controller/upload/files/document.gs",  
	     type: 'POST',  
	     data: formData,
	     async: false,  
	     cache: false,  
	     contentType: false,  
	     processData: false,  
	     success: function (jsondata) 
	     {  
	    	 /** 开始提交数据  **/
	    	 var posturl="";

    		if (gsgetvalue("hide_ID") == "") {
    			// 新增
    			posturl = "../../../controller/office/document/insert.gs";
    		} else {
    			// 修改
    			posturl = "../../../controller/office/document/setedit.gs";
    		}
    		$.post(posturl,{
    			ID : gsgetvalue("hide_ID"), 						// 参数 文件主键 新增则为后台生成
    			documentID : gsgetvalue("hide_documentID"), 		// 参数 文件业务主键 新增则为后台生成
    			documentTitle : gsgetvalue("documentTitle"), 		// 参数 主键
    			documentDate : gsgetvalue("documentDate"), 			// 参数 文件日期
    			documentTypeID : gsgetvalue("hide_documentTypeID"), // 传递 文件类型ID 内容参数
    			documentTypeName : gsgetvalue("documentTypeName"), 	// 参数 文件类型名称
    			documentUserID : gsgetvalue("hide_documentUserID"), // 传递 文件所属用户ID 内容参数
    			documentUserCnName : gsgetvalue("hide_documentUserCnName"), // 传递所属 文件用户名称												// 内容参数
    			branchID : gsgetvalue("hide_branchID"), 			// 传递 文件所属用户所属部门ID 内容参数
    			branchName : gsgetvalue("hide_branchName"), 		// 传递 文件所属用户所属部门名称 内容参数
    			documentRemak : gsgetvalue("documentRemak"),		//日期 文档备注信息
    			releaseDate : gsgetvalue("releaseDate"),			//文档发布日期
    			
    			// 新增时候 使用以下 当前登录用户参数 userID userName userBranchName userBranchID当前登录用户 和部门信息
    			userID : gsgetvalue("session.userID"),
    			usercnName : gsgetvalue("session.usercnName"),
    			userBranchID : gsgetvalue("session.userBranchId"),
    			userBranchName : gsgetvalue("session.userBranchName"),
    			
	    		/** 附件 部分 **/
	    		attachOldFileNameS: jsondata.oldFileNameS,
	    		attachFileSizeS: jsondata.fileSizeS,
	    		attachFileExNameS:jsondata.fileExNameS,
	    		attachNewFileNameS:jsondata.newFileNameS,
	    		
	    		deleteIDS:gsgetvalue("hide_deleteAttIDS")
	    		/** 附件 部分 **/
	    		},
	    		function(jsondata){
	    		 if (jsondata.errcode!=0){
	    		$.alert({
	    		title: '错误!',
	    		backgroundDismiss: true,
	    		type:'red',
	    		content: jsondata.errmsg,
	    		});
	
	    		return false;}
	    		else{
	
	    		$.confirm({
	    		    title: '光融.云!',
	    		    type : 'blue',
	    			backgroundDismiss : false,
	    		    content: '数据提交完成',
	    		    buttons: {
	    		        确定: function () 
	    		        {
	    		        	adviseparent();
	    		        	closelayer();
	    		        } 
	    		    }
	    		});
    		
    		}},"json");
	    	 
	    	 /** 结束提交数据  **/
	     },  
	     error: function (jsondata) 
	     {  
	         alert('gr:ajax与服务器断开连接:');
	     }  
	});
	 
}

/* 选择文件类型 */
function selectdocumentTypeName() {
	// 设置选择类型 0 单选 1 多选
	gssetvalue("hide_selectType", "0");
	layer_showEx('部门选择列表', '../documentType/documentType_list.jsp');
}

/* 接收选择的文件类型 */
function takeMeetingTypelist(tyeID, typeName) {
	// 设置文件类型ID
	gssetvalue("hide_documentTypeID", tyeID);
	// 设置文件类型名称
	gssetvalue("documentTypeName", typeName);
}


function closeDownColumn() {
	gspageobj("tab_att").rows[0].cells[0].style.display  =  "none";
	gspageobj("tab_att").rows[1].cells[0].style.display  =  "none";
}
//选择附件
function selectatt(pFileID) {
var evt = new MouseEvent("click", {
	bubbles : false,
	cancelable : true,
	view : window
});
gspageobj(pFileID).dispatchEvent(evt);
}
function checkatt(obj, pNameID, pTypeID, pSizeID) {
// 文件组实例
var fs = obj.files;
// 大小
var fsize = fs[0].size;
if (fsize > 20148000) {
	$.alert({
		title : '错误!',
		backgroundDismiss : false,
		type : 'red',
		content : '上传文件不能大于20MB'
	});
	return false;
}
gssethtml(pSizeID, gsFileSize(fsize));
// 名称
var fname = fs[0].name;
gssethtml(pNameID, fname);
// 类型
var ftype = (fname.substr(fname.lastIndexOf("."))).toLowerCase();
gssethtml(pTypeID, gsFileTypeIco(ftype));
//更新修改标识
if (gsgetattribute(obj.id,"sdata")=="1")
{
	gssetvalue("hide_deleteAttIDS",gsgetvalue("hide_deleteAttIDS")+gsgetattribute(obj.id,"attachID")+";");
	//更新要上传的新文件标识
	gssetattribute(obj.id,"sdata","0");
}

}
function selectatt(pFileID) {
var evt = new MouseEvent("click", {
	bubbles : false,
	cancelable : true,
	view : window
});
gspageobj(pFileID).dispatchEvent(evt);
}

function appendatt(newFileName,oldFileName) {
	// 新附件ID号
	var newAttID = parseInt(gsgetvalue("hide_attID")) + 1;
	gssetvalue("hide_attID", newAttID);
	// 主体
	var table = gspageobj("tab_att");
	var tr = table.insertRow();
	tr.setAttribute("attID", newAttID);
	// 下载列
	var td_down = document.createElement("td");
	td_down.setAttribute("class", "td-manage");
	if (gsgetvalue("hide_ID")=="")
	{
		td_down.setAttribute("style", "display: none;width: 2pt");	
	}
	// a下载
	var a_down = document.createElement("a");
	a_down.setAttribute("href", "javascript:;");
	a_down.setAttribute("onclick", "downAtt('"+newFileName+"','"+oldFileName+"',"+newAttID+")");
	a_down.setAttribute("class", "btn size-S btn-primary radius");
	a_down.innerHTML = "<i class=\"Hui-iconfont\"></i>下载附件";
	td_down.appendChild(a_down);
	tr.appendChild(td_down);
	// 文件
	var td_file = document.createElement("td");
	td_file.setAttribute("class", "td-manage");
	
	// a连接
	var a_file = document.createElement("a");
	a_file.setAttribute("href", "javascript:;");
	a_file.setAttribute("onclick", "selectatt('file_" + newAttID + "')");
	a_file.setAttribute("class", "btn size-S btn-success radius");
	a_file.innerHTML = "<i class=\"Hui-iconfont\"></i>选择附件";
	td_file.appendChild(a_file);
	// f文件
	var f_file = document.createElement("input");
	f_file.setAttribute("type", "file");
	f_file.setAttribute("id", "file_" + newAttID);
	f_file.setAttribute("sdata", "0");
	f_file.setAttribute("name", "file_atts");
	f_file.setAttribute("style", "display: none;width: 2pt");
	f_file.setAttribute("onchange", "checkatt(this,'td_name_" + newAttID
			+ "','td_type_" + newAttID + "','td_size_" + newAttID + "')");
	td_file.appendChild(f_file);
	// 添加td列
	tr.appendChild(td_file);
	// 名称
	var td_name = document.createElement("td");
	td_name.setAttribute("id", "td_name_" + newAttID);
	tr.appendChild(td_name);
	// 类型
	var td_type = document.createElement("td");
	td_type.setAttribute("class", "text-c");
	td_type.setAttribute("id", "td_type_" + newAttID);
	tr.appendChild(td_type);
	// 大小
	var td_size = document.createElement("td");
	td_size.setAttribute("id", "td_size_" + newAttID);
	tr.appendChild(td_size);
	// 新文件名
	var td_newName = document.createElement("td");
	td_newName.setAttribute("id", "td_newName_" + newAttID);
	td_newName.setAttribute("style", "display: none;width: 2pt");
	tr.appendChild(td_newName);	
	// 增加
	var td_add = document.createElement("td");
	td_add.setAttribute("class", "td-manage");
	var a_add = document.createElement("a");
	a_add.setAttribute("href", "javascript:;");
	a_add.setAttribute("onclick", "appendatt('')");
	a_add.setAttribute("class", "btn size-S btn-primary radius");
	a_add.innerHTML = "<i class=\"Hui-iconfont\"></i>增加附件";
	td_add.appendChild(a_add);
	tr.appendChild(td_add);
	// 删除
	var td_del = document.createElement("td");
	td_del.setAttribute("class", "td-manage");
	var a_del = document.createElement("a");
	a_del.setAttribute("href", "javascript:;");
	a_del.setAttribute("onclick", "deleteatt("+newAttID+")");
	a_del.setAttribute("class", "btn size-S btn-warning radius");
	a_del.innerHTML = "<i class=\"Hui-iconfont\"></i>删除附件";
	td_del.appendChild(a_del);
	tr.appendChild(td_del);
}

function deleteatt(pAttID) 
{
	var table = gspageobj("tab_att");
	var rows = table.rows;
	for ( var i = 0; i <= rows.length; i++) 
	{
		if (rows[i].getAttribute("attID") == pAttID) 
		{
			//更新修改标识
			if (gsgetattribute("file_"+pAttID,"sdata")=="1")
			{
				gssetvalue("hide_deleteAttIDS",gsgetvalue("hide_deleteAttIDS")+gsgetattribute("file_"+pAttID,"attachID")+";");
			}
			table.deleteRow(i);			
			break;
		}
	}

}

function checkatt(obj, pNameID, pTypeID, pSizeID) {
	// 文件组实例
	var fs = obj.files;
	// 大小
	var fsize = fs[0].size;
	if (fsize > 20148000) {
		$.alert({
			title : '错误!',
			backgroundDismiss : false,
			type : 'red',
			content : '上传文件不能大于20MB'
		});
		return false;
	}
	gssethtml(pSizeID, gsFileSize(fsize));
	// 名称
	var fname = fs[0].name;
	gssethtml(pNameID, fname);
	// 类型
	var ftype = (fname.substr(fname.lastIndexOf("."))).toLowerCase();
	gssethtml(pTypeID, gsFileTypeIco(ftype));
	//更新修改标识
	if (gsgetattribute(obj.id,"sdata")=="1")
	{
		gssetvalue("hide_deleteAttIDS",gsgetvalue("hide_deleteAttIDS")+gsgetattribute(obj.id,"attachID")+";");
		//更新要上传的新文件标识
		gssetattribute(obj.id,"sdata","0");
	}

}

function downAtt(newFileName,oldFileName,newID)
{
	if (newFileName==""||gsgetattribute("file_"+newID,"sdata")=="0")
		{
			$.alert({
				title : '错误!',
				backgroundDismiss : false,
				type : 'red',
				content : '只能下载服务端的附件.'
			});
			return true;	
		}
	else
		{
			//提交到服务端下载数据
			gsPostDownFile('../../../controller/download/files/exportDocument.gs',newFileName,oldFileName);
		}
}

  

后台controller代码

package com.gr.spring.controller.office.document;

import java.sql.Date;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gr.share.comm.CommWriteJson;
import com.gr.share.comm.exception.CommExceptionPostBack;
import com.gr.share.office.document.DocumentModel;
import com.gr.share.account.token.UserToken;
import com.gr.share.archives.archives.ArchivesModel;

/**
 * 文件名称: DocumentControl 文件说明: 调度者类 版本号: v1.0.1 编制者: 李洪柱 编制时间: 2017-06-23
 * 14:18:59 引入外部类:否
 */

@Controller
@RequestMapping(value = "/controller/office/document/")
public class DocumentControl {
    /** 表格式说明 **/
    /* 字段:ID 注释:办公室_考勤表 */
    /* 字段:documentID 注释:文件编码 */
    /* 字段:documentTitle 注释:文件标题 */
    /* 字段:documentDate 注释:文件日期 */
    /* 字段:documentTypeID 注释:文件类型ID */
    /* 字段:documentTypeName 注释:文件类型名称 */
    /* 字段:documentUserID 注释:文件用户ID */
    /* 字段:documentUserCnName 注释:文件用户名称 */
    /* 字段:branchID 注释:部门ID */
    /* 字段:branchName 注释:部门名称 */
    /* 字段:documentRemak 注释:备注 */
    /* 字段:logtime 注释:日志时间戳 */
    
    /** 下载数据 **/
    //TODO  参数说明  userID  为预留参数  用于验证当前登录用户可查看权限 
    @ResponseBody
    @RequestMapping(value = "list")
    public String listDocument(HttpSession session, Model model,
            String userToken, Integer paging, String findKey, Integer pageNO,
            Integer pageRowCount,int userID) {

        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));
            if (paging == null || paging == 0) {
                pageNO = 1;
                pageRowCount = 1000000000;
            }
            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.listDocument(findKey, pageNO, pageRowCount,userID);
            cjson.appendCompleteJson();
            if (isData) {    
                /** 获取jsonarray数据值 **/
                cjson.appendAarrayCloumn("data", documentModel.getJsonArray());
                cjson.appendCloumn("datacount",
                        Integer.toString(documentModel.getJsonArrayCount()));
                cjson.appendCloumn("pagecount",
                        Integer.toString(documentModel.getPageCount()));
                cjson.appendCloumn("rowcount",
                        Integer.toString(documentModel.getRowCount()));
            } else {
                // 下载数据为空
                cjson.appendCloumn("datacount", "0");
                cjson.appendCloumn("pagecount","0");
                cjson.appendCloumn("rowcount","0");
            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }
        return cjson.getJson();
    }

    /** 下载ID字段编辑数据 **/
    @ResponseBody
    @RequestMapping(value = "getedit")
    public String getEditDocument(HttpSession session, Model model,
            String userToken, Integer ID) {

        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));

            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.getEditDocument(ID);
            cjson.appendCompleteJson();
            if (isData) {
                /* 获取json数组数据 */
                cjson.appendAarrayCloumn("data", documentModel.getJsonArray());
                cjson.appendCloumn("datacount",
                        Integer.toString(documentModel.getJsonArrayCount()));
            } else {

                cjson.appendCloumn("datacount", "0");
            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }
        return cjson.getJson();
    }

    /** 提交ID字段编辑数据 **/
    @ResponseBody
    @RequestMapping(value ="setedit")
    public String setEditDocument(HttpSession session, Model model,String userToken,
            int ID,int documentID,String documentTitle, int documentTypeID,
            String documentTypeName, Date documentDate,Date releaseDate,
            int documentUserID, String documentUserCnName, String branchID,
            String branchName, String documentRemak,String deleteIDS,
            String attachOldFileNameS, String attachNewFileNameS, String attachFileSizeS,
            String attachFileExNameS) {

        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));

            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.setEditDocument(ID, documentID, documentTitle,
                    documentTypeID, documentTypeName, documentDate, documentUserID,
                    releaseDate, documentUserCnName, branchID, branchName, 
                    documentRemak,deleteIDS, attachOldFileNameS, attachNewFileNameS, 
                    attachFileSizeS, attachFileExNameS);
            if (isData) {
                cjson.appendCompleteJson();

            } else {

            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }

        return cjson.getJson();
    }

    /** 插入数据 **/
    @ResponseBody
    @RequestMapping(value = "insert")
    public String insertDocument(HttpSession session, Model model,String userToken,
             String documentTitle,int documentTypeID, String documentTypeName,
            Date documentDate, int userID,Date releaseDate,String usercnName, 
            String userBranchID, String userBranchName,    String documentRemak,
            
            String attachOldFileNameS, String attachNewFileNameS, String attachFileSizeS,
            String attachFileExNameS) {
        //userXXX  为当前登录用户信息

        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));

            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.insertDocument(documentTitle, documentTypeID,
                    documentTypeName, documentDate, releaseDate, userID,
                    usercnName, userBranchID, userBranchName, documentRemak, attachOldFileNameS,
                    attachNewFileNameS, attachFileSizeS, attachFileExNameS);

            if (isData) {
                cjson.appendCompleteJson();

            } else {

            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }

        return cjson.getJson();
    }

    /** 删除数据(ID列) **/
    @ResponseBody
    @RequestMapping(value = "deleteID")
    public String deleteID(HttpSession session, Model model, String userToken,
            Integer ID,int documentID) {

        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));

            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.deleteID(ID,documentID);
            if (isData) {
                cjson.appendCompleteJson();

            } else {
            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }
        return cjson.getJson();
    }
    /** 批量删除数据(ID列多值) **/
    @ResponseBody
    @RequestMapping(value = "deleteIDS")
    public String deleteIDS(HttpSession session, Model model, String userToken,
            String IDS,String documentIDS) {
        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",
                    UserToken.updateUserToken(session, userToken));

            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.deleteIDS(IDS,documentIDS);
            if (isData) {
                cjson.appendCompleteJson();
            } else {

            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }

        return cjson.getJson();
    }

    
    /** 下载附件 文档关联的附件 **/
    @ResponseBody
    @RequestMapping(value = "listDocumentAttach")
    public String listArchivesAttach(HttpSession session, Model model,
            String userToken,Integer documentID) {
        CommWriteJson cjson = new CommWriteJson();
        cjson.beginJson();
        try {
            /* 更换用户令牌 */
            cjson.appendCloumn("usertoken",UserToken.updateUserToken(session,userToken));
            DocumentModel documentModel = new DocumentModel();
            boolean isData;
            isData = documentModel.listDocumentAttach(documentID);
            cjson.appendCompleteJson();
            if (isData) {
                cjson.appendAarrayCloumn("data", documentModel.getJsonArray());
                cjson.appendCloumn("datacount",
                        Integer.toString(documentModel.getJsonArrayCount()));
            } else {
                // 下载数据为空
                cjson.appendCloumn("datacount", "0");
            }
        } catch (CommExceptionPostBack ex) {
            cjson.appendErrorJson(ex);
        } catch (Exception e) {
            cjson.appendExceptionJson(e);
        }

        finally {
            cjson.endJson();
        }

        return cjson.getJson();
    }
}

 

model层代码

package com.gr.share.office.document;

import java.sql.Date;
import java.util.Hashtable;
import java.util.List;

import com.gr.share.meeting.MeetingData;
import com.gr.share.office.document.DocumentBean;
import com.gr.share.office.document.DocumentData;
import com.gr.share.office.document.DocumentData.FactoryData;
import com.gr.share.comm.exception.CommExceptionPostBack;
import com.gr.share.comm.exception.CommExceptionManager;

/**
 * 文件名称: DocumentModel Bean 文件说明: 模块类 版本号: v1.0.1 编制者: 李洪柱 编制时间: 2017-06-23
 * 14:18:54 引入外部类:否
 */

public class DocumentModel implements DocumentFactory {
	public DocumentModel() {

	}
	/** 工厂数据集合(Hash) **/
	private Hashtable<String, FactoryData> factoryHash;

	/** 获取工厂数据集合(Hash) **/
	public Hashtable<String, FactoryData> getFactoryHash() {
		return factoryHash;
	}

	/** 获取工厂数据集合(Hash)(数量) **/
	public int getFactoryHashCount() {
		return factoryHash.size();
	}
	/** 获取工厂数据(关健字) **/
	public FactoryData getFactoryDataHash(String key) {
		return factoryHash.get(key);
	}

	/* 设置工厂数据集合(Hash) (私有) */
	private void setFactoryHash(Hashtable<String, FactoryData> factoryHash) {
		this.factoryHash = factoryHash;
	}
	/** 工厂数据集合 **/
	private List<FactoryData> factoryList;

	/** 获取工厂数据集合 **/
	public List<FactoryData> getFactoryList() {
		return factoryList;
	}

	/** 获取工厂数据集合(数量) **/
	public int getFactoryListCount() {
		return factoryList.size();
	}

	/** 获取工厂数据 **/
	public FactoryData getFactoryData(int index) {
		return factoryList.get(index);
	}

	/** 获取工厂数据(重载)(无参数默认 0 ) **/
	public FactoryData getFactoryData() {
		return getFactoryData(0);
	}

	/* 设置工厂数据集合 (私有) */
	private void setFactoryList(List<FactoryData> factorylist) {
		this.factoryList = factorylist;
	}

	/** 获取JSON数组格式数据 **/
	private String jsonArray;

	public String getJsonArray() {
		return jsonArray;
	}

	/* 设置json数组数据 (私有) */
	private void setJsonArray(String jsonArray) {
		this.jsonArray = jsonArray;
	}

	/** 获取JSON数据(行数) **/
	private Integer jsonArrayCount;

	public Integer getJsonArrayCount() {
		return jsonArrayCount;
	}

	/* 设置json数据行数(私有) */
	private void setJsonArrayCount(Integer jsonArrayCount) {
		this.jsonArrayCount = jsonArrayCount;
	}

	/** 分页数据的总行数 **/
	private int rowCount;

	private void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getRowCount() {
		return this.rowCount;
	}
	
	
	/** 分页数据的总页数 **/
	private int pageCount;

	private void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageCount() {
		return this.pageCount;
	}
	/** 表格式说明 **/
	/* 字段:ID 注释: */
	/* 字段:documentgID 注释:会议ID */
	/* 字段:documentgTitle 注释:会议标题 */
	/* 字段:documentgTypeID 注释:会议类型编码 */
	/* 字段:documentgTypeName 注释:会议类型名称 */
	/* 字段:documentgAttachID 注释:会议附件ID */
	/* 字段:documentgDate 注释:开会时间 */
	/* 字段:documentgAddress 注释:开会地点 */
	/* 字段:documentgSummary 注释:会议纪要 */
	/* 字段:documentgRemak 注释:会议备注 */
	/* 字段:logtime 注释:日志时间戳 */
	@Override
	public boolean listDocument(String findKey, int pageNO, int pageRowCount, int userID)
			throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData = documentgData.listDocument(findKey, pageNO, pageRowCount,userID);
		if(isData){

			//获取并设置分页数据的总行数
			setRowCount(documentgData.getRowCount());
			//获取并设置分页数据的总页数
			setPageCount(documentgData.getPageCount());
			// 获取json数组数据(默认)
			setJsonArray(documentgData.getJsonArray());
			// 并 获取json数组行数
			setJsonArrayCount(documentgData.getJsonArrayCount());
		}
		return isData;
	}
	
	@Override
	public boolean getEditDocument(int ID) throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData =  documentgData.getEditDocument(ID);
		if(isData){
			// 获取json数组数据
			setJsonArray(documentgData.getJsonArray());
			// 获取json数组行数
			setJsonArrayCount(documentgData.getJsonArrayCount());
		}
		return isData;
	}

	@Override
	public boolean setEditDocument(int ID, int documentID, String documentTitle,
			int documentTypeID, String documentTypeName,
			Date documentDate, int documentUserID,Date releaseDate,
			String documentUserCnName, String branchID, String branchName,
			String documentRemak,String deleteIDS,
			String attachOldNameS, String attachNewNameS, String attachSizeS,
			String attachTypeS) throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData = documentgData.setEditDocument(ID, documentID,
				documentTitle, documentTypeID, documentTypeName,
				documentDate, documentUserID, releaseDate, 
				documentUserCnName, branchID, branchName,
				documentRemak, deleteIDS, attachOldNameS, 
				attachNewNameS, attachSizeS, attachTypeS);
				
				return isData;
	}

	@Override
	public boolean insertDocument(String documentTitle, int documentTypeID,
			String documentTypeName, Date documentDate,Date releaseDate,
			int documentUserID, String documentUserCnName, String branchID,
			String branchName, String documentRemak,
			String attachOldNameS, String attachNewNameS, String attachSizeS,
			String attachTypeS)
			throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData = documentgData.insertDocument(documentTitle, documentTypeID, documentTypeName,
				documentDate, releaseDate, documentUserID, documentUserCnName, branchID,
				branchName, documentRemak, attachOldNameS, attachNewNameS, attachSizeS, attachTypeS);
		return isData;
	}

	@Override
	public boolean deleteID(int ID,int documentId) throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData = documentgData.deleteID(ID,documentId);
	return isData;
	}

	@Override
	public boolean deleteIDS(String IDS,String documentIDS) throws CommExceptionPostBack {
		DocumentData documentgData =new DocumentData();
		boolean isData; 
		isData = documentgData.deleteIDS(IDS,documentIDS);
	return isData;
	}

	/**
	 * 根据指定的ID 下载相关附件
	 * @param documentID
	 * @return
	 * @throws CommExceptionPostBack
	 */
	public boolean listDocumentAttach(int documentID)
			throws CommExceptionPostBack {
		DocumentData documentData =new DocumentData();
		boolean isData; 
		isData = documentData.listDocumentAttach(documentID);
		if (isData) {
			/** 模块部分只负责转储工厂数据列表 **/
			// 获取json数组数据(默认)
			setJsonArray(documentData.getJsonArray());
			// 并 获取json数组行数
			setJsonArrayCount(documentData.getJsonArrayCount());
		} else {
			
		}
		return isData;
	}

	@Override
	public String exportExcel(String findKey) throws CommExceptionPostBack {
		// TODO 导出数据 暂时不做
		return null;
	}

	
}

  data数据访问层代码

package com.gr.share.office.document;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.io.IOException;

import jxl.write.WriteException;

import com.gr.share.archives.archives.ArchivesDataAttachs;
import com.gr.share.comm.exception.CommExceptionManagerEx;
import com.gr.share.comm.exception.CommExceptionPostBack;
import com.gr.share.comm.exception.CommExceptionManager;
import com.gr.share.comm.CommWriteJsonResultSet;

import com.gr.share.comm.data.CommMySql;
import com.gr.share.comm.data.CommResultSet;
import com.gr.share.comm.excel.CommExcel;
import com.gr.share.comm.file.CommFile;

/**
 * 文件名称: DocumentData Bean 文件说明: 数据类 版本号: v1.0.1 编制者: 李洪柱 编制时间: 2017-06-23
 * 20:25:15 引入外部类:否
 */
public class DocumentData implements DocumentFactory {
	public DocumentData() {

	}

	/* 内部数据集 */
	private ResultSet resultSet;

	/** 封装工厂数据 **/
	public class FactoryData extends DocumentBean {

	}

	/** 工厂数据集合(HashTable)(会影响效率) **/
	private Hashtable<String, FactoryData> factoryHash;

	/* 获取工厂数据集合 (HashTable) */
	public Hashtable<String, FactoryData> getFactoryHash(String keyField)
			throws CommExceptionPostBack {

		// 如果resultSet未初始化,触发异常
		if (this.resultSet == null) {
			CommExceptionManager.CreateCommException("0xd1008");
		}

		factoryHash = new Hashtable<String, FactoryData>();
		try {
			resultSet.beforeFirst();
			while (resultSet.next()) {
				// 添加到Hash列表
				addFactoryHash(resultSet.getString(keyField),
						getFactoryData(resultSet));
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1004", e);
		}
		return factoryHash;
	}

	/* 添加工厂数据集合 内容 */
	private void addFactoryHash(String key, FactoryData factorydata) {
		factoryHash.put(key, factorydata);
	}

	/** 工厂数据集合(默认) **/
	private List<FactoryData> factoryList;

	/* 填充工厂数据集合 */
	public List<FactoryData> getFactoryList() throws CommExceptionPostBack {

		// 如果resultSet未初始化 ,触发异常
		if (this.resultSet == null) {
			CommExceptionManager.CreateCommException("0xd1008");
		}

		factoryList = new ArrayList<FactoryData>();
		try {
			resultSet.beforeFirst();
			while (resultSet.next()) {
				// 添加到工厂数据集合
				addFactoryList(getFactoryData(resultSet));
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1004", e);
		}
		return factoryList;
	}

	/* 添加工厂数据集合 内容 */
	private void addFactoryList(FactoryData factorydata) {
		factoryList.add(factorydata);
	}

	/* 封包 工厂数据 */
	private FactoryData getFactoryData(ResultSet rs) throws SQLException {
		// 封装包结构
		FactoryData factoryData = new FactoryData();
		factoryData.setID(rs.getInt("ID"));
		factoryData.setDocumentID(rs.getInt("documentID"));
		factoryData.setDocumentTitle(rs.getString("documentTitle"));
		factoryData.setDocumentTypeID(rs.getInt("documentTypeID"));
		factoryData.setDocumentTypeName(rs.getString("documentTypeName"));
		factoryData.setDocumentUserID(rs.getInt("documentUserID"));
		factoryData.setDocumentUserCnName(rs.getString("documentUserCnName"));
		factoryData.setBranchID(rs.getString("branchID"));
		factoryData.setBranchName(rs.getString("branchName"));
		factoryData.setDocumentDate(rs.getDate("documentDate"));
		factoryData.setDocumentRemak(rs.getString("documentRemak"));
		factoryData.setReleaseDate(rs.getDate("releaseDate"));
		factoryData.setLogtime(rs.getDate("logtime"));
		return factoryData;
	}

	/** 获取JSON数据(行数) **/
	private Integer jsonArrayCount;

	public Integer getJsonArrayCount() {
		return jsonArrayCount;
	}

	/* 私有 设置json数据行数 */
	private void setJsonArrayCount(Integer jsonArrayCount) {
		this.jsonArrayCount = jsonArrayCount;
	}

	/** 获取JSON数组格式数据 **/
	public String getJsonArray() throws CommExceptionPostBack {
		// 如果resultSet未初始化,触发异常
		if (this.resultSet == null) {

			CommExceptionManager.CreateCommException("0xd1008");

		}

		CommWriteJsonResultSet cmjson = new CommWriteJsonResultSet();
		try {
			String result;
			this.resultSet.beforeFirst();
			result = cmjson.ResultSetToJsonArray(this.resultSet);
			// 要先获取数组数据才能统计出行数
			setJsonArrayCount(cmjson.getRowsCount());
			return result;

		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1006", e);
		}
		return null;
	}

	/** 获取数据行数 **/
	public int getDataCount() throws CommExceptionPostBack {
		CommResultSet commResultSet = new CommResultSet();
		return commResultSet.getResultSetRows(this.resultSet);
	}

	/** 插入/更新/删除 影响的行数 **/
	private int execCount;

	private void setExecCount(int execcount) {
		this.execCount = execcount;
	}

	public int getExecCount() {
		return this.execCount;
	}

	/** 插入/更新/删除 影响的行数 **/
	private int[] execCountArray;

	private void setExecCountArray(int[] execcountarray) {
		this.execCountArray = execcountarray;
	}

	public int[] getExecCountArray() {
		return this.execCountArray;
	}

	/** 分页数据的总行数 **/
	private int rowCount;

	private void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getRowCount() {
		return this.rowCount;
	}

	/** 分页数据的总页数 **/
	private int pageCount;

	private void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageCount() {
		return this.pageCount;
	}

	/** 表格式说明 **/
	/* 字段:ID 注释:办公室_考勤表 */
	/* 字段:documentID 注释:文件编码 */
	/* 字段:documentTitle 注释:文件标题 */
	/* 字段:documentDate 注释:文件日期 */
	/* 字段:documentTypeID 注释:文件类型ID */
	/* 字段:documentTypeName 注释:文件类型名称 */
	/* 字段:documentUserID 注释:文件用户ID */
	/* 字段:documentUserCnName 注释:文件用户名称 */
	/* 字段:documentRemak 注释:备注 */
	/* 字段:logtime 注释:日志时间戳 */

	/** 下载数据( 分页数据 )  **/
	//TODO  参数userID 预留 用于权限控制
	@Override
	public boolean listDocument(String findKey, int pageNO, int pageRowCount,int userID)
			throws CommExceptionPostBack {
		boolean isData = false;
		CommMySql commMySql = new CommMySql();
		try {
			/* 清除临时表 */
			String tempTable = "temp_list_document";
			commMySql.dropTempTable(tempTable);
			/* 创建临时表并归类明细数据 */
			String sqlText = "";
			sqlText = sqlText + " CREATE TEMPORARY TABLE " + tempTable + "(";
			sqlText = sqlText + "  SELECT ";
			sqlText = sqlText
					+ " 	t0.ID,t0.documentID,t0.documentTitle,t0.releaseDate,t0.documentDate,t0.documentTypeID,t0.documentTypeName,t0.documentUserID,t0.documentUserCnName,t0.branchID,t0.branchName,t0.documentRemak,t0.logtime";
			sqlText = sqlText + "  FROM  office_document t0";
			sqlText = sqlText + "  LEFT JOIN office_document_types t1";
			sqlText = sqlText + "  ON t0.documentTypeID=t1.typeID";
			sqlText = sqlText + " WHERE 0=0";
			sqlText = sqlText + "  AND ( t0.documentTitle LIKE  ? "; // 文档标题支持模糊查询
			sqlText = sqlText + "  OR t0.documentTypeName LIKE ? "; // 文档类型名称
			sqlText = sqlText + "  OR t0.documentUserCnName LIKE ? "; // 文档创建人名称
			sqlText = sqlText + "  OR t0.documentRemak LIKE ? "; // 文档备注
			sqlText = sqlText + "  OR t0.branchName LIKE ? ) "; // 文档部门名称
			sqlText = sqlText + " );";
			commMySql.clearPrepared();
			commMySql.addParameter("%" + findKey + "%");
			commMySql.addParameter("%" + findKey + "%");
			commMySql.addParameter("%" + findKey + "%");
			commMySql.addParameter("%" + findKey + "%");
			commMySql.addParameter("%" + findKey + "%");
			/* 开始计算页号 */
			int rowCount = commMySql.execPrepared(sqlText);
			if (rowCount > 0) {
				setRowCount(rowCount);
				setPageCount((int) (Math
						.floor(rowCount / (pageRowCount + 0.01)) + 1));
				/* 开始下载分页数据 */
				sqlText = "";
				sqlText += " SELECT * FROM " + tempTable;
				sqlText += " ORDER BY ID";
				sqlText += " LIMIT " + ((pageNO - 1) * pageRowCount) + ","
						+ pageRowCount;
				commMySql.clearPrepared();
				commMySql.openPrepared(sqlText);
				isData = commMySql.getCommResultSet().next();
				if (isData) {
					resultSet = commMySql.getCommResultSet();
					resultSet.beforeFirst();
				} else {
					/* 此处说明 当前页数 没有数据 */
				}
			} else {
				setRowCount(0);
				/* 此处说明 总行数 没有数据 */
				setPageCount(0);
			}
			
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1009", e);
		}
		finally{
			commMySql.freeConnection();
		}
		return isData;
	}

	/** 下载编辑唯一数据值 **/
	@Override
	public boolean getEditDocument(int ID) throws CommExceptionPostBack {
		boolean isData = false;
		CommMySql commMySql = new CommMySql();
		try {
			String sqlText = "";
			sqlText = sqlText + "SELECT * FROM office_document";
			sqlText = sqlText + " WHERE ID=? ";
			commMySql.clearPrepared();
			commMySql.addParameter(ID);
			commMySql.openPrepared(sqlText);
			isData = commMySql.getCommResultSet().next();
			if (isData) {
				resultSet = commMySql.getCommResultSet();

				if (getDataCount() > 1) {
					/* 触发一个关健字行数不唯一的异常 */
					CommExceptionManager.CreateCommException("0xd1001");
				}

			} else {
				/* 触发唯一ID数据不存在异常 */
				CommExceptionManager.CreateCommException("0xd1010");
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}
		return isData;
	}

	/** 插入数据 **/
	@Override
	public boolean insertDocument(String documentTitle, int documentTypeID,
			String documentTypeName, Date documentDate,Date releaseDate,
			int documentUserID, String documentUserCnName, String branchID,
			String branchName, String documentRemak,
			String attachOldNameS, String attachNewNameS, String attachSizeS,
			String attachTypeS)
			throws CommExceptionPostBack {
		CommMySql commMySql = new CommMySql();
		boolean isData = false;
		try {
			commMySql.beginTransaction();
			// TODO 此处较验重复数据 请检查
			/*
			 * commMySql.checkRepeatedEx("office_document", "ID",ID, "","0xb
			 * 重复错误代码); commMySql.checkRepeatedEx("office_document",
			 * "documentID",documentID, "","0xb 重复错误代码);
			 * commMySql.checkRepeatedEx("office_document",
			 * "documentTitle",documentTitle, "","0xb 重复错误代码);
			 */
			/* 计算新的编号 */
			int newID = commMySql.getNewIDEx("office_document", "documentID",
					"");
			String sqlText = "";
			sqlText += "INSERT INTO office_document";
			sqlText += " (documentID,documentTitle,documentDate,documentTypeID,documentTypeName," +
					"documentUserID,documentUserCnName,branchID,branchName,documentRemak,releaseDate) ";
			sqlText += "VALUES(?,?,?,?,?,?,?,?,?,?,?)";
			commMySql.clearPrepared();
			commMySql.addParameter(newID);
			commMySql.addParameter(documentTitle);
			commMySql.addParameter(documentDate);
			commMySql.addParameter(documentTypeID);
			commMySql.addParameter(documentTypeName);
			commMySql.addParameter(documentUserID);
			commMySql.addParameter(documentUserCnName);
			commMySql.addParameter(branchID);
			commMySql.addParameter(branchName);
			commMySql.addParameter(documentRemak);
			commMySql.addParameter(releaseDate);

			setExecCount(commMySql.execPrepared(sqlText));
			isData = (getExecCount() > 0);
			if (isData) {

				DocumentDataAttachs documentDataAttachs =new DocumentDataAttachs();
				isData = documentDataAttachs.insertDocument_attach(commMySql, newID,
						attachOldNameS, attachNewNameS, attachSizeS, attachTypeS);
				if(isData){//附件插入成功 事务提交
					commMySql.commitTransaction();
				}
			} else {
				// 释放一个影响行数为零的异常
				CommExceptionManager.CreateCommException("0xd1005", sqlText);
			}
		} catch (CommExceptionPostBack ex) {
			commMySql.rollbackTransaction();
			throw ex;
		} catch (SQLException e) {
			commMySql.rollbackTransaction();
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}

		return isData;
	}

	/** 提交数据 **/
	@Override
	public boolean setEditDocument(int ID, int documentID, String documentTitle,
			int documentTypeID, String documentTypeName,
			Date documentDate, int documentUserID,Date releaseDate,
			String documentUserCnName, String branchID, String branchName,
			String documentRemak,String deleteIDS,
			String attachOldNameS, String attachNewNameS, String attachSizeS,
			String attachTypeS) throws CommExceptionPostBack {
		CommMySql commMySql = new CommMySql();
		boolean isData = false;
		try {
			commMySql.beginTransaction();
			// TODO 此处较验重复数据 请检查
			/*
			 * commMySql.checkRepeatedEx("office_document",
			 * "documentUserID",documentUserID, "  AND ID<>"+ID+"  ","重复错误代码);
			 */
			String sqlText = "";
			sqlText += "UPDATE office_document SET ";
			sqlText += " documentID=? ";
			sqlText += " ,documentTitle=? ";
			sqlText += " ,documentDate=? ";
			sqlText += " ,documentTypeID=? ";
			sqlText += " ,documentTypeName=? ";
			sqlText += " ,documentUserID=? ";
			sqlText += " ,documentUserCnName=? ";
			sqlText += " ,branchID=? ";
			sqlText += " ,branchName=? ";
			sqlText += " ,documentRemak=? ";
			sqlText += " ,releaseDate=? ";
			
			sqlText += " WHERE 0=0 ";
			sqlText += " AND ID=? ";
			commMySql.clearPrepared();
			commMySql.addParameter(documentID);
			commMySql.addParameter(documentTitle);
			commMySql.addParameter(documentDate);
			commMySql.addParameter(documentTypeID);
			commMySql.addParameter(documentTypeName);
			commMySql.addParameter(documentUserID);
			commMySql.addParameter(documentUserCnName);
			commMySql.addParameter(branchID);
			commMySql.addParameter(branchName);
			commMySql.addParameter(documentRemak);
			commMySql.addParameter(releaseDate);
			commMySql.addParameter(ID);
			setExecCount(commMySql.execPrepared(sqlText));
			isData = (getExecCount() > 0);
			if (isData) {
				DocumentDataAttachs documentDataAttachs =new DocumentDataAttachs();
				isData = documentDataAttachs.setEditDocumentAttach(commMySql, deleteIDS,
						documentID, attachOldNameS, attachNewNameS, attachSizeS, attachTypeS);
				if(isData){
					commMySql.commitTransaction();
				}
				
			} else {
				// 释放一个影响行数为零的异常
				CommExceptionManager.CreateCommException("0xd1005", sqlText);
			}
		} catch (CommExceptionPostBack ex) {
			commMySql.rollbackTransaction();
			throw ex;
		} catch (SQLException e) {
			commMySql.rollbackTransaction();
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}

		return isData;
	}

	/** 删除数据(ID)列 **/
	@Override
	public boolean deleteID(int ID, int documentID)
			throws CommExceptionPostBack {
		CommMySql commMySql = new CommMySql();
		boolean isData = false;
		try {
			commMySql.beginTransaction();
			// TODO 后期考虑增加检测数据是否被使用
			/* if (checkDataUse(documentID)){
			 * CommExceptionManager.CreateCommException("0xb被使用错误代码"); }
			 */
			// 删除部分
			String sqlText = "";
			sqlText += " DELETE FROM office_document ";
			sqlText += " WHERE 0=0 ";
			sqlText += " AND ID=? ";
			commMySql.clearPrepared();
			commMySql.addParameter(ID);
			setExecCount(commMySql.execPrepared(sqlText));
			isData = (getExecCount() > 0);
			if (isData) {
				DocumentDataAttachs documentDataAttachs =new DocumentDataAttachs();
				isData = documentDataAttachs.deleteAttachBydocumentID(commMySql, documentID);
				if(isData){
					commMySql.commitTransaction();
				}
			} else {
				// 释放一个影响行数为零的异常
				CommExceptionManager.CreateCommException("0xd1005", sqlText);
			}
		} catch (CommExceptionPostBack ex) {
			commMySql.rollbackTransaction();
			throw ex;
		} catch (SQLException e) {
			commMySql.rollbackTransaction();
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}

		return isData;
	}

	/** 批量删除数据(ID)列 **/
	@Override
	public boolean deleteIDS(String IDS, String documentIDS)
			throws CommExceptionPostBack {
		CommMySql commMySql = new CommMySql();
		boolean isData = false;
		try {

			commMySql.beginTransaction();

			// 检测数据是否被使用
			if (checkDataUse(IDS)) {
				CommExceptionManager.CreateCommException("0xb被使用错误代码");
			}
			// 删除部分

			// 开始解析多ID参数
			String sqlText = "";
			commMySql.clearPrepared();
			String[] IDSS = IDS.split(";");
			int length = IDSS.length;
			for (int i = 0; i < length; i++) {

				commMySql.addParameter(IDSS[i]);
				commMySql.addParameter("&;");
			}

			sqlText = sqlText + "DELETE FROM office_document ";
			sqlText = sqlText + " WHERE 0=0 ";
			sqlText = sqlText + " AND ID=? ";
			setExecCountArray(commMySql.execPreparedBatch(sqlText));
			isData = true;
			/* 较验是否全部成功 */
			for (int i = 0; i < getExecCountArray().length; i++) {
				if (getExecCountArray()[i] < 1) {
					isData = false;
					break;
				}
			}
			if (isData) {
				DocumentDataAttachs documentDataAttachs =new DocumentDataAttachs();
				isData = documentDataAttachs.deleteAttachBydocumentIDS(commMySql, documentIDS);
				if(isData){
					commMySql.commitTransaction();
				}
			} else {
				// 释放一个影响行数为零的异常
				CommExceptionManager.CreateCommException("0xd1005", sqlText);

			}
			commMySql.freeConnection();
		} catch (CommExceptionPostBack ex) {
			commMySql.rollbackTransaction();
			throw ex;
		} catch (SQLException e) {
			commMySql.rollbackTransaction();
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}

		return isData;
	}

	/** 导出数据到Excel表 **/
	@Override
	public String exportExcel(String findKey) throws CommExceptionPostBack {
		// TODO 此功能暂时不实现
		String fileName = "";
		/*	try {
			// listDocument(findKey,pageNO, pageRowCount);
			*//** 整理数据(准备导出) **//*
			// Excel文件名称
			fileName = CommFile.getRandFileName() + ".xls";
			String excelFullFileName = CommFile.getToExcelDirName() + fileName;
			CommExcel commExcel = new CommExcel();
			commExcel.createExcelBook(excelFullFileName);
			commExcel.createExcelSheet(" 数据类", 0);
			// 标题行
			String title[] = { "办公室_考勤表", "文件编码", "文件标题 ", "文件日期", "文件类型ID",
					"文件类型名称", "文件用户ID", "文件用户名称", "备注", "日志时间戳" };
			commExcel.loadTitleStyle();
			int tr = 1;
			commExcel.writeTitle(title, tr);
			// 写入数据行
			commExcel.loadDataStyle();
			resultSet.beforeFirst();
			int index = 0;
			while (resultSet.next()) {
				// 行号(继续向下)
				tr++;
				// 列号(每行回到起始头)
				int td = 0;
				// 序号
				commExcel.addCell(++td, tr, Integer.toString(++index));
				// 办公室_考勤表
				commExcel.addCell(++td, tr, resultSet.getString("ID"));
				// 文件编码
				commExcel.addCell(++td, tr, resultSet.getString("documentID"));
				// 文件标题
				commExcel.addCell(++td, tr,
						resultSet.getString("documentTitle"));
				// 文件日期
				commExcel
						.addCell(++td, tr, resultSet.getString("documentDate"));
				// 文件类型ID
				commExcel.addCell(++td, tr,
						resultSet.getString("documentTypeID"));
				// 文件类型名称
				commExcel.addCell(++td, tr,
						resultSet.getString("documentTypeName"));
				// 文件用户ID
				commExcel.addCell(++td, tr,
						resultSet.getString("documentUserID"));
				// 文件用户名称
				commExcel.addCell(++td, tr,
						resultSet.getString("documentUserCnName"));
				// 备注
				commExcel.addCell(++td, tr,
						resultSet.getString("documentRemak"));
				// 日志时间戳
				commExcel.addCell(++td, tr, resultSet.getString("logtime"));
			}
			// 存储文件
			commExcel.saveFile();
		} catch (IOException e) {
			CommExceptionManager.CreateCommException(e);
		} catch (WriteException e) {
			CommExceptionManagerEx.CreateCommException(e);
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1004", e);
		}*/
		return null;
	}

	/** 检测数据是否被使用(私有)(整型) **/
	private boolean checkDataUse(int ID) throws CommExceptionPostBack {
		return checkDataUse(Integer.toString(ID));
	}

	/** 检测数据是否被使用(私有) **/
	private boolean checkDataUse(String IDS) throws CommExceptionPostBack {

		// TODO 此处暂时关闭
		return false;

		/*
		 * boolean isData = false; CommMySql commMySql = new CommMySql(); try{
		 * int a_index=0; String[] valueS=IDS.split(";"); int
		 * length=valueS.length; int len=length*2; String [] talbeNameS=new
		 * String[len]; String [] fieldNameS=new String[len]; String []
		 * fieldValueS=new String[len]; for (int i=0;i<length;i++){
		 * talbeNameS[i+a_index]=表名1; fieldNameS[i+a_index]=字段1;
		 * fieldValueS[i+a_index]=valueS[i]; talbeNameS[i+a_index+1]=表名2;
		 * fieldNameS[i+a_index+1]=字段2; fieldValueS[i+a_index+1]=valueS[i];
		 * a_index++; } isData = commMySql.checkDataUse(talbeNameS,
		 * fieldNameS,fieldValueS); if (isData) { }else { } } catch
		 * (SQLException e) {
		 * CommExceptionManager.CreateCommException("0xd1009", e); } return
		 * isData;
		 */
	}

	public boolean listDocumentAttach(int documentID) 
				throws CommExceptionPostBack {
			boolean isData = false;
			CommMySql commMySql = new CommMySql();
			try {
				commMySql.beginTransaction();
				DocumentDataAttachs documentDataAttachs = new DocumentDataAttachs();
				isData = documentDataAttachs.listDocumentAttachByDocumentID(commMySql, documentID);
				if (isData) {
					resultSet = commMySql.getCommResultSet();
					commMySql.commitTransaction();
				}
			} catch (CommExceptionPostBack ex) {
				commMySql.rollbackTransaction();
				throw ex;
			} catch (SQLException e) {
				commMySql.rollbackTransaction();
				CommExceptionManager.CreateCommException("0xd1009", e);
			} finally {
				commMySql.freeConnection();
			}
			return isData;
		}	
}

  附件表处理类代码

package com.gr.share.office.document;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.io.IOException;

import jxl.write.WriteException;

import com.gr.share.comm.exception.CommExceptionManagerEx;
import com.gr.share.comm.exception.CommExceptionPostBack;
import com.gr.share.comm.exception.CommExceptionManager;
import com.gr.share.comm.CommWriteJsonResultSet;

import com.gr.share.comm.data.CommMySql;
import com.gr.share.comm.data.CommResultSet;
import com.gr.share.comm.excel.CommExcel;
import com.gr.share.comm.file.CommFile;

/**
 * 文件名称: Document_attach Data Bean 
 * 文件说明: 数据类 版本号: v1.0.1 
 * 编制者: 沈文博
 * 编制时间:2017-7-3 10:14:52
 * 引入外部类:否
 */

public class DocumentDataAttachs {

	public DocumentDataAttachs() {

	}

	/* 内部数据集 */
	private ResultSet resultSet;

	/**
	 * 关闭内部结果集方法
	 * 
	 * @throws SQLException
	 **/
	public boolean close() throws CommExceptionPostBack {
		try {
			if (resultSet != null && !resultSet.isClosed()) {
				resultSet.close();
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1021", e);
		}
		return true;
	}

	/** 封装工厂数据 **/
	public class FactoryData extends DocumentBean {

	}

	/** 工厂数据集合(HashTable)(会影响效率) **/
	private Hashtable<String, FactoryData> factoryHash;

	/* 获取工厂数据集合 (HashTable) */
	public Hashtable<String, FactoryData> getFactoryHash(String keyField)
			throws CommExceptionPostBack {

		// 如果resultSet未初始化,触发异常
		if (this.resultSet == null) {
			CommExceptionManager.CreateCommException("0xd1008");
		}

		factoryHash = new Hashtable<String, FactoryData>();
		try {
			resultSet.beforeFirst();
			while (resultSet.next()) {
				// 添加到Hash列表
				addFactoryHash(resultSet.getString(keyField),
						getFactoryData(resultSet));
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1004", e);
		}
		return factoryHash;
	}

	/* 添加工厂数据集合 内容 */
	private void addFactoryHash(String key, FactoryData factorydata) {
		factoryHash.put(key, factorydata);
	}

	/** 工厂数据集合(默认) **/
	private List<FactoryData> factoryList;

	/* 填充工厂数据集合 */
	public List<FactoryData> getFactoryList() throws CommExceptionPostBack {

		// 如果resultSet未初始化 ,触发异常
		if (this.resultSet == null) {
			CommExceptionManager.CreateCommException("0xd1008");
		}

		factoryList = new ArrayList<FactoryData>();
		try {
			resultSet.beforeFirst();
			while (resultSet.next()) {
				// 添加到工厂数据集合
				addFactoryList(getFactoryData(resultSet));
			}
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1004", e);
		}
		return factoryList;
	}

	/* 添加工厂数据集合 内容 */
	private void addFactoryList(FactoryData factorydata) {
		factoryList.add(factorydata);
	}

	/* 封包 工厂数据 */
	private FactoryData getFactoryData(ResultSet rs) throws SQLException {
		// 封装包结构
		FactoryData factoryData = new FactoryData();
		return factoryData;
	}

	/** 获取JSON数据(行数) **/
	private int jsonArrayCount;

	public int getJsonArrayCount() {
		return jsonArrayCount;
	}

	/* 私有 设置json数据行数 */
	private void setJsonArrayCount(int jsonArrayCount) {
		this.jsonArrayCount = jsonArrayCount;
	}

	/** 获取JSON数组格式数据 **/
	public String getJsonArray() throws CommExceptionPostBack {
		// 如果resultSet未初始化,触发异常
		if (this.resultSet == null) {
			CommExceptionManager.CreateCommException("0xd1008");
		}
		CommWriteJsonResultSet cmjson = new CommWriteJsonResultSet();
		try {
			String result;
			this.resultSet.beforeFirst();
			result = cmjson.ResultSetToJsonArray(this.resultSet);
			// 要先获取数组数据才能统计出行数
			setJsonArrayCount(cmjson.getRowsCount());
			return result;

		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1006", e);
		}
		return null;
	}

	/** 获取数据行数 **/
	public int getDataCount() throws CommExceptionPostBack {
		CommResultSet commResultSet = new CommResultSet();
		return commResultSet.getResultSetRows(this.resultSet);
	}

	/** 插入/更新/删除 影响的行数 **/
	private int execCount;

	private void setExecCount(int execcount) {
		this.execCount = execcount;
	}

	public int getExecCount() {
		return this.execCount;
	}

	/** 插入/更新/删除 影响的行数 **/
	private int[] execCountArray;

	private void setExecCountArray(int[] execcountarray) {
		this.execCountArray = execcountarray;
	}

	public int[] getExecCountArray() {
		return this.execCountArray;
	}

	/** 分页数据的总行数 **/
	private int rowCount;

	private void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getRowCount() {
		return this.rowCount;
	}

	/** 分页数据的总页数 **/
	private int pageCount;

	private void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageCount() {
		return this.pageCount;
	}

	/** 表格式说明 **/

	/* 字段 :ID 说明: */
	/* 字段 :DocumentID 说明:档案ID */
	/* 字段 :attachID 说明:附件ID */
	/* 字段 :attachOldName 说明:附件原名称 */
	/* 字段 :attachNewName 说明:附件新名称 */
	/* 字段 :attachSize 说明:附件大小 */
	/* 字段 :attachType 说明:附件类型 */
	/* 字段 :logtime 说明:日志时间戳 */

	/** 表格式说明 **/

	/** 下载数据 **/
	public boolean listDocumentAttachByDocumentID(CommMySql commMySql, int documentID)
			throws CommExceptionPostBack {
		boolean isData = false;
		try {
			String sqlText = "";
			sqlText = sqlText + "  SELECT  * FROM office_document_attach";
			sqlText = sqlText + "  WHERE documentID=?";
			commMySql.clearPrepared();
			commMySql.addParameter(documentID);
			commMySql.openPrepared(sqlText);

			isData = commMySql.getCommResultSet().next();
			if (isData) {
				resultSet = commMySql.getCommResultSet();
			} else {
				// 附件表数据项不存在
				CommExceptionManager.CreateCommException("0xd1024");
			}
		} catch (CommExceptionPostBack ex) {
			throw ex;
		} catch (SQLException e) {
			CommExceptionManager.CreateCommException("0xd1009", e);
		} finally {
			commMySql.freeConnection();
		}
		return isData;
	}

	/** 插入数据 **/
	public boolean insertDocument_attach(CommMySql commMySql, int documentID,
			String attachOldNameS, String attachNewNameS, String attachSizeS,
			String attachTypeS) throws CommExceptionPostBack {
		boolean isData = true;
		/* 计算新的编号 */
		int newID = commMySql.getNewIDEx("office_document_attach", "attachID", "");
		String sqlText = "";
		sqlText += "INSERT INTO office_document_attach";
		sqlText += " (documentID,attachID,attachOldName,attachNewName,attachSize,attachType) ";
		sqlText += "VALUES(?,?,?,?,?,?)";
		commMySql.clearPrepared();
		String[] attachOldNameSS = attachOldNameS.split(";");
		String[] attachNewNameSS = attachNewNameS.split(";");
		String[] attachSizeSS = attachSizeS.split(";");
		String[] attachTypeSS = attachTypeS.split(";");
		for (int i = 0; i < attachOldNameSS.length; i++) {
			commMySql.addParameter(documentID);
			commMySql.addParameter(newID);
			commMySql.addParameter(attachOldNameSS[i]);
			commMySql.addParameter(attachNewNameSS[i]);
			commMySql.addParameter(attachSizeSS[i]);
			commMySql.addParameter(attachTypeSS[i]);
			commMySql.addParameter("&;");
			newID++;
		}
		setExecCountArray(commMySql.execPreparedBatch(sqlText));
		/* 较验是否全部成功 */
		for (int i = 0; i < getExecCountArray().length; i++) {
			if (getExecCountArray()[i] < 1) {
				isData = false;
				break;
			}
		}
		if (isData) {
			return isData;
		} else {
			// 释放一个影响行数为零的异常
			CommExceptionManager.CreateCommException("0xd1022", sqlText);
		}
		return isData;
	}

	//根据办公档案ID 删除附件
	public boolean deleteAttachBydocumentID(CommMySql commMySql,int documentID) throws CommExceptionPostBack
	{
		boolean isData = true;
		String sqlText = "";
		sqlText += " DELETE FROM office_document_attach";
		sqlText += " WHERE 0=0";
		sqlText += " AND documentID=?";
		commMySql.clearPrepared();
		commMySql.addParameter(documentID);
		setExecCount(commMySql.execPrepared(sqlText));
		if (getExecCount()>0)
		{
			isData=true;
		}
		else 
		{
			// 释放一个影响行数为零的异常
			isData=false;
			CommExceptionManager.CreateCommException("0xd1022", sqlText);
		}
		return isData;
	}
	
	//根据档案ID 删除附件
	public boolean deleteAttachBydocumentIDS(CommMySql commMySql,String documentIDS) throws CommExceptionPostBack
	{
		boolean isData = true;
		String sqlText = "";
		sqlText += " DELETE FROM office_document_attach";
		sqlText += " WHERE 0=0";
		sqlText += " AND documentID=?";
		commMySql.clearPrepared();
		String[] documentIDSS=documentIDS.split(";");
		for (int i = 0; i < documentIDSS.length; i++) 
		{
			commMySql.addParameter(documentIDSS[i]);
			commMySql.addParameter("&;");
		}
		setExecCountArray(commMySql.execPreparedBatch(sqlText));
		/* 较验是否全部删除成功 */
		for (int i = 0; i < getExecCountArray().length; i++) {
			if (getExecCountArray()[i] < 1) {
				isData = false;
				break;
			}
		}
		return isData;
	}
	
	/** 更新数据 **/
	public boolean setEditDocumentAttach(CommMySql commMySql,
			String deleteIDS, int documentID, String attachOldNameS,
			String attachNewNameS, String attachSizeS,
			String attachTypeS)
			throws CommExceptionPostBack {
		boolean isData = true;
		
		/* 清除原有旧的附件 */
		String[] deleteIDSS=deleteIDS.split(";");
		if (!deleteIDSS[0].equals(""))
		{
			String sqlText = "";
			sqlText += " DELETE FROM office_document_attach";
			sqlText += " WHERE 0=0";
			sqlText += " AND attachID=?";
			commMySql.clearPrepared();
			for (int i = 0; i < deleteIDSS.length; i++) 
			{
				commMySql.addParameter(deleteIDSS[i]);
				commMySql.addParameter("&;");
			}
			setExecCountArray(commMySql.execPreparedBatch(sqlText));
			/* 较验是否全部删除成功 */
			for (int i = 0; i < getExecCountArray().length; i++) {
				if (getExecCountArray()[i] < 1) {
					isData = false;
					break;
				}
			}
		}

		/* 清除原有旧的附件 */
		if (isData) 
		{
			if (!attachOldNameS.equals(""))
			{
				/* 插入新的附件 */
				isData=this.insertDocument_attach(commMySql, documentID,
						attachOldNameS, attachNewNameS, attachSizeS, attachTypeS);
				if (isData) {
					return isData;
				} else {
					// 释放一个影响行数为零的异常
					CommExceptionManager.CreateCommException("0xd1022");
				}	
			}
		} else {
			// 释放一个影响行数为零的异常
			CommExceptionManager.CreateCommException("0xd1022");
		}
		/* 插入新的附件 */
		return isData;
	}

}

  文件接收服务器代码

	/** 办公文档附件上传**/
	@ResponseBody
	@RequestMapping(value = "document")
	public String uploadDocumentFile(HttpSession session, Model model,
			String userToken, String[] fileNameS,String[] fileSizeS, MultipartFile[] fileS) 
	{
		CommWriteJson cjson = new CommWriteJson();
		cjson.beginJson();
		try {
			if (!UserToken.CheckUserToKen(session, userToken)) {
				// 激活用户令牌异常
				cjson.appendErrorJson("0xa96");
			} else {
				
				String jsonOldFileS =""; //原文件名集合
				String jsonFileExNameS =""; //扩展名集合
				String jsonFileSizeS=""; //文件大小集合
				String jsonNewFileS = ""; //新的文件名集合
				
				if (fileNameS != null &&fileNameS.length>0) {
					// 检测名称组不能为空
					int len = fileNameS.length;
					String fileName = "";// 文件名
					String fileExName = ""; // 文件扩展名
					String newFileName = "";// 新生成的文件名
					MultipartFile muFile = null;// 实体文件
					for (int i = 0; i < len; i++) 
					{
						// 原有文件名称
						fileName = fileNameS[i];
						jsonOldFileS+=fileName + ";";
						
						// 取扩展名
						fileExName = fileName.substring(
								fileName.lastIndexOf(".")).toLowerCase();
						jsonFileExNameS+=fileExName + ";";
						
						// 取新文件名称
						newFileName = CommFile.getRandFileName() + fileExName;
						jsonNewFileS+=newFileName + ";";
						
						// 取文件
						muFile = fileS[i];
						// 存储文件
						CommSpringFile.saveFile(muFile,
								CommFile.getDocumentPath() + newFileName);
						
						//直接copy文件大小
						jsonFileSizeS+=fileSizeS[i] + ";";
						
					}
				}
				//原文件名列表
				cjson.appendCloumn("oldFileNameS", jsonOldFileS);
				//文件大小列表
				cjson.appendCloumn("fileSizeS",jsonFileSizeS);				
				//扩展名列表
				cjson.appendCloumn("fileExNameS",jsonFileExNameS);				
				//新文件名列表
				cjson.appendCloumn("newFileNameS", jsonNewFileS);
				cjson.appendCompleteJson();
			}
		} catch (CommExceptionPostBack ex) {
			cjson.appendErrorJson(ex);
		} catch (Exception e) {
			cjson.appendExceptionJson(e);
		} finally {
			cjson.endJson();
		}
		return cjson.getJson();
	}

  文件下载服务端代码

	/** 下载  办公文档 关联的附件   档案文件 **/
	@ResponseBody
	@RequestMapping(value = "exportDocument")
	public ResponseEntity<byte[]> downExportDocument(HttpSession session, Model model,
			String userToken, String fileName,String newFileName)
	{
		if (!UserToken.CheckUserToKen(session,userToken))
		{
			return null;	
		}
		else
		{
			try
			{
				CommSpringFile commSpringFile=new CommSpringFile();
				return commSpringFile.getFileByte(CommFile.getDocumentPath(), fileName, newFileName);
			}
			catch(Exception e)
			{
				return null;
			}
		}
	}

  公共部分代码

1cjson代码

package core.libs;




/**
 *文件名称:CoreWriteJson
 *文件说明:核心JSON字符串写入类
 *版本号:v1.0.1
 *编制者:李洪柱 
 *编制时间:2016-10-11 09:50:58
 *引入外部类:否
*/

public class WriteJson
{
	/** 设立私有化Json封装 */
	private String privateJson;
	
	public void clearJson() 
	{
		privateJson="";
	}
	public String getJson() 
	{
		return privateJson;
	}
	
	public void appendCloumn(String fieldname,String fieldvalue) 
	{
		if (fieldvalue!=null)
		{
			privateJson+="\""+fieldname+"\""+":"+"\""+fieldvalue+"\",";
		}
		else
		{
			privateJson+="\""+fieldname+"\""+":"+"\"\",";
		}
	}
	public void appendAarrayCloumn(String fieldname,String fieldvalue) 
	{
		if (fieldvalue!=null)
		{
			privateJson+="\""+fieldname+"\""+":"+""+fieldvalue+",";
		}
		else
		{
			privateJson+="\""+fieldname+"\""+":"+"[],";
		}
	}
	//开始封装json
	public void beginJson() 
	{	
		privateJson="{";
		appendCloumn("timestamp",CoreDate.getTimeStamp());
	}
	//开始封装添加json行
	public void beginRow() 
	{	
		privateJson+="{";
	}
	//开始组装array组
	public void beginArray(String pArrayName)
	{
		privateJson+="\""+pArrayName+"\""+":[";
	}
	//结束组装array组
	public void endArray(String endCode)
	{
		privateJson+="]"+endCode;
	}
	//完成封装json
	public void endJson() 
	{	
		privateJson=privateJson.substring(0,privateJson.length()-1);
		privateJson+="}";
	}
	//完成json行封装
	public void endRow(String endCode) 
	{	
		privateJson+="}"+endCode;
	}
	
	//页面测试json串
	public String getPageJson(String msg)
	{
		beginJson();
		appendCloumn("errcode","0");
		appendCloumn("errmsg",msg);
		endJson();
		return privateJson;
	}
	
	/** 页面错误json串 */
	public String getErrorJson(String errcode,String e)
	{
		beginJson();
		appendCloumn("errcode",errcode);
		appendCloumn("errmsg",e);
		endJson();
		return privateJson;
	}
	
	/** 写入json正确值 */
	public void appendCompleteJson()
	{
		appendCloumn("errcode","0");
		appendCloumn("errmsg","");
	}
    /** 写入json基本错误值 */
	public void appendErrorJson(String errCode)
	{
		appendCloumn("errcode",errCode);
		appendCloumn("errmsg",CommException.getCode(errCode));
	}
	
	/** 写入json异常错误值 */
	public void appendExceptionJson(Exception e)
	{
		String errCode="0xa100";
		appendCloumn("errcode",errCode);
		appendCloumn("errmsg",CommException.getCode(errCode));
		appendCloumn("errmsgsystem",e.toString());
	}
	
	
	/** 写入json基本错误值(包含系统错误代码) */
	public void appendErrorJson(CommExceptionPostBack e)
	{
		appendCloumn("errcode",e.getCommExceptionCode());
		appendCloumn("errmsg",CommException.getCode(e.getCommExceptionCode()));
		appendCloumn("errmsgsystem",e.getExceptionMsgSystem());
		appendCloumn("errmsgdebug",e.getExceptionMsgDebug());
	}
	
	
}

  文件保存组件代码

  

package com.gr.share.comm.spring;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

import com.gr.share.comm.exception.CommExceptionManager;
import com.gr.share.comm.exception.CommExceptionPostBack;
import com.gr.share.comm.file.CommFile;



/**
 *文件名称:CommSpringFile
 *文件说明:基于Spring形式的文件管理
 *版本号:v1.0.1
 *编制者:李洪柱 
 *编制时间:2017-04-11 09:50:58
 *引入外部类:是
 *
*/
public class CommSpringFile
{
	

	/** 读取文件并以byte[]形式返回  
	 * @throws IOException **/
	public ResponseEntity<byte[]> getFileByte(String Path,String fileName,String newFileName) throws IOException
	{
		/** 开始下载文件  **/
		String fullFileName=Path+fileName;
		File file = new File(fullFileName);
        HttpHeaders headers = new HttpHeaders();  
        //下载显示的文件名,解决中文名称乱码问题  
        String downloadFielName = new String(newFileName.getBytes("UTF-8"),"iso-8859-1");
        //通知浏览器以attachment(下载方式)打开图片
        headers.setContentDispositionFormData("attachment", downloadFielName); 
        //application/octet-stream : 二进制流数据(最常见的文件下载)。
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),    
                headers, HttpStatus.CREATED);
	}
	
	
	/** 将文件存储到指定位置 
	 * @throws CommExceptionPostBack 
	 **/
	public static void saveFile(MultipartFile file,String fullFileName) throws CommExceptionPostBack
	{
			try 
			{
				file.transferTo(new File(fullFileName));
			}
			catch (IllegalStateException e) 
			{
				CommExceptionManager.CreateCommException(e);	
			} catch (IOException e) 
			{
				CommExceptionManager.CreateCommException(e);
			}
	}
	
	/** 删除指定名称文件(仅限文件)
	 * @throws CommExceptionPostBack 
	 **/
	public static boolean deleteFile(String fullFileName) throws CommExceptionPostBack
	{
		 File file = new File(fullFileName);
	        if (file.exists()) 
	        {
	        	  if (file.isFile())
	        	  {
	        		  deleteFile(fullFileName);
	        		  return true;
	        	  }
	        	  else
	        	  {
	        		  return false;
	        	  }
	        }
			return true; 
	}
	
	/** 删除指定名称文件(仅限目录)
	 * @throws CommExceptionPostBack 
	 **/
	public static boolean deleteDirectory(String fullDirectoryName) throws CommExceptionPostBack
	{
		 File file = new File(fullDirectoryName);
	        if (file.exists()) 
	        {
	        	  if (!file.isFile())
	        	  {
	        		  deleteDirectory(fullDirectoryName);
	        		  return true;
	        	  }
	        	  else
	        	  {
	        		  return false;
	        	  }
	        }
			return true; 
	}
	
	/** 删除指定名称文件(文件目录均可)
	 * @throws CommExceptionPostBack 
	 **/
	public static boolean deleteFileEx(String fullFileName) throws CommExceptionPostBack
	{
		 File file = new File(fullFileName);
	        if (file.exists()) 
	        {
	        	  if (file.isFile())
	        	  {
	        		  deleteFile(fullFileName);
	        		  return true;
	        	  }
	        	  else
	        	  {
	        		  deleteDirectory(fullFileName);
	        		  return true;
	        	  }
	        }
			return false; 
	}
	
}

  

 

posted @ 2017-09-29 21:51  迷~途  阅读(747)  评论(0编辑  收藏  举报