使用JavaScript Submit()通过Spring引导提交表单数据

使用JavaScript Submit()通过Spring引导提交表单数据,javascript,java,spring,spring-boot,Javascript,Java,Spring,Spring Boot,我的最终目标是将POST数据发送回Spring,它可以处理这些数据。但是,我没有使用标记。我想在屏幕上显示一个项目列表,类似于本机移动界面中的列表布局,并提交包含所选项目信息的POST数据 HTML的相关片段如下所示: <ons-list> <form id="form" action="#" th:action="@{/week-hours-summary}" method="post"&

我的最终目标是将POST数据发送回Spring,它可以处理这些数据。但是,我没有使用
标记。我想在屏幕上显示一个项目列表,类似于本机移动界面中的列表布局,并提交包含所选项目信息的POST数据

HTML的相关片段如下所示:

<ons-list>
    <form id="form" action="#" th:action="@{/week-hours-summary}" method="post">
        <ons-list-item
                tappable
                th:each="item, iterStat : ${list}"
                th:data-user="${item.value.getTitle()}"
                th:data-date="${date}"
                onclick="submit(document.getElementById('form'), this.getAttribute('data-user'), this.getAttribute('data-date'), 'week-hours-summary')">
            <div class="center">
                <span class="list-item__title" th:text="${item.value.getTitle().toUpperCase()}">Not Sure</span>
                <span class="list-item__subtitle" th:text="${item.value.getSubtitle().toUpperCase()}">RT:38 | OT:3.25</span>
            </div>
        </ons-list-item>
    </form>
</ons-list>
这是
@控制器中接收端的方法签名:

@PostMapping("/week-hours-summary")
public String showUserWeekHoursByDay(@ModelAttribute String user, @ModelAttribute String dateString, Model model)
变量被传递到方法中,但用户字段和日期字段均为
null
。为什么呢?来自
标记的表单数据有什么神奇之处,Spring可以处理它,但不会处理用JavaScript填充的表单


web控制台显示JavaScript确实在获取值并将其作为表单的一部分发送。为什么它们在春季为
null

查看FormData()并将其与ajax或更好的fetch()一起使用。是否有理由只使用
submit()
,或者允许使用其他方式作为
ajax
@PostMapping("/week-hours-summary")
public String showUserWeekHoursByDay(@ModelAttribute String user, @ModelAttribute String dateString, Model model)