2016-01-04 77 views
0

我有一個控制器說,如何通過thymleaf發送參數?

@RequestMapping(value = "/search/{lastname}", method = RequestMethod.GET) 
    public String searchAlpha(@PathVariable String lastname) { 
     log.info("-------------------"); 
     log.info(lastname); 
     return "welcome"; 
    } 

和一個表單

<form action="#" th:action="@{/search/__${lastName}__}" method="get" class="form-horizontal"> 
     <div class = "form-group"> 
      <input th:field="*{lastName}" type="text" class="form-control" placeholder="Last Name" /> 
       <span class="input-group-btn"> 
       <button class="btn btn-default" type="submit">Search</button> 
       </span> 
     </div> 

如何使發送的參數,而無需使用模式?

回答

0

發現這樣做的方式。

<form action="#" th:action="@{/search}" method="get" class="form-horizontal"> 
     <div class = "form-group"> 
      <input name="lastname" id="lastname" type="text" class="form-control" placeholder="Last Name" /> 
       <span class="input-group-btn"> 
       <button class="btn btn-default" type="submit">Search</button> 
       </span> 
     </div> 
</form> 

並在控制器,而不是@pathvariable使其@RequestParam

@RequestMapping(value = "/search", method = RequestMethod.GET) 
    public String searchAlpha(@RequestParam String lastname) { 
     log.info(lastname); 
     return "welcome"; 
    }