当我尝试访问findById时,显示以下内容:

IllegalArgumentException "id to load is required for loading"


这是我的代码:

package controllers;
import play.*;
import play.mvc.*;
import java.util.*;
import models.*;

public class Application extends Controller {

    public static void index() {

       render();
    }
    public static void saveUser(String name)
    {
        User1 user =new User1(name);
        String res = "";
        if( user.save()!=null){
            res="Stored Successfully";
        }
        else{
            res="Failed to store";
        }
        render(res);
    }
    public static void showUser(Long id)
    {
       User1 user=  User1.findById(id);
       render(user);
    }

}


下面是我的路由文件,我不明白为什么会出现错误和非法参数异常。
    #路线
    #此文件定义所有应用程序路由(优先级高的路由优先)
    #~~~~

# Home page
GET     /                                       Application.index

# Ignore favicon requests
GET     /favicon.ico                            404

# Map static resources from the /app/public folder to the /public path
GET     /public/                                staticDir:public

# Catch all
*       /{controller}/{action}                  {controller}.{action}

最佳答案

抛出IllegalArgumentException,因为id为null。确保在请求中传递正确的值。如下将控制器方法映射到routes文件中将防止传递null:

GET /user/{id} Aplication.showUser

08-20 01:21