【发布时间】:2020-11-07 00:55:40
【问题描述】:
嘿嘿。我是春季靴子和百里香的新手。我不知道如何搜索特定用户。例如,我将输入一个 thymeleaf,每当我搜索特定的用户名时,就会从数据库中查询用户信息。并出现在屏幕上。
这是我的百里香输入框。
listAll 的 Thymeleaf 模板
<!-- /mosque/update(id=${tempList.id}) -->
<h2>List of all trade</h2>
<form th:action="@{/mosque/findPeople}" method="GET">
<input type="text" th:value="${thePeople}" placeholder="Search people" />
<input type="submit" value="Search" />
</form>
<table border="1">
<thead>
<tr>
<th>NAME</th>
<th>ADDRESS</th>
<th>COLLECTION HEAD</th>
<th>AMOUNT</th>
<th>WAY OF PAYMENT</th>
<th>DATE</th>
<th>YEAR OF TRADE</th>
<th>TRADE BY</th>
<th>ACTION</th>
</tr>
</thead>
<tbody>
<tr th:each="tempList : ${listAll}">
<td th:text="${tempList.name}"></td>
<td th:text="${tempList.address}"></td>
<td th:text="${tempList.trade_head}"></td>
<td th:text="${tempList.amount}"></td>
<td th:text="${tempList.wop}"></td>
<td th:text="${tempList.date}"></td>
<td th:text="${tempList.yot}"></td>
<td th:text="${tempList.trade_by}"></td>
<td><a th:href="@{/mosque/update(id=${tempList.id})}">Update</a>
<a th:href="@{/mosque/delete(id=${tempList.id})}"
onclick="if(!(confirm('Are you sure you want to update?'))) return false">Delete</a></td>
</tr>
</tbody>
</table>
<form th:action="@{/mosque/findPeople}" method="GET">
<input type="text" th:value="${thePeople}" placeholder="Search people" />
<input type="submit" value="Search" />
</form>
这是我的控制器类。
@GetMapping("/findPeople")
public String findPeople(@RequestParam("people") String thePeople, Model theModel) {
List<Mosque> theMosque = theMosqueService.findPerson(thePeople);
theModel.addAttribute("thePeople", theMosque);
return "listAll";
}
这是我为特定用户所做的查询
// Search People
@Query("SELECT person FROM Mosque person WHERE person.name like %?1%")
List<Mosque> findPerson(String value);
【问题讨论】:
-
可以给listAll添加thymleaf模板吗
-
是的已添加。请在上面查看。
-
你必须在People not listAll上进行迭代
-
我想你没有得到我的问题。不要关心列出所有成员。我只想通过用户名获取特定用户。我将在输入框中输入一个名称,然后它会给我用户信息。
-
那么您尝试这样做的错误是什么?
标签: spring spring-boot spring-mvc spring-data-jpa spring-data