在Thymeleaf中创建下拉菜单和表单 [英] Creating drop down menu and form in Thymeleaf
问题描述
我想创建一个下拉菜单,允许客户端通过下拉菜单中指定的字段搜索用户.例如,按州搜索,按城市搜索等.
I want to create a drop down menu that allows a client to search users by a field specified in the drop down menu. For example, search by state, search by city, etc.
这是我到目前为止所拥有的:
This is what I have so far:
<p>Search options:</p>
<form action="#" th:action="@{/get/{value}" method="get">
<select>
<option th:value="AllUsers">Search all users</option>
<option th:value="ByUsername">Search by user name</option>
<option th:value="ByFirstname">Search by first name</option>
<option th:value="ByLastname">Search by last name</option>
<option th:value="ByAddress">Search by address</option>
<option th:value="ByCity">Search by city</option>
<option th:value="ByState">Search by state</option>
<option th:value="ByZipCode">Search by zip code</option>
<option th:value="ByPhoneNumber">Search by phone number</option>
<option th:value="ByEmail">Search by email</option>
</select>
<input type="text" th:field="value" name="searchField"/>
<input type="submit" value="Search" name="searchButton"/>
</form>
我只是不确定如何连接下拉列表中当前所选项目的action
和value
标签以指定URI.如果用户选择按州搜索,然后输入马里兰州",该如何指定相应的URI标签?
I'm just not sure how to connect the action
and the value
tag of the currently selected item in the drop down list to specify the URI. If a user selects, search by state, and he enters in "Maryland", how do I specify the corresponding URI tag?
这将是我在Spring中执行操作的方法:
This would be my method in Spring that executes the action:
@RequestMapping(value = "/get/ByState", method = RequestMethod.GET)
public String getByState() {
// ...
}
@RequestMapping(value = "/get/ByCity", method = RequestMethod.GET)
public String getByCity() {
// ...
}
推荐答案
您仅在此链接中具有所需的答案:
You have just the required answer in this link:
http://fruzenshtein.com/spring-mvc-form-select-tag/
这篇关于在Thymeleaf中创建下拉菜单和表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!