在Scala模板中获取表单
在给定一些输入的情况下,我正在尝试使用GET to search创建表单:在Scala模板中获取表单,scala,playframework-2.0,Scala,Playframework 2.0,在给定一些输入的情况下,我正在尝试使用GET to search创建表单: <form class="form-inline" role="form" method="get" action="@routes.Index.search"> <div class="form-group"> <label for="search-field">Search:</label> <input id="searc
<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>
而我的路由
文件具有以下路由:
GET /search controllers.Index.search(q: String)
我希望这应该像我期望的那样工作,也就是说应该向http://foo.bar/search?q=hello
如果搜索字段中的值为hello
。相反,我得到了以下编译错误:
/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">
/index.scala.html:8:类ReverseIndex中的方法搜索缺少参数;
如果要将其视为部分应用的函数,请使用“\u1”遵循此方法
任何关于这一错误原因的帮助都将不胜感激。问题在于我没有为路由
文件中的查询参数提供默认值:
GET /search controllers.Index.search(q: String ?= "")
解决了这个问题
GET /search controllers.Index.search(q: String ?= "")