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)
});
});
謝謝。