2016-04-30 97 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 **部分,它不考慮點後的字符 –