java总结

Jquery ajax

function checkSchema(){

    var rows = $('#MAINTable').datagrid('getSelections');

    var ids = "";

    if(rows.length > 0){

        var idsArray = new Array();

        for(var i=0; i<rows.length; i++){

            idsArray.push(rows[i]['PACKAGE_ID']);

        }

        ids = idsArray.join(',');

        $.post('elecFileAccess!toDoRecordPage.action',{'packageId':ids},function(data){

            if(data == 'eep'){

                var url= 'elecFileAccess!checkSchema.action?ids='+ids;

                var bhlDlg = new BhlDialog(url,"验证结果信息",500,250);   

                parent.showBhlDialog(bhlDlg);

            }

            if(data == 'zip'){

                $.messager.alert("系统提示","zip文件暂时不提供Schema验证!",'error');

            }

            if(data != 'eep' && data != 'zip'){

                $.messager.alert("系统提示","该批次电子文件不存在!",'error');

            }

        });

    }else{

        $.messager.alert("系统提示","请选择需要验证Schema的移交批次!",'info');

    }

}

直接返回string

protected void writeHtml(StringstrData) {

        try {

            response.setContentType("text/html;charset=UTF-8");

            PrintWriter pw = response.getWriter();

            pw.write(strData);

            pw.flush();

            pw.close();

        } catch (IOException e) {

          log.error("writeHtml()", e);

        }

    }

返回数组

public void doHaveData(){

        String packageId = request.getParameter("packageId");

        String dorecord = request.getParameter("dorecord");

        String str = elecFileAccessService.doHaveData(packageId);

        if(dorecord!=null && str.equals("")){//电子文件入库和审核

            str = elecFileAccessService.haveCheckNo(packageId,dorecord);

        }      

        JSONObject jsonObject = new JSONObject();  

        jsonObject.put("str", str);

        JSONArray jsonArray= new JSONArray();

        jsonArray.add(jsonObject);      

        if(str.equals("")){

            writeJson(jsonArray,true);

        }else{

            writeJson(jsonArray,false);

        }

    }

 

protected void writeJson(Object result,boolean isSuccess) {

        try {

            response.setContentType("text/json;charset=utf-8");

            PrintWriter writer = response.getWriter();

            if (isSuccess) {

                writer.write("{\"success\":true" +

                     (result != null ? ",\"result\":"+result+"}" : "}"));

            } else {

                writer.write("{\"success\":false" +

                        (result != null ? ",\"result\":"+result+"}" : "}"));

            }          

            writer.flush();

            writer.close();

        } catch (IOException e) {

          log.error("writeJson()", e);

        }

}

 

 

构造树结构:

public String initPage() {

        List<TreeNodeModel> treeNodeList = newArrayList<TreeNodeModel>();

        TreeNodeModel tree2 = new TreeNodeModel();

        tree2.setId("-2");

        tree2.setpId("-20");

        tree2.seticon(6);

        tree2.setName("离线接收审核");

        TreeNodeModel tree3 = new TreeNodeModel();

        tree3.setId("-3");

        tree3.setpId("-20");

        tree3.seticon(6);

        tree3.setName("退回");

        TreeNodeModel tree4 = new TreeNodeModel();

        tree4.setId("-4");

        tree4.setpId("-20");

        tree4.seticon(6);

        tree4.setName("入库");

       

 

        TreeNodeModel tree8 = new TreeNodeModel();     

        tree8.setId("-6");

        tree8.setpId("-3");

        tree8.seticon(1);

        tree8.setName("待退回");

        int nuBackCount=elecFileAccessService.getToDoListCount("Nuback", -1, -1, "",true);

        tree8.setDiyParameter2(nuBackCount+"");

        TreeNodeModel tree5 = new TreeNodeModel();

        tree5.setId("-7");

        tree5.setpId("-3");

        tree5.seticon(1);

        tree5.setName("已退回");

        int backCount=elecFileAccessService.getToDoListCount("Back", -1, -1 ,"",true);

        tree5.setDiyParameter2(backCount+"");

        TreeNodeModel tree6 = new TreeNodeModel();

        tree6.setId("-8");

        tree6.setpId("-4");

        tree6.seticon(1);

        tree6.setName("待入库");

        int norecordCount=elecFileAccessService.getToDoListCount("Norecord", -1, -1, "",true);

        tree6.setDiyParameter2(norecordCount+"");

        TreeNodeModel tree7 = new TreeNodeModel();

        tree7.setId("-9");

        tree7.setpId("-4");

        tree7.seticon(1);

        tree7.setName("已入库");

        int recordCount=elecFileAccessService.getToDoListCount("Record", -1, -1, "",true);

        tree7.setDiyParameter2(recordCount+"");

        TreeNodeModel treeNode = null;

        int flowId = recordsAuditService.getElecAuditFlowId();

        List<FlowStepModel> flowSteps = flowService.findAllFlowStep(flowId);

        int i=1;

        int stepCount=flowSteps.size();

        Object userModel = request.getSession().getAttribute(

                ApplicationConst.SESSION_USER);

        String userName =((UserModel) userModel).getUserName();

        int userId= ((UserModel) userModel).getUserId();

        for (FlowStepModel step : flowSteps) {

            treeNode = new TreeNodeModel();

            int stepId=step.getStepId();

            int count=0;

            if(step.getStepNo()>1){

                count=elecFileAccessService.getToDoListCount("", stepId,step.getStepNo(),userName,true);

            }else{

                //接收申请的时候需查看该用户是否是设定的查看人员

                boolean flag=getIsHavePermission(userName, userId, step); //查看当前用户是否有查看权限

                if(flag){

                    count=elecFileAccessService.getToDoListCount("", stepId,step.getStepNo(),userName,true);

                }

            }

            treeNode.setId(step.getStepId() + "");

            treeNode.setpId("-2");

            treeNode.seticon(1);

            treeNode.setName(step.getStepName());

            treeNode.setvalues(step.getStepNo() + "");

            treeNode.setDiyParameter2(count+"");

            //设置标示位来表示当前节点是否是审核的最后节点

            if(i==stepCount){

                treeNode.setDiyParameter1(1+"");

            }else{

              treeNode.setDiyParameter1(0+"");

           }

           treeNodeList.add(treeNode);

           i++;

       }

 

       treeNodeList.add(tree2);

       treeNodeList.add(tree3);

       treeNodeList.add(tree4);

       treeNodeList.add(tree8);

       treeNodeList.add(tree5);

       treeNodeList.add(tree6);

       treeNodeList.add(tree7);

       request.setAttribute("treeNodeList", JSONArray.fromObject(treeNodeList));

       request.setAttribute("flowId", flowId);

       return "initPage";

}

 

 

var setting = {

        data:{key:{},simpleData:{enable:true}},

        callback:{onClick:TreeNodeOnClick}

    };

 

function initTree(){

    zNodes = new Array();  

    if(treeNodeList!=null && treeNodeList.length>0){

        for(var i=0; i<treeNodeList.length; i++){

            var pId=treeNodeList[i].pId;

            var nodeName=treeNodeList[i].name;

            if(pId!=-20){

                nodeName+='('+treeNodeList[i].diyParameter2+')'

            }

            var treeNode ={id:treeNodeList[i].id,pId:treeNodeList[i].pId,name:nodeName,icon:treeNodeList[i].icon,values:treeNodeList[i].values,open:true,isEnd:treeNodeList[i].diyParameter1,count:treeNodeList[i].diyParameter2};

           

            zNodes.push(treeNode);

        }

    }

    $.fn.zTree.init($("#tree"), setting,zNodes);

   // 选中树节点

   zTreeObj = $.fn.zTree.getZTreeObj("tree");

      var node = zTreeObj.getNodeByParam("id", nowStepId, null);

      if (nowStepId == -8) {

         nodes = zTreeObj.getNodes();

         zTreeObj.selectNode(nodes[2].children[0]);

      }else{

      if (node != null && node != '') {

         // 刷新时,重新选中之前的节点

         zTreeObj.selectNode(node);

      }else {

         // 默认选中第一个节点

         nodes = zTreeObj.getNodes();

         if (nodes.length > 0) {

            setTimeout("zTreeObj.selectNode(nodes[0].children[0])", 200);

            TreeNodeOnClick("", "", nodes[0].children[0], "");

         }

      } 

      }

}

 

 

 

Ie不兼容trim解决代码:

String.prototype.trim = function () {

    return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' );

 }

 

Map 遍历key+value

keySet遍历key+value(写法1):

Iterator<String> iter = map.keySet().iterator();

while (iter.hasNext()) {

    key = iter.next();

    value = map.get(key);

}

keySet遍历key+value(写法2):

for (String key : map.keySet()) {

    value = map.get(key);

}

 

 

 

 

下拉框后台赋值

$(document).ready(function(){       

         var path = ${path};

         var pathIds=${pathIds};    

         var len=pathIds.length;

         for(var i=0;i<len;i++){         

              $('#path').append('<optionvalue='+pathIds[i]+' > '+path[i]+'</option>');

         }

});

 

<select name="path" id="path"style="width:240px;"> </select>

 

后台代码

public String doRecordChoose(){

         //查找所有的可供选择的电子文件存储路径

         Map<Integer,String> pathMap=elecFileAccessService.getPathNameListByType("2");

         Set<Integer> keys=pathMap.keySet();

         String[] array=new String[keys.size()];

         int i=0;

         for(Integer id:keys){

              array[i]=pathMap.get(id);

              i++;

             

         }

         request.setAttribute("path", JSONArray.fromObject(array));

         request.setAttribute("pathIds", JSONArray.fromObject(pathMap.keySet().toArray()));

         request.setAttribute("packageId", request.getParameter("packageId"));

         request.setAttribute("nowStepId", request.getParameter("nowStepId"));

         return "recordPathChoose";

     }

 

 

 

ServletContext context =getServletContext();

        //获取项目路径

        String webapp_path= context.getRealPath("/");

 

        WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());

        //获取服务信息类

        final DescriptService descriptService =(DescriptService)wac.getBean("descriptService");

        //获取服务信息类

        final MultimediaPathService multimediaPathService =(MultimediaPathService)wac.getBean("multimediaPathService");

        //ffmpeg地址

    final String ffmpegPath = webapp_path+"install\\ffmpeg\\ffmpeg.exe";

 

JS中获取url参数

this.getValue = function(paras){//所要取的参数名称传过来

                  var url =window.location.href;  

                  var paraString =url.substring(url.indexOf("?") + 1,url.length).split("&");  

                  var paraObj = {};

                  for (i = 0; j =paraString[i]; i++) {  

                     paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] =j.substring(j.indexOf("=") + 1, j.length);  

                  }  

                  var returnValue =paraObj[paras.toLowerCase()];  

                  if (typeof(returnValue) == "undefined") {  

                      return"";  

                  } else {  

                      returnreturnValue;  

                  }  

       };

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值