2016-05-03 7 views
0

ich versucht habeParameter von Thymleaf Seite

<table class="table table-bordered table-striped"> 
    <thead> 
     <tr> 
      <th>Email</th> 
      <th>Send Invoice</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr class="table-row" th:each="p : ${POList}"> 
      <td th:text="${p.email}"></td> 
      <td> 
      <form style='float:left; padding:5px; height:0px' th:object="${p}" th:method="post" th:action="@{/dashboard/makeAndSendInvoice/{email}(email=${p.email})}"> 

       <button class="btn btn-default btn-xs" type="submit">Send Invoice</button> 
      </form> 
      </td> 
     </tr> 
    </tbody> 

einen Parameter aus dieser thymleaf Seite zu senden und dann habe ich versucht, den Parameter (email) mit diesem Code

@RequestMapping(method=POST, path="/makeAndSendInvoice/{email}") 
public void makeAndSendInvoice(@PathVariable("email") String email) throws Exception { 

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

    } 

Das Problem ist, zu erhalten wenn der Wert von p.email ist so etwas wie [email protected] was ich in der Methode makeAndSendInvoice erhalten, ist nur [email protected]

und es sendet mir nicht die .com teil

Wie kann ich es beheben?

+0

Ich glaube, Sie haben Fehler bei Ihrem Formularlayout gemacht, wenn Sie diese Zeit an E-Mails übergeben haben, die Sie im Browser debuggen, welcher Wert übergeben wird? –

Antwort

0

Die Zeit in „.com“ muss es als Suffix

+0

was ist, wenn ich ein Präfix wie **. Ee ** brauche –

1

(email=${p.email}) Mittel analysiert werden, um zu verhindern in der URL verwendet werden, codiert werden, Abfrageparameter sind vorbei Sie. Also, wie können Sie in der Lage sein, den Abfrageparamwert mithilfe der Pfadvariablen abzufangen?

Wir können @RequestParam verwenden, um die queryparam Wert im Frühjahr zu fangen

Versuchen Sie, die folgenden Java-Code:

@RequestMapping(method=POST, path="/makeAndSendInvoice/{email}") 
public void makeAndSendInvoice(@RequestParam("email") String email) throws Exception { 
     System.out.println("Invoice is sent to..................."+email); 
} 
0

Ihre HTML:

<table class="table table-bordered table-striped"> 
<thead> 
    <tr> 
     <th>Email</th> 
     <th>Send Invoice</th> 
    </tr> 
</thead> 
<tbody> 
    <tr class="table-row" th:each="p : ${POList}"> 
     <td th:text="${p.email}"></td> 
     <td> 
     <form method="post" th:action="@{/dashboard/makeAndSendInvoice/__${p.email}__} "> 

      <button class="btn btn-default btn-xs" type="submit">Send Invoice</button> 
     </form> 
     </td> 
    </tr> 
</tbody> 

Ihr Controller

@RequestMapping(value = "/dashboard") 
@Controller 
public class testController { 

    ... 

    @RequestMapping(value = "/makeAndSendInvoice/{email}", method = RequestMethod.POST) 
    public ModelAndView makeAndSendInvoice(@PathVariable String email, ModelAndView mav) { 
     return mav; // <- Break point, debug !! 
    } 
} 
Verwandte Themen