我有一个控制器说,
@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 :(得分: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";
}