我正在尝试实现一种过滤功能,该功能将按类型显示商家。这是“搜索表单”,用户可以在其中选择要显示的业务类型
@(businessList: List[Business], formSearch: Form[Business])
@import helper._
@main("All businesses"){
@form(action=routes.Application.displayAllBusinesses("")){
@select(formSearch("type"),options(Seq("Dining","Accomodation","Manufacturing","Retail", "Services")),'_label ->"Business Type",'_default->"--Select a business type--")
<input type="submit" class="btn btn-success" value="Search by type">
<a class="btn" href="@routes.Application.displayAllBusinesses()">Show all businesses</a>
<a class="btn" href="/registerBusiness">Register a business</a>
}
然后我有一个for循环来显示所有业务:
<ul>
@for(business <- businessList) {
<li>
<p>Business Name: @business.getName()</p>
<p>Business Type: @business.getType()</p>
<p>Business Email: @business.getEmail()</p>
<p>Business Location: @business.getLocation()</p>
<p>Business Description: @business.getDescription()</p>
<p>Id is: @business.id </p>
<a class="btn" href="@routes.Application.displayUpdateBusiness(business.id)">Update</a>
@form(routes.Application.deleteBusiness(business.id)) {
<input class="btn" type="submit" value="Delete">
}
</li>
}
</ul>
当用户提交表单时,displayAllbusinesses路由看起来像(这是出现错误的地方):
GET /listBusinesses controllers.Application.displayAllBusinesses(type: String ?= "all")
app / Application.java中的displayAllbusinesses方法是:
public static Result displayAllBusinesses(String type){
List<Business> businesses;
if(type=="all"){
businesses = allBusinesses;
} else {
businesses = Business.find.where().like("type", type).findList();
//TRACE
System.out.println(businesses);
}
return ok(listBusinesses.render(businesses, businessForm));
}
当我运行此代码时,我得到/ listBusinesses路由的“非法启动简单表达式”。这是什么意思?
答案 0 :(得分:3)
type是Scala中的保留关键字。路由编译器没有正确地转发它,我认为这是一个已知的错误。
答案 1 :(得分:1)
答案:我在路线中大写了类型
controllers.Application.displayAllBusinesses(Type: String ?= "all")
并将搜索表单更改为大写类型
@form(action=routes.Application.displayAllBusinesses("")){
@select(formSearch("Type"),options(Seq("Dining","Accomodation","Manufacturing","Retail", "Services")),'_label ->"Business Type",'_default->"--Select a business type--")
现在有效。去图