• 遍历数据批量导入部分代码


    直奔主题:

    前台页面代码:

            //定义变量存id值
    	var ids = " ";
    	//遍历数据获取id数组元素
    	for(var i = 0; i < rowId.length; i++){
    		if(i == 0){
    			ids = rowId[i]; 
    		}else{
    			ids = ids+ ","+rowId[i]; 
    		}
    	}         
    

    webController层:

    @RequiresPermissions("customer:customer:edit")
    	@RequestMapping(value = "write")
    	@ResponseBody
    	public String write(String ids) {
    		//切割字符串
    		String[] list = ids.split(",");
    		//创建空对象
    		Customer customer = null;
    		//遍历对象
    		for(int i=0; i<list.length; i++) {
    			customer = new Customer();
    			//set整型id
    			customer.setIid(Integer.valueOf(list[i]));
    			//调用接口把id传给对象
    			customer = customerService.get(customer);
    			//需要try cash抛异常
    			try {
    				customerService.write(customer);
    			} catch (RemoteException | ServiceException e) {
    				e.printStackTrace();
    				return renderResult(Global.FALSE, text("客户写入EAS失败!"));
    			}
    		}
    		return renderResult(Global.TRUE, text("客户写入EAS成功!"));
    	}
    

      service层:

    @Transactional(readOnly=false, rollbackFor = Exception.class)
    	public void write(Customer customer) throws RemoteException, ServiceException {
    		//调用对象里面的数据传给接口
    		Result sendCustomerInfo = easService.sendCustomerInfo(customer.getCcuscode(), customer.getCcusname(),
    				customer.getCcusenname(), customer.getCcusabbname(), customer.getCcusaddress(),
    				customer.getCcuslperson());
    		//判断它是否成功
    		if(sendCustomerInfo.isFlag()) {
    			//成功则更改它的状态为Y             主要是更改这部分东西
    			customer.setIsup(CustomerConstant.ISUP_Y);
    			this.update(customer);
    		}else {
    			//抛出异常并且提示错误信息
    			throw new BaseException(sendCustomerInfo.getMessage());
    		}
    	}
    

      

  • 相关阅读:
    第十二周作业
    2019春总结作业
    第一次实验总结
    第二次实验总结
    第十二周
    第十一周作业
    第九周作业
    第八周作业
    第七周作业
    第六周作业
  • 原文地址:https://www.cnblogs.com/qijiang123/p/14005704.html
Copyright © 2020-2023  润新知