2016-04-30 78 views
1

我在Thymleaf页面下面的表格发送参数inThymleaf。 我以为th:action="@{'/dashboard/makeAndSendInvoice(email=${po.Email})'}" 会做出这样dashboard/makeAndSendInvoice/{Email}链接的URL @

一个链接所以我试图得到它在这样的方法:

@RequestMapping(method=POST, path="makeAndSendInvoice") 
    public String makeAndSendInvoice(@PathVariable("email") String email){ 

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

,但在我看来,这是行不通的,因为它不承认我的方法。 因此,如何能接受我的方法

+0

@Ralph ............... –

回答

1

更改th:actionpo.Email

th:action="@{/dashboard/makeAndSendInvoice/{email}(email=${po.Email})}" 

,并在RequestMapping值添加PathVariable像:

@RequestMapping(method=POST, path="/dashboard/makeAndSendInvoice/{email:.+}") 
public String makeAndSendInvoice(@PathVariable("email") String email) { 

Thymeleaf - Link URLs

变量模板也允许URL路径,像 @{/order/{orderId}/details(orderId=${orderId})}

<!-- 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> 

Spring - URI Template Patterns

在Spring MVC,您可以使用一个方法 参数的@PathVariable注释绑定它的价值URI模板变量:

@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"; 
} 
+0

当我在方法中打印电子邮件值时,它有这样的值** {email}(email = $ {p ** –

+1

I'我做了一个错字。 @ {...}中的路径不应加引号。编辑。 –

+0

感谢它的工作,但是当我发送像**[email protected]** 它不考虑** .ee **部分,它不考虑点后的字符 –