Scala 模板中的 GET 表单
GET form in Scala templates
我正在尝试使用 GET 创建一个表单以在给定一些输入的情况下进行搜索:
<form class="form-inline" role="form" method="get" action="@routes.Index.search">
<div class="form-group">
<label for="search-field">Search:</label>
<input id="search-field" class="form-control" type="text" name="q" placeholder="Sun"/> </div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
其中 Index
控制器具有以下方法:
def search(q: String) = Action.async {
...
}
我的 routes
文件有以下路径:
GET /search controllers.Index.search(q: String)
我原以为这应该会像我预期的那样工作,也就是说,如果 search-field
中的值为 hello
,则应该向 http://foo.bar/search?q=hello
发出 GET
请求.相反,我收到以下编译错误:
/index.scala.html:8: missing arguments for method search in class ReverseIndex;
follow this method with `_' if you want to treat it as a partially applied function
<form class="form-inline" role="form" method="get" action="@routes.Index.search">
任何关于为什么这是错误的帮助将不胜感激。
问题是我没有为 routes
文件中的查询参数提供默认值:
GET /search controllers.Index.search(q: String ?= "")
已解决问题。
我正在尝试使用 GET 创建一个表单以在给定一些输入的情况下进行搜索:
<form class="form-inline" role="form" method="get" action="@routes.Index.search">
<div class="form-group">
<label for="search-field">Search:</label>
<input id="search-field" class="form-control" type="text" name="q" placeholder="Sun"/> </div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
其中 Index
控制器具有以下方法:
def search(q: String) = Action.async {
...
}
我的 routes
文件有以下路径:
GET /search controllers.Index.search(q: String)
我原以为这应该会像我预期的那样工作,也就是说,如果 search-field
中的值为 hello
,则应该向 http://foo.bar/search?q=hello
发出 GET
请求.相反,我收到以下编译错误:
/index.scala.html:8: missing arguments for method search in class ReverseIndex;
follow this method with `_' if you want to treat it as a partially applied function
<form class="form-inline" role="form" method="get" action="@routes.Index.search">
任何关于为什么这是错误的帮助将不胜感激。
问题是我没有为 routes
文件中的查询参数提供默认值:
GET /search controllers.Index.search(q: String ?= "")
已解决问题。