找不到' byId()'和'找到'在playframework 2.4中的ebeans方法

时间:2016-09-16 11:02:43

标签: java playframework

我想使用' byId()'在playframework 2.4中的ebeans方法;

程序返回'找不到符号byId()'。

然而,' .all()'方法可以工作并获取数据。(我想知道为什么)。

这是一段代码。

import java.util.List;
import models.UserMaster;
import com.avaje.ebean.Model.Finder;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.*;
import com.avaje.ebean.Query;

public class TestController extends Controller {

public Result test(){

    //Finder<Long, UserMaster> finder = new Finder<Long,UserMaster> (Long.class, UserMaster.class);

    UserMaster UserMaster = UserMaster.find.byId(1L);

    return ok(test.render(teststring));

}
}

这是一个模型(摘要)。

package models;

import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.avaje.ebean.Model;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.UpdatedTimestamp;
import com.avaje.ebean.Model.Finder;


@Entity
@Table(name = "user_master")
public class UserMaster extends Model {

   @Id
   @Column(name = "user_id")
   private String userId;

   @Column(name = "user_name")
   private String userName;


   @Column(name = "password")
   private String password;

   @CreatedTimestamp
   @Column(name = "regist_time")
   private Timestamp registTime;


   @UpdatedTimestamp
   @Column(name = "update_time")
   private Timestamp updateTime;

/**
 * find
 */

public static Finder<Long, UserMaster> finder = new Finder<Long,UserMaster> (Long.class, UserMaster.class);


}

我也试过finder.find.byid(1),但它也没有用。 你能帮我一把吗?

1 个答案:

答案 0 :(得分:1)

你的模特:

import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.avaje.ebean.Model;
import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.UpdatedTimestamp;
import com.avaje.ebean.*;



@Entity
@Table(name = "user_master")
public class UserMaster extends Model {

   @Id
   @Column(name = "user_id")
   private String userId;

   @Column(name = "user_name")
   private String userName;


   @Column(name = "password")
   private String password;

   @CreatedTimestamp
   @Column(name = "regist_time")
   private Timestamp registTime;


   @UpdatedTimestamp
   @Column(name = "update_time")
   private Timestamp updateTime;

/**
 * find
 */

  public static Find<Long,UserMaster> find = new Find<Long,UserMaster>(){};


}

在您的控制器中:

public class TestController extends Controller {

  public Result test(){

    UserMaster UserMaster = UserMaster.find.byId(1L);

    return ok(test.render(teststring));

  }
}