Java 使用链接URL发送参数inThymleaf@
我的页面中有以下表格:Java 使用链接URL发送参数inThymleaf@,java,spring-mvc,thymeleaf,Java,Spring Mvc,Thymeleaf,我的页面中有以下表格: <div class="panel-body"> <table class="table table-bordered table-striped"> <thead> <tr> <th>Issue Date</th> <th>Payment Schedule</th&
<div class="panel-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Issue Date</th>
<th>Payment Schedule</th>
<th>Total</th>
<th>Status</th>
<th>Start Date</th>
<th>End Date</th>
<th>Send Invoice</th>
</tr>
</thead>
<tbody>
<tr class="table-row" th:each="p : ${POList}">
<td th:text="${p.issueDate}"></td>
<td th:text="${p.paymentSchedule}"></td>
<td th:text="${p.total}"></td>
<td th:text="${p.status}"></td>
<td th:text="${p.rentalPeriod.startDate}"></td>
<td th:text="${p.rentalPeriod.endDate}"></td>
<td>
<form style='float:left; padding:5px; height:0px' th:object="${po}" th:method="post" th:action="@{'/dashboard/makeAndSendInvoice(email=${po.Email})'}">
<button class="btn btn-default btn-xs" type="submit">Send Invoice</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
但在我看来,它似乎不起作用,因为它不承认我的方法。
那么如何在我的方法中接收
po.Email
将th:action
更改为:
th:action="@{/dashboard/makeAndSendInvoice/{email}(email=${po.Email})}"
并在RequestMapping
值中添加PathVariable
,如下所示:
@RequestMapping(method=POST, path="/dashboard/makeAndSendInvoice/{email:.+}")
public String makeAndSendInvoice(@PathVariable("email") String email) {
发件人:
URL路径中也允许使用变量模板,如
@{/order/{orderId}/details(orderId=${orderId})}
@Ralph………..当我在方法中打印email值时,它有一个类似于{email}(email=${pI)的值,我已经输入了一个错误。@{…}应该是未引用的。编辑。谢谢它正在工作,但当我发送类似salman@ut.ee它不考虑.EE部分,它不考虑字符之后,这是一个春天MVC的问题。这里你可以找到一个详细的解释:
@RequestMapping(method=POST, path="/dashboard/makeAndSendInvoice/{email:.+}")
public String makeAndSendInvoice(@PathVariable("email") String email) {
<!-- Will produce '/gtvg/order/details?orderId=3' (plus rewriting) -->
<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
<!-- Will produce '/gtvg/order/3/details' (plus rewriting) -->
<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
public String findOwner(@PathVariable String ownerId, Model model) {
Owner owner = ownerService.findOwner(ownerId);
model.addAttribute("owner", owner);
return "displayOwner";
}