gpt4 book ai didi

java - play框架2.4中未找到bean方法的 'byId()'和 'find'

转载 作者:行者123 更新时间:2023-12-01 09:29:47 26 4
gpt4 key购买 nike

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

程序返回“找不到符号 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) 但它也不起作用。请你帮我一下好吗?

最佳答案

您的型号:

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>(){};


}

在你的 Controller 中:

public class TestController extends Controller {

public Result test(){

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

return ok(test.render(teststring));

}
}

关于java - play框架2.4中未找到bean方法的 'byId()'和 'find',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39529896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com