我是Play 2.0的新手。我创建了一个注册表单,现在我尝试创建一个搜索表单。但我被error: " Missing parameter in call definition: String In /home/thangnk/Task/conf/routes at line 17. "
抓住了。
这是我的代码:
CONTROLLER --- Search.java
package controllers;
import java.util.ArrayList;
import java.util.List;
import models.Task;
import play.*;
import play.data.Form;
import play.db.ebean.Model.Finder;
import play.mvc.*;
import views.html.*;
public class Search extends Controller{
static Form<Task> myform = form(Task.class);
public static Result search(){
return ok(search.render());
}
public static Result searchByusername(String username){
Form<Task> filledForm = myform.bindFromRequest();
username=filledForm.get().username;
return ok(result_search.render(username));
}
}
MODELS --- Task.java
package models;
import java.util.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import play.data.validation.Constraints.Email;
import play.data.validation.Constraints.MaxLength;
import play.data.validation.Constraints.MinLength;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;
import play.db.ebean.Model.Finder;
@Entity
public class Task extends Model {
@Id
public static Long id;
// @Required
// @MinLength(6)
// @MaxLength(12)
public String password;
@Email
public String email;
// @MinLength(6)
public String username;
public Task() {
}
public Task(Long id, String username, String email, String password) {
this.email = email;
this.username = username;
this.id = id;
this.password = password;
}
public static Finder<Long, Task> find = new Finder(Long.class, Task.class);
public static List<Task> all() {
return find.all();
}
public static void create(Task task) {
task.save();
}
public static void delete(Long id) {
find.ref(id).delete();
}
public static List<Task> searchByusername(String name) {
return find.where().like("username", "%" + name + "%").findList();
}
}
路线 的 的
的GET / controllers.Application.index()
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id:Long)
# POST /showuser controllers.Application.showUser()
# Search
GET /search controllers.Search.search()
POST /result_search/:String controllers.Search.searchByusername(username:String)
-------// This error mark at line "username : String" ----------------------------------
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
的
TERMINAL ----
[error] {file:/home/thangnk/Task/}Task/compile:sources: in /home/thangnk/Task/conf/routes - PlayException: Compilation error [Missing parameter in call definition: String]
[error] application -
! Internal server error, for request [GET /search] ->
sbt.PlayExceptions$RoutesCompilationException: Compilation error [Missing parameter in call definition: String]
at sbt.PlayCommands$$anonfun$52.apply(PlayCommands.scala:433) ~[na:na]
at sbt.PlayCommands$$anonfun$52.apply(PlayCommands.scala:423) ~[na:na]
at sbt.Scoped$$anonfun$hf3$1.apply(Structure.scala:474) ~[na:na]
at sbt.Scoped$$anonfun$hf3$1.apply(Structure.scala:474) ~[na:na]
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:41) ~[scala-library.jar:0.11.3]
at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$11.apply(Structure.scala:295) ~[na:na]
希望你们帮助我解决它并帮助我完成这个表格。
答案 0 :(得分:6)
在您的路线文件中,您反转了参数名称并输入:
POST /result_search/:username controllers.Search.searchByusername(username:String)