選択値を含むURLにリダイレクトするために選択ボックスを使用したいと思います。ここでThymeleaf + Springフォーム選択オプション値から@PathVariableをコントローラに渡す方法
はthymeleaf変数をHTMLページを怒鳴る:
<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答え
を次のヒント
EDITいただきありがとうございます私はjQueryとAJAXを使用してJavaScriptに移動:
$('button').click(function() {
$.ajax({
url: '/app/' + $('#app').val(),
dataType: 'html'
}).done(function(data) {
$('#result').html(data)
});
});
ありがとうございました。