【发布时间】:2023-03-15 19:45:02
【问题描述】:
我有一个页面,可以在其中获取条目列表。现在,我希望能够从这些列表中进行搜索。
我当前用于检索列表的 url 是 /show/products。我想在此页面中添加一个搜索表单,以便我可以使用请求参数进行搜索。 是的,我可以使用 ajax,但我必须使用请求参数。
所以如果我搜索产品名称,那么 - /show/products?name=someName
<form ui-jp="parsley" th:action="@{/show/products(name=${pName})}" th:object="${pName}" method="get">
<div class="row m-b">
<div class="col-sm-6">
Search by Name:
<input id="filter" type="text" th:field="*{pName}" class="form-control input-sm w-auto inline m-r"/>
<button class="md-btn md-fab m-b-sm indigo">
<i class="material-icons md-24"></i>
</button>
</div>
</div>
</form>
这就是我在控制器中尝试过的:
@GetMapping("/show/products")
public String getProduct(Model model,
@RequestParam(required = false) String name,
@ModelAttribute String pName) {
List<Product> products = this.productService.getAllProducts(name)
model.addAttribute("products", products);
return "show_product";
}
我收到此错误:
Neither BindingResult nor plain target object for bean name 'pName' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153)
at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:897)
【问题讨论】:
标签: java spring spring-mvc thymeleaf