gpt4 book ai didi

java - 从 Thymeleaf 页面接收参数

转载 作者:行者123 更新时间:2023-12-01 09:58:26 25 4
gpt4 key购买 nike

我尝试从此 thymleaf 页面发送参数

<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Email</th>
<th>Send Invoice</th>
</tr>
</thead>
<tbody>
<tr class="table-row" th:each="p : ${POList}">
<td th:text="${p.email}"></td>
<td>
<form style='float:left; padding:5px; height:0px' th:object="${p}" th:method="post" th:action="@{/dashboard/makeAndSendInvoice/{email}(email=${p.email})}">

<button class="btn btn-default btn-xs" type="submit">Send Invoice</button>
</form>
</td>
</tr>
</tbody>

然后我尝试使用此代码接收参数(电子邮件)

@RequestMapping(method=POST, path="/makeAndSendInvoice/{email}")
public void makeAndSendInvoice(@PathVariable("email") String email) throws Exception {

System.out.println("Invoice is sent to..................."+email);

}

问题是当p.email的值类似于myemail@gmail.com时我在方法 makeAndSendInvoice 中收到的只是 myemail@gmail

并且它没有向我发送 .com 部分

如何修复它?

最佳答案

(email=${p.email}) 表示您正在传递查询参数。那么,如何使用路径变量捕获查询参数值?

我们可以使用@RequestParam来捕获Spring中的queryparam

尝试下面的java代码:

@RequestMapping(method=POST, path="/makeAndSendInvoice/{email}")
public void makeAndSendInvoice(@RequestParam("email") String email) throws Exception {
System.out.println("Invoice is sent to..................."+email);
}

关于java - 从 Thymeleaf 页面接收参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37002860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com