2016-01-04 5 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"; 
    } 
Смежные вопросы