我的emailTemplate.html中有一个链接模板,如下所示:
<span>To edit the invoice <a th:href="@{${editAddress}(invoiceid=${invoiceid})}">click here</a></span>
并产生:
http://localhost:8080/edit/?invoiceid=5d088b012f8c32416dbb5522
但是我想拥有:
http://localhost:8080/edit/5d088b012f8c32416dbb5522
我的控制器方法:
@RequestMapping(value = "/edit/{invoiceid}", method = RequestMethod.GET, produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String editInvoice(@PathVariable("invoiceid") String invoiceid, Model model) {
InvoiceData invoiceData = invoiceDataRepository.findById(invoiceid).get();
model.addAttribute("invoicedata", invoiceData);
return "edit";
}
我该如何实现?
答案 0 :(得分:0)
苦苦挣扎后,我变了
<a th:href="@{${editAddress}(invoiceid=${invoiceid})}">click here</a>
到
<a th:href="@{{editAddress}{invoiceid}(invoiceid=${invoiceid},editAddress=${editAddress})}">click here</a>
现在一切正常,输出为:
http://localhost:8080/edit/5d088b012f8c32416dbb5522
答案 1 :(得分:0)
最简单的方法:
<span>To edit the invoice
<a th:href="@{${edit_address + '/' + invoice_id}}">click here</a>
</span>
假设edit_address ='edit'并且invoice_id = 5d088b012f8c32416dbb5522,链接将指向http://localhost:8080/edit/5d088b012f8c32416dbb5522