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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 爱跳舞的程序员

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