草庐IT

java - 调用定义中缺少参数错误 : String

coder 2024-03-30 原文

我是 play 2.0 的新手。我创建了一个注册表单,现在我尝试创建一个搜索表单。但是我遇到了这个 错误:“调用定义中缺少参数:字符串在/home/thangnk/Task/conf/routes 中的第 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));
    }   
}

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

希望你们帮我解决问题,帮我完成这个表格。

最佳答案

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

 POST   /result_search/:username      controllers.Search.searchByusername(username:String)

关于java - 调用定义中缺少参数错误 : String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17650367/

有关java - 调用定义中缺少参数错误 : String的更多相关文章

  1. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  2. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  3. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  4. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  5. ruby - RSpec - 使用测试替身作为 block 参数 - 2

    我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere

  6. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  7. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  8. ruby - 如何在 Ruby 中拆分参数字符串 Bash 样式? - 2

    我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"

  9. ruby - 检查方法参数的类型 - 2

    我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)

  10. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

随机推荐