StirngMVC部分学习笔记

激活日期控件

var checkin = $("#createDate");
	checkin.datetimepicker({}).on('changeDate',function(ev){
		checkin.datetimepicker('hide');
		$('#createDate').focus();
	});


下拉列表

$.each(category_basedata, function(key, value) {
	$.each(value,function(index,e){
				//value.forEach(function(e) {
					$("<option>").text(e).val(e).appendTo(
							$('#applyCategory'));
		})
})

table切换

$('#baseInformation').click(function (e) {
	 e.preventDefault()
	 $(this).tab('show')
})
$('#capitalStructure').click(function (e) {
	e.preventDefault()
	$(this).tab('show')
})
$('#mainManager').click(function (e) {
	e.preventDefault()
	$(this).tab('show')
})

Datatable添加行

var c = $('#capitalStructureTable').DataTable({
	"bServerSide":false,
	 "bPaginate":false,
	 "bSort":false,
	 "bInfo":false
	 });
$('#addCapitalStructureRow').on( 'click', function () {
	    c.row.add( [
		'<input style="width:100px;height:30px" name="investor_"/>',
		'<select class="form-control chuzirenleibie" name="investorType_">' +
		'<option  value="自然人"  selected="selected">自然人</option>' +
		'<option  value="法人">法人</option>' +
		'</select>',
		'<select class="form-control chuzifangshi" name="investmentMode_">' +
		'<option  value="货币" selected="selected">货币</option>' +
		'<option  value="股份" >股份</option>' +
		'</select>',
		'<input style="width:100px;height:30px" name="contribution_"/>',
		'<input style="width:100px;height:30px" name="percentage_"/>',
		'<input style="width:100px;height:30px" name="nationality_"/>',
		'<input style="width:100px;height:30px" name="unitProperty_"/>',
		'<input style="width:100px;height:30px" name="headC_"/>',
		'<button style="width:50px" class="btn btn-danger icon-trash" id="deleteBtn">'
	  ] ).draw( false );
	 
} );

序列化table里的一行

	    function GetDataJson(ntr,name,$table){
	    	 
	    	 var data = [];
	    	 $.each(ntr,function(index,obj){
		    	 var json = {};
		    	  
		    	  $.each($(obj).find('input,select'),function(_index,_obj){
			    	   var tmpObj = $(_obj);
			    	   var name = tmpObj.attr('name').substring(0,tmpObj.attr('name').indexOf('_'))
			    	   var value = tmpObj.val();
			    	   json[name] = value; // json赋值
		    	  })
		    	  data.push(json);
	    	 });
	    	 
	    	 $table.find(name).remove();
	    	 var $input = $('<input type="hidden" id="' + name + '" name="' + name + '" />');
	    	 $input.val(JSON.stringify(data));
	    	 $table.append($input);
	    	 
	    	 return data;
	    }
submitHandler : function(form) {
				//alert($('#roleId').val());
				/*
				 * 拼接资本结构表格到隐藏input
				 */
				var capitalNtr = $('#executiveStructureTable tbody tr');
				var capitalData = GetDataJson(capitalNtr,'executive',$("#createForm"));
				
				var capitalNtr = $('#capitalStructureTable tbody tr');
				var capitalData = GetDataJson(capitalNtr,'capital',$("#createForm"));
				
				$.ajax({
					url : "apply/add",
					cache : false,
					type : "post",
					data : $('#createForm').serialize(),
					dataType : "json",
					success : function(data) {

						bootbox.alert(data.msg);

						if (data.flag) {
							$.refreshContent({
								'url' : 'apply/list'
							});

						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						alert(XMLHttpRequest.status + " : " + errorThrown);
					}
				});
				return false;
			}


值回显

var m = $('#executiveTable').DataTable({
  	"bServerSide":false,
  	"bPaginate":false,
  	"bSort":false,
  	"bInfo":false
  	});
var c = $('#capitalTable').DataTable({
  	"bServerSide":false,
  	"bPaginate":false,
  	"bSort":false,
  	"bInfo":false
  	});

var showPreValue = function(data) {
	$.each(data, function(num, array)  {    //每个数据库的表遍历 即传过来得几个model类对象的遍历  num为第几个字段 array为每个字段对象
		$.each(array, function(key, value)	{				//每个字段对象遍历 key为字段名 value为字段值
			if(key.toUpperCase() == 'CAPITAL'){	//如果字段名为captial
				 var jsonObj = jQuery.parseJSON(value);
			     $.each(jsonObj,function(index,obj){	//每个json对象序列化的对象遍历 
			    	 var i = 1;
			      if (!$.isEmptyObject(obj)){			//如果对象不为空就添加一行到datatable中
			  	        c.row.add( [
			  			  '<input style="width:100px;height:30px" name="investor_" value="'+obj.investor+'"/>',
			  			  '<select id="IType'+i+'" class="form-control chuzirenleibie" name="investorType_">' +
			  			  '<option  value="自然人" >自然人</option>' +
			  			  '<option  value="法人">法人</option>' +
			  			  '</select>',
			  			  '<select id="IMode'+i+'" class="form-control chuzifangshi" name="investmentMode_">' +
			  			  '<option  value="货币" >货币</option>' +
			  			  '<option  value="股份" >股份</option>' +
			  			  '</select>',
			  			  '<input style="width:100px;height:30px" name="contribution_" value="'+obj.contribution+'"/>',
			  			  '<input style="width:100px;height:30px" name="percentage_" value="'+obj.percentage+'"/>',
			  			  '<input style="width:100px;height:30px" name="nationality_" value="'+obj.nationality+'"/>',
			  			  '<input style="width:100px;height:30px" name="unitProperty_" value="'+obj.unitProperty+'"/>',
			  			  '<input style="width:100px;height:30px" name="headC_" value="'+obj.headC+'"/>',
			  			  '<button type="button" style="width:50px" id="deleteBtn" class="btn btn-danger icon-trash"></button>'
			  	        ] ).draw( false );
			  	        $('#IType'+i).val(obj.investorType);
			  	        $('#IMode'+i).val(obj.investmentMode);
			  	        i++;
			      }
			     })
			     }
			else if(key.toUpperCase() == 'EXECUTIVE'){	//如果字段名为EXECUTIVE
				 var jsonObj = jQuery.parseJSON(value);
			     $.each(jsonObj,function(index,obj){	//每个json对象序列化的对象遍历 
			      if (!$.isEmptyObject(obj)){			//如果对象不为空就添加一行到datatable中
			    	 
			  	        m.row.add( [
			  			  '<input style="width:100px;height:30px" name="name_" value="'+obj.name+'"/>',
			  			  '<input style="width:100px;height:30px" name="post_" value="'+obj.post+'"/>',
			  			  '<input style="width:100px;height:30px" name="title_" value="'+obj.title+'"/>',
			  			  '<input style="width:100px;height:30px" name="nationalityB_" value="'+obj.nationalityB+'"/>',
			  			  '<input style="width:100px;height:30px" name="idNumber_" value="'+obj.idNumber+'"/>',
			  			  '<a href="#" style="width:50px" class="btn btn-danger" ><i class="icon-trash" style="width:50px"></i></a>'
			  	        ] ).draw( false );
			  	 
			      }
			     })
			}
			$(".updFormElement").each(function(index, obj){	//每个class为updFormElement的表单元素遍历 index是第几个表单元素 
					if ($(obj).attr("name").toUpperCase() == key.toUpperCase()) {	//如果html表单元素class为...且name属性大写和字段名大写相等
							$(obj).val(value);			//表单元素value值变为同名字段的value值
					}
			});
		
	});
		
	});
};

删除dataTable的一行

 $('#capitalTable tbody').on('click','#deleteBtn',function(){
    	c.row($(this).parents('tr'))
    	.remove()
    	.draw()
 	});

枚举类型键值对应用

public enum AutoCode {
	初次审查("C"),延续审查("Y"),变动审查("B"),
	
	涉密文件资料印制资质("1"),国家统一考试试卷印制资质("2"),涉密防伪票据证书印制资质("3"),涉密光电磁介质印制资质("4"),涉密档案数字化加工资质("5"),
	
	北京市("11"),天津市("12"),河北省("13"),山西省("14"),内蒙古自治区("15"),辽宁省("16"),吉林省("17"),黑龙江省("18"),上海市("19"),
	江苏省("20"),浙江省("21"),安徽省("22"),福建省("23"),江西省("24"),山东省("25"),河南省("26"),湖北省("27"),湖南省("28"),广东省("29"),
	广西壮族自治区("30"),海南省("31"),重庆市("32"),四川省("33"),贵州省("34"),云南省("35"),西藏自治区("36"),陕西省("37"),甘肃省("38"),
	青海省("39"),宁夏回族自治区("40"),新疆维吾尔族自治区("41"),新疆生产建设兵团("42");
	
	private String strValue;
	public String getStrValue() {
		return strValue;
	}
	public void setStrValue(String strValue) {
		this.strValue = strValue;
	}
	private AutoCode(String strValue){
		this.strValue=strValue;
	}
}
String autoApplyCode = "P";
AutoCode val = AutoCode.valueOf(apply.getApplyType());//String类型对象匹配枚举类型对象并获得其value值
autoApplyCode += val.getStrValue()+"";
val = AutoCode.valueOf(apply.getApplyCategory());
autoApplyCode += val.getStrValue()+"";

导入excel到网页

controller部分代码
@RequestMapping(value="/getFile", method = RequestMethod.POST)
	public @ResponseBody AjaxResult getFile(@RequestParam(value="exFile") MultipartFile exFile){
			
				AjaxResult result = null;
				String fname = exFile.getOriginalFilename();
				 try {
					SaveFileFromInputStream(exFile.getInputStream(),"D:/",fname);
				} catch (IOException e) {
					result = new AjaxResult(0, e);
					e.printStackTrace();
				}
				Object[] data = new Object[2];
                try {
					data = new ReadExcel().readExcel("D:/"+fname);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                if (null != data) {

					result = new AjaxResult(1, data);
				}
                else{
                	result = new AjaxResult(1, "失败");
                }
			return result;
	}

org.zzsc.apply.file包下代码
Common类负责提供判断时用到的字符串
package org.zzsc.apply.file;

public class Common {
	public static final String OFFICE_EXCEL_2003_POSTFIX = "xls";
    public static final String OFFICE_EXCEL_2010_POSTFIX = "xlsx";

    public static final String EMPTY = "";
    public static final String POINT = ".";
    public static final String LIB_PATH = "lib";
    public static final String STUDENT_INFO_XLS_PATH = LIB_PATH + "/student_info" + POINT + OFFICE_EXCEL_2003_POSTFIX;
    public static final String STUDENT_INFO_XLSX_PATH = LIB_PATH + "/student_info" + POINT + OFFICE_EXCEL_2010_POSTFIX;
    public static final String NOT_EXCEL_FILE = " : Not the Excel file!";
}


Util类负责获取后缀名
package org.zzsc.apply.file;

public class Util {

    public static String getPostfix(String path) {
        if (path == null || Common.EMPTY.equals(path.trim())) {
            return Common.EMPTY;
        }
        if (path.contains(Common.POINT)) {
            return path.substring(path.lastIndexOf(Common.POINT) + 1, path.length());
        }
        return Common.EMPTY;
    }
}


Excel类接收各sheet返回的json字符串
package org.zzsc.apply.model;

public class Excel {
	private String baseInformation;
	private String capital;
	private String executive;
	public String getBaseInformation() {
		return baseInformation;
	}
	public void setBaseInformation(String baseInformation) {
		this.baseInformation = baseInformation;
	}
	public String getCapital() {
		return capital;
	}
	public void setCapital(String capital) {
		this.capital = capital;
	}
	public String getExecutive() {
		return executive;
	}
	public void setExecutive(String executive) {
		this.executive = executive;
	}
	
}




ReadExcel类实际对获得的xls文件或xlsx文件操作
package org.zzsc.apply.file;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.zzsc.apply.model.Excel;
import org.zzsc.apply.model.TApply;
import org.zzsc.apply.model.TApplyEnterprice;


public class ReadExcel {
	public Excel readExcel(String path) throws IOException {
        if (path == null || Common.EMPTY.equals(path)) {
            return null;
        } else {
            String postfix = Util.getPostfix(path);
            if (!Common.EMPTY.equals(postfix)) {
                if (Common.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
                    return readXls(path);
                } else if (Common.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
                    return readXlsx(path);
                }
            } else {
                System.out.println(path + Common.NOT_EXCEL_FILE);
            }
        }
        return null;
    }

    /**
     * Read the Excel 2010
     * @param path the path of the excel file
     * @return
     * @throws IOException
     */
    @SuppressWarnings("null")
    public Excel readXlsx(String path) throws IOException {
    	InputStream is = new FileInputStream(path);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		XSSFWorkbook wb = new XSSFWorkbook(is);
		Excel excel = new Excel();
		// 得到Excel所有工作表对象
		int sheetsCount = wb.getNumberOfSheets();
		for (int sheetNum = 0; sheetNum < sheetsCount; sheetNum++) {
			// 获得第sheetNum个sheet
			XSSFSheet sheet = wb.getSheetAt(sheetNum);
			if (sheetNum == 0) {
				ArrayList<String> key = new ArrayList<String>();
				ArrayList<String> value = new ArrayList<String>();
				Map<String, String> map = new HashMap<String, String>();
				// 总行数
				int trLength = sheet.getLastRowNum();
				for (int tr = 0; tr <= trLength; tr++) {
					// 得到Excel工作表的第tr行
					XSSFRow row = sheet.getRow(tr);
					// 得到第tr行不为空的列个数
					int notEmpty = sheet.getRow(0).getPhysicalNumberOfCells();
					for (int i = 0; i < notEmpty; i++) {
						if (tr == 0) {// 读取表头
							key.add(getValue(row.getCell(i)));
						} else if (tr == 1) {
							if (row.getCell(i) == null || "".equals(row.getCell(i))) {
								value.add(null);// 当单元格没有数据时如果不把null传进去会出错从而不往下走
							} else if ("applyDate".equals(key.get(i)) || "regTime".equals(key.get(i))) {
								row.getCell(i).setCellType(Cell.CELL_TYPE_NUMERIC);
								value.add(format.format(row.getCell(i).getDateCellValue()));
							} else {
								row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
								value.add(row.getCell(i).getStringCellValue());
							}
						}
					}
				}
				int keyLength = key.size();
				for (int i = 0; i < keyLength; i++) {
					map.put(key.get(i), value.get(i));
				}
				Date date = new Date();
				map.put("applyDate", format.format(date));
				JSONArray jsonObj = JSONArray.fromObject(map);
				excel.setBaseInformation(jsonObj.toString());
			}
			if (sheetNum == 1) {
				List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
				int trLength = sheet.getLastRowNum();
				for (int tr = 1; tr <= trLength; tr++) {
					XSSFRow xssfRow = sheet.getRow(tr);
					if (xssfRow != null) {
						String[] xs = { "investor", "investorType",
								"investmentMode", "contribution", "percentage",
								"nationality", "unitProperty", "headC" };
						Map<String, String> map = new HashMap<String, String>();
						int len = xs.length;
						for (int i = 0; i < len; i++) {
							xssfRow.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
							System.out.println(xs[i] + xssfRow.getCell(i).getStringCellValue());
							map.put(xs[i], xssfRow.getCell(i).getStringCellValue());
						}
						ret.add(map);
					}
				}
				JSONArray jsonObj = JSONArray.fromObject(ret);
				excel.setCapital(jsonObj.toString());
			}
			if (sheetNum == 2) {
				List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
				int trLength = sheet.getLastRowNum();
				for (int rowNum = 1; rowNum <= trLength; rowNum++) {
					XSSFRow xssfRow = sheet.getRow(rowNum);
					if (xssfRow != null) {
						String[] xs = { "name", "post", "title","nationalityB", "idNumber" };
						Map<String, String> map = new HashMap<String, String>();
						int len = xs.length;
						for (int j = 0; j < len; j++) {
							if ("idNumber".equals(xs[j])) {
								xssfRow.getCell(j).setCellType(Cell.CELL_TYPE_NUMERIC);
								DecimalFormat df = new DecimalFormat("0");
								String idCard = df.format(xssfRow.getCell(j).getNumericCellValue());
								map.put(xs[j], idCard);
							} else {
								xssfRow.getCell(j).setCellType(Cell.CELL_TYPE_STRING);
								map.put(xs[j], xssfRow.getCell(j).getStringCellValue());
							}
						}
						ret.add(map);
					}
				}
				JSONArray jsonObj = JSONArray.fromObject(ret);// 通过fromObject方法将map对象转换为JSONObject对象
				excel.setExecutive(jsonObj.toString());
			}
		}
		return excel;

	}

    /**
     * Read the Excel 2003-2007
     * @param path the path of the Excel
     * @return
     * @throws IOException
     */
    public Excel readXls(String path) throws IOException {
    	InputStream is = new FileInputStream(path);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        HSSFWorkbook wb = new HSSFWorkbook(is);
        Excel excel = new Excel();
		//得到Excel所有工作表对象
		int sheetsCount = wb.getNumberOfSheets();
		for(int sheetNum=0;sheetNum<sheetsCount;sheetNum++){
			//获得第sheetNum个sheet
			HSSFSheet sheet = wb.getSheetAt(sheetNum);
			if(sheetNum==0){
			   ArrayList<String> key = new ArrayList<String>();
			   ArrayList<String> value = new ArrayList<String>();
			   Map<String, String> map = new HashMap<String, String>();
			   //总行数
			   int trLength = sheet.getLastRowNum();
			   for(int tr=0;tr<=trLength;tr++){
					//得到Excel工作表的第tr行
					HSSFRow row = sheet.getRow(tr);
					//得到第tr行不为空的列个数
					int notEmpty = sheet.getRow(0).getPhysicalNumberOfCells();
					for(int i=0;i<notEmpty;i++){
						if(tr==0){//读取表头
							key.add(getValue(row.getCell(i)));
						}
						else if(tr==1){
							if(row.getCell(i)==null || "".equals(row.getCell(i))){
								value.add(null);//当单元格没有数据时如果不把null传进去会出错从而不往下走
							}
							else if("applyDate".equals(key.get(i)) || "regTime".equals(key.get(i))){
								row.getCell(i).setCellType(Cell.CELL_TYPE_NUMERIC);;
								value.add(format.format(row.getCell(i).getDateCellValue()));
							}
							else{
								row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);;
								value.add(row.getCell(i).getStringCellValue());
							}
						}
					}
				}
			   	int keyLength = key.size();
			   	for(int i=0;i<keyLength;i++){
                	map.put(key.get(i), value.get(i));
                }
			    Date date = new Date();
				map.put("applyDate",format.format(date));
                JSONArray jsonObj = JSONArray.fromObject(map);
            	excel.setBaseInformation(jsonObj.toString());
            	System.out.println(" excel: "+excel);
			}
			if(sheetNum==1){
				List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
				 int trLength = sheet.getLastRowNum();
				   for(int tr=0;tr<=trLength;tr++){
	                  HSSFRow hssfRow = sheet.getRow(tr);
	                  if (hssfRow != null) {
		                  String[] xs={"investor","investorType","investmentMode","contribution",
		                   		 "percentage","nationality","unitProperty","headC"};
		                  Map<String, String> map=new HashMap<String, String>();
		                  int len = xs.length;
		                  for(int i=0;i<len;i++){
		                      hssfRow.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
		                      map.put(xs[i],hssfRow.getCell(i).getStringCellValue());
		                  }
		                  ret.add(map);
	                  }
	             }
	             JSONArray jsonObj = JSONArray.fromObject(ret);
	             System.out.println(" jsonObj :"+jsonObj);
	           	 excel.setCapital(jsonObj.toString());
	             System.out.println(" excel :"+excel);
			}
			if(sheetNum == 2){
            	List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
           	 	for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                    HSSFRow hssfRow = sheet.getRow(rowNum);
                    if (hssfRow != null) {
	                   	 String[] xs={"name","post","title","nationalityB","idNumber"};
	                   	 Map<String, String> map=new HashMap<String, String>();
	                   	 int len = xs.length;
	                     for(int j=0;j<len;j++){
	                    	if("idNumber".equals(xs[j])){
	                        	hssfRow.getCell(j).setCellType(Cell.CELL_TYPE_NUMERIC);
	                        	DecimalFormat df = new DecimalFormat("0");  
	                        	String idCard = df.format(hssfRow.getCell(j).getNumericCellValue());
	                        	map.put(xs[j],idCard);
	                        }
	                    	else{
		                        hssfRow.getCell(j).setCellType(Cell.CELL_TYPE_STRING);
		                       	map.put(xs[j],hssfRow.getCell(j).getStringCellValue());
	                    	}
	                     }
	                     ret.add(map);
                    }
                 }
	             JSONArray jsonObj = JSONArray.fromObject(ret);//通过fromObject方法将map对象转换为JSONObject对象
	             System.out.println(" jsonObj :"+jsonObj);
	           	 excel.setExecutive(jsonObj.toString());
	             System.out.println(" excel :"+excel);
			}
		}
		return excel; 
    }

    @SuppressWarnings("static-access")
    private String getValue(XSSFCell xssfRow) {
        if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
            return String.valueOf(xssfRow.getBooleanCellValue());
        } 
        else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_STRING) {
            return String.valueOf(xssfRow.getStringCellValue());
        } 
        else {
        	//纯数字的号码单元格用getNumericValue()读取后后面多了一个".0"为了去掉改为也用String类型读取方式读取
        	xssfRow.setCellType(Cell.CELL_TYPE_STRING);
        	return xssfRow.getStringCellValue()+"";
        }
    }

    @SuppressWarnings("static-access")
    private String getValue(HSSFCell hssfCell) {
        if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(hssfCell.getBooleanCellValue());
        }
        else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_STRING) {
            return String.valueOf(hssfCell.getStringCellValue());
        } 
        else {
        	//纯数字的号码单元格用getNumericValue()读取后后面多了一个".0"为了去掉改为也用String类型读取方式读取
        	hssfCell.setCellType(Cell.CELL_TYPE_STRING);
            return hssfCell.getStringCellValue()+"";
        }
    }
}




获得input file上传提交的文件保存到服务器的目录中
public void SaveFileFromInputStream(InputStream stream,String path,String filename) throws IOException   
    {         
        FileOutputStream fs=new FileOutputStream( path + "/"+ filename);   
        byte[] buffer =new byte[1024*1024];   
        int bytesum = 0;   
        int byteread = 0;    
        while ((byteread=stream.read(buffer))!=-1)   
        {   
           bytesum+=byteread;   
           fs.write(buffer,0,byteread);   
           fs.flush();   
        }    
        fs.close();   
        stream.close();         
    } 



js部分代码
//浏览按钮点击事件调用隐藏的input file的点击事件
	$('#choose').on('click',function(){
		$('#exFile').click();
		
	})
	
	//隐藏的input file值改变事件同时改变现实路径的input text的value值
	$('#exFile').change(function(e){
		$('#fileAdd').val($('#exFile').val());
	})
	
	//导入按钮点击事件调用所在表单的ajax提交文件方法 成功后调用回显方法 
	$('#insert').on('click',function(){
		var formData = new FormData($( "#fileForm" )[0]); 
		$.ajax({
				type: "POST",
				url: "apply/getFile",
				data : formData,
				async: false,  
		                cache: false,  
		                contentType: false,  // 告诉jQuery不要去设置Content-Type请求头 
		                processData: false,  // 告诉jQuery不要去处理发送的数据
				success: function(data){
				    alert( "导入成功");
				    setTimeout(showPreValue(data.data), delaytime);
				}
		});
	})


数据回显同上面的数据回显
	var m = $('#executiveStructureTable').DataTable({
		"bServerSide":false,
		"bPaginate":false,
		"bSort":false,
		"bInfo":false
    });
	
	var c = $('#capitalStructureTable').DataTable({
		"bServerSide":false,
		"bPaginate":false,
		"bSort":false,
		"bInfo":false
	 });
	 
	var showPreValue = function(data) {
		$.each(data, function(k, v)  {    //data是三个sheet数组对象 k是sheet名 v是json字符串值
			var jsonObj = jQuery.parseJSON(v);
		    $.each(jsonObj,function(index,o){
		    	$.each(o,function(key,value){	//key是列名value是单元格的值	
		    		$(".updFormElement").each(function(index, obj){	//每个class为updFormElement的表单元素遍历 
		    			if ($(obj).attr("name").toUpperCase() == key.toUpperCase()) {	
		    				$(obj).val(value);			
		    				return true;
		    			}
		    		});
					
		    	});
		    	if(k.toUpperCase() == 'CAPITAL'){	//如果字段名为captial
					 var jsonObj = jQuery.parseJSON(v);
				     $.each(jsonObj,function(index,obj){	//每个json对象序列化的对象遍历 
					     var i = 1;
					     if (!$.isEmptyObject(obj)){			//如果对象不为空就添加一行到datatable中
					  	        c.row.add( [
					  			  '<input style="width:100px;height:30px" name="investor_" value="'+obj.investor+'"/>',
					  			  '<select id="IType'+i+'" class="form-control chuzirenleibie" name="investorType_">' +
					  			  '<option  value="自然人" >自然人</option>' +
					  			  '<option  value="法人">法人</option>' +
					  			  '</select>',
					  			  '<select id="IMode'+i+'" class="form-control chuzifangshi" name="investmentMode_">' +
					  			  '<option  value="货币" >货币</option>' +
					  			  '<option  value="股份" >股份</option>' +
					  			  '</select>',
					  			  '<input style="width:100px;height:30px" name="contribution_" value="'+obj.contribution+'"/>',
					  			  '<input style="width:100px;height:30px" name="percentage_" value="'+obj.percentage+'"/>',
					  			  '<input style="width:100px;height:30px" name="nationality_" value="'+obj.nationality+'"/>',
					  			  '<input style="width:100px;height:30px" name="unitProperty_" value="'+obj.unitProperty+'"/>',
					  			  '<input style="width:100px;height:30px" name="headC_" value="'+obj.headC+'"/>',
					  			  '<button type="button" style="width:50px" id="deleteBtn" class="btn btn-danger icon-trash"></button>'
					  	        ] ).draw( false );
					  	        $('#IType'+i).val(obj.investorType);
					  	        $('#IMode'+i).val(obj.investmentMode);
					  	        i++;
					     }
				     })
				}
				else if(k.toUpperCase() == 'EXECUTIVE'){	//如果字段名为EXECUTIVE
					 var jsonObj = jQuery.parseJSON(v);
				     $.each(jsonObj,function(index,obj){	//每个json对象序列化的对象遍历 
				      if (!$.isEmptyObject(obj)){			//如果对象不为空就添加一行到datatable中
				    	 
				  	        m.row.add( [
				  			  '<input style="width:100px;height:30px" name="name_" value="'+obj.name+'"/>',
				  			  '<input style="width:100px;height:30px" name="post_" value="'+obj.post+'"/>',
				  			  '<input style="width:100px;height:30px" name="title_" value="'+obj.title+'"/>',
				  			  '<input style="width:100px;height:30px" name="nationalityB_" value="'+obj.nationalityB+'"/>',
				  			  '<input style="width:100px;height:30px" name="idNumber_" value="'+obj.idNumber+'"/>',
				  			  '<button type="button" style="width:50px" id="deleteBtn1" class="btn btn-danger icon-trash"></button>'
				  	        ] ).draw( false );
				  	 
				      }
				     })
				}
		    });
		});
	};		













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值