0
我想使用选择框重定向到包含选择值的URL。Thymeleaf + Spring如何从窗体选择选项值传递给控制器@PathVariable
这里娄的HTML页面thymeleaf变量:
<form th:action="@{/app/}">
<select id="app" name="app">
<option th:each="app : ${apps}"
th:value="${app.id}"
th:text ="${app.name}">
</option>
</select>
<button>Go</button>
</form>
控制器写入如下:
@RequestMapping("/app/{appId}")
public ModelAndView getApp(@PathVariable String appId){...}
我的目标是通过URL来访问控制:mydomain/app/{app.id}/
我试着使用th:field
到选择没有成功。我在这里错过了一些东西。
请问,你能解释我如何将选择值添加到控制器预期的URL?
谢谢你的提示
编辑以下@NicolaiEhemann答案
我使用jQuery和Ajax搬到了JavaScript的:
$('button').click(function() {
$.ajax({
url: '/app/' + $('#app').val(),
dataType: 'html'
}).done(function(data) {
$('#result').html(data)
});
});
谢谢。