我最终离开了这样的路线:GET /latest controllers.Find.findLatest(repo=null)和类似的视图:<form action="@routes.Find.findLatest(null)" method="get"> <select name="repo"> .... </select>....</form>并在控制器中:public Result findLatest(String repoStr) { if(repoStr==null) { repoStr=Form.form().bindFromRequest().get("repo");.....这使我拥有第二条路线,例如:GET /latest/:repo controllers.Find.findLatest(repo: String)In my Find controller I have a method like:public Result findLatest(String repoStr) { ............}Which is linked through a route:GET /latest controllers.Find.findLatest(repo: String)Then, I have a form in a view like:<form action="@routes.Find.findLatest()" method="get"> .... <select name="repo">....</select></form>But obviously that is failing, because it is expecting some parameters that I do not fulfill in the action. What is the correct way to do this without having to end up leaving the findLatest method taking no parameters in my controller? 解决方案 Cavice suggested something close to what I consider the best solution for this (since F.Option are not supported anymore with the default binders in Play 2.1 ).I ended up leaving the route like:GET /latest controllers.Find.findLatest(repo=null)and the view like: <form action="@routes.Find.findLatest(null)" method="get"> <select name="repo"> .... </select>....</form>and in the controller:public Result findLatest(String repoStr) { if(repoStr==null) { repoStr=Form.form().bindFromRequest().get("repo");.....This allows me to have a second route like:GET /latest/:repo controllers.Find.findLatest(repo: String) 这篇关于将html表单动作绑定到需要一些参数的控制器方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 23:46