2016-04-30 2 views
1

@リンクのURLを使用してパラメータinThymleafを送信します。 私はので、私はこのような方法でそれを取得しようとしましたth:action="@{'/dashboard/makeAndSendInvoice(email=${po.Email})'}"dashboard/makeAndSendInvoice/{Email}は、私は私の<strong>Thymleaf</strong>ページに次の形式を持つ

のようなリンクを行います考えた:

@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を追加:Thymeleaf - Link URLsから

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

変数テンプレートはまたSpring - URI Template Patternsから @{/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> 

のように、URLパスで許可されています。

は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

私は、タイプミスがありました。 @ {...}のパスは引用符で囲まないでください。編集されました。 –

+0

ありがとうございますが、私は** [email protected]**のようなsthを送ったとき ** .ee **部分は考慮されていません。ドットの後の文字は考慮しません –

関連する問題