6

我是玩 2.0 的新手。我创建了一个注册表单,现在我尝试创建一个搜索表单。但我被这个抓住了error: " Missing parameter in call definition: String In /home/thangnk/Task/conf/routes at line 17. "

这是我的代码:

控制器 --- 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));
    }   
}

模型---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)

终端 - -

[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]

希望你们帮我解决它并帮助我完成这个表格。

4

1 回答 1

6

它在您的路由文件中,您颠倒了参数名称和类型:

 POST   /result_search/:username      controllers.Search.searchByusername(username:String)
于 2013-07-15T09:47:21.993 回答