惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Scott Helme
Scott Helme
Webroot Blog
Webroot Blog
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
Hacker News: Ask HN
Hacker News: Ask HN
PCI Perspectives
PCI Perspectives
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News | PayPal Newsroom
Help Net Security
Help Net Security
The Hacker News
The Hacker News
H
Heimdal Security Blog
O
OpenAI News
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 叶小钗
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
I
Intezer
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security Affairs
P
Proofpoint News Feed
S
Secure Thoughts
腾讯CDC
Google DeepMind News
Google DeepMind News
量子位
罗磊的独立博客

博客园 - 爱跳舞的程序员

freemarker对数字格式的处理 FilePathJaxbUtil(xml文件转JavaBean对象工具) freemarker对日期的处理 PL_SQL常用快捷键 将博客搬至CSDN css+jquery右下角弹框提示框(工作需要就开发调式了) textarea文本居中的问题 bat批量复制文件(一键打包更新代码,避免手动一个个复制) url特殊字符传递参数解决方法(特指超链接) js 拼接字符串带变量(js方法参数单双引号拼接的问题记录) 解决复制select下拉框时 值没法复制的问题 Jquery操作select汇总 博文阅读密码验证 - 博客园 ztree树添加右击菜单 ligerLayout布局(左右分栏) 模糊查询+首字母查询组合框 displayTag解决中文排序、和翻页查询出错的问题 jquery之ztree树入门(输出最简单树形) java 根据word xml模板生成word(个人v2版本)
表单提交由submit改为异步的方式
爱跳舞的程序员 · 2023-10-07 · via 博客园 - 爱跳舞的程序员

1,submit方式(页面会按action的url跳转,这个不方便一些交互)

function saveSingleYx(){
    $('#myTwoForm').submit();
}

2,ajax异步方式

function saveSingleYx(){
    //document.getElementById('myTwoForm').setAttribute("action", "saveSingleYx.ht");
     //$("myTwoForm").submit(function (event) {
         //event.preventDefault(); // 阻止表单的默认提交行为
         var formData =  $('#myTwoForm').serialize(); // 序列化表单数据                 
         $.ajax({
             url: "saveSingleYx.ht",
             type: "POST",
             data: formData,
             success: function (response) {
                 // 请求成功,处理后端返回的数据
                 console.log(response);
                 alert(response);
                 window.location.reload();
             },
             error: function () {
                 // 请求失败,处理错误情况
                 console.log("保存失败!!");
             }
         });
     //});
}

java后端

    @RequestMapping("saveSingleYx")
    @Action(description = "保存")
    @org.springframework.web.bind.annotation.ResponseBody
    public String saveSingleYx(HttpServletRequest request, HttpServletResponse response, Yjsydbsplc yjsydbsplc) throws Exception {
        String resString= "保存成功";try {
            List<Sydbyxsub> initSubAll = this.initSubAll(request);
            if (initSubAll!=null) {
                sydbyxsubService.batchUpdate(initSubAll);
            }else {
                logger.info("initSubAll=" + initSubAll);
            }
        } catch (Exception e) {
            resString  = "保存失败 请联系管理员!!"+e.getMessage();
        }
        return resString;
    }

    public List<Sydbyxsub> initSubAll(HttpServletRequest request) {

        List<Sydbyxsub> listSubAll = new ArrayList<Sydbyxsub>();

        // 所有子表id
        String[] idList = request.getParameterValues("subId");
        if (idList == null) {
            return null;
        }
        System.out.println("subId==" + idList.length);
        // 通过id 产生每个实例对象
        for (int i = 0; i < idList.length; i++) {
            Sydbyxsub sub = new Sydbyxsub();
            String idString = idList[i];
            if (idString != null && idString != "") {
                sub.setId(Long.parseLong(idString));
                listSubAll.add(sub);
            } else {
                System.out.println("有个subid为空" + idString);
            }
        }

        // 初始化实例对象的每个属性值
        String[] byzdList = request.getParameterValues("byzd");
        for (int i = 0; i < byzdList.length; i++) {
            if (byzdList[i] != null) {
                listSubAll.get(i).setByzd(byzdList[i]);
            }
        }
        String[] xhlxList = request.getParameterValues("xhlx");// 这个数量多了1,咋来的
        if (xhlxList != null) {
            // System.out.println(xhlxList.length);
            // System.out.println(listSubAll.size());
            for (int i = 0; i < xhlxList.length; i++) {
                if (xhlxList[i] != null) {
                    listSubAll.get(i).setXhlx(xhlxList[i]);
                }
            }
        }

        String[] ztList = request.getParameterValues("zt");

        if (ztList != null) {
            System.out.println("ztList=" + ztList.length);
            System.out.println("listSubAll=" + listSubAll.size());
            for (int i = 0; i < ztList.length; i++) {
                if (ztList[i] != null) {
                    listSubAll.get(i).setZt(ztList[i]);
                }
            }
        }

        String[] wjList = request.getParameterValues("wj");
        // logger.info("wjList="+wjList.length);
        for (int i = 0; i < wjList.length; i++) {
            if (wjList[i] != null) {
                listSubAll.get(i).setWj(wjList[i]);
            }
        }
        // String[] yxList = request.getParameterValues("yx");
        // for (int i = 0; i < yxList.length; i++) {
        // listSubAll.get(i).setYx(yxList[i]);
        // }
        String[] yxmcList = request.getParameterValues("yxmc");
        for (int i = 0; i < yxmcList.length; i++) {
            if (yxmcList[i] != null) {
                listSubAll.get(i).setYxmc(yxmcList[i]);
            }
        }
        String[] sfhbList = request.getParameterValues("sfhb");
        for (int i = 0; i < sfhbList.length; i++) {
            if (sfhbList[i] != null) {
                listSubAll.get(i).setSfhb(sfhbList[i]);
            }
        }
        String[] lbList = request.getParameterValues("lb");
        for (int i = 0; i < lbList.length; i++) {
            if (lbList[i] != null) {
                listSubAll.get(i).setLb(lbList[i]);
            }
        }
        String[] czmcList = request.getParameterValues("cz");
        for (int i = 0; i < czmcList.length; i++) {
            if (czmcList[i] != null) {
                listSubAll.get(i).setCz(czmcList[i]);
            }
        }
        String[] gjdjList = request.getParameterValues("gjdj");
        for (int i = 0; i < gjdjList.length; i++) {
            if (gjdjList[i] != null) {
                listSubAll.get(i).setGjdj(gjdjList[i]);
            }
        }
        String[] sfgzpList = request.getParameterValues("sfgzp");
        for (int i = 0; i < sfgzpList.length; i++) {
            if (sfgzpList[i] != null) {
                listSubAll.get(i).setSfgzp(sfgzpList[i]);
            }
        }
        String[] jxList = request.getParameterValues("jx");
        for (int i = 0; i < jxList.length; i++) {
            if (jxList[i] != null) {
                listSubAll.get(i).setJx(jxList[i]);
            }
        }
        String[] sfykList = request.getParameterValues("sfyk");
        for (int i = 0; i < sfykList.length; i++) {
            if (sfykList[i] != null) {
                listSubAll.get(i).setSfyk(sfykList[i]);
            }
        }
        String[] xhoneList = request.getParameterValues("xhone");
        for (int i = 0; i < xhoneList.length; i++) {
            if (xhoneList[i] != null) {
                listSubAll.get(i).setXhone(xhoneList[i]);
            }
        }
        String[] jgList = request.getParameterValues("jg");
        for (int i = 0; i < jgList.length; i++) {
            if (jgList[i] != null) {
                listSubAll.get(i).setJg(jgList[i]);
            }
        }
        String[] jgmcList = request.getParameterValues("jgmc");
        for (int i = 0; i < jgmcList.length; i++) {
            if (jgmcList[i] != null) {
                listSubAll.get(i).setJgmc(jgmcList[i]);
            }
        }
        String[] hbhxhList = request.getParameterValues("hbhxh");
        for (int i = 0; i < hbhxhList.length; i++) {
            if (hbhxhList[i] != null) {
                listSubAll.get(i).setHbhxh(hbhxhList[i]);
            }
        }
        String[] xxlxmcList = request.getParameterValues("xxlxmc");
        for (int i = 0; i < xxlxmcList.length; i++) {
            if (xxlxmcList[i] != null) {
                listSubAll.get(i).setXxlxmc(xxlxmcList[i]);
            }
        }
        String[] gfxxmsList = request.getParameterValues("gfxxms");
        for (int i = 0; i < gfxxmsList.length; i++) {
            if (gfxxmsList[i] != null) {
                listSubAll.get(i).setGfxxms(gfxxmsList[i]);
            }
        }
        String[] sfznzList = request.getParameterValues("sfznz");
        for (int i = 0; i < sfznzList.length; i++) {
            if (sfznzList[i] != null) {
                listSubAll.get(i).setSfznz(sfznzList[i]);
            }
        }
        String[] xhList = request.getParameterValues("myXh");
        for (int i = 0; i < xhList.length; i++) {
            if (xhList[i] != null && xhList[i] != "") {
                listSubAll.get(i).setXh(Long.parseLong(xhList[i]));
            }
        }
        String[] dhList = request.getParameterValues("dh");
        for (int i = 0; i < dhList.length; i++) {
            if (dhList[i] != null) {
                listSubAll.get(i).setDh(dhList[i]);
            }
        }
        String[] hbztList = request.getParameterValues("hbzt");
        for (int i = 0; i < hbztList.length; i++) {
            if (hbztList[i] != null) {
                listSubAll.get(i).setHbzt(hbztList[i]);
            }
        }
        return listSubAll;
    }

initSubAll