4
如何使用play.db.ebean.Model.Finder獲取數據庫表中的第一條記錄,如同第一個方法一樣。對應的SQL將是:Play&Ebean - 獲得第一筆記錄
SELECT * FROM my_table LIMIT 1;
如何使用play.db.ebean.Model.Finder獲取數據庫表中的第一條記錄,如同第一個方法一樣。對應的SQL將是:Play&Ebean - 獲得第一筆記錄
SELECT * FROM my_table LIMIT 1;
假設模型Student
@Entity
public class Student{
@Id
public int id;
public String name;
}
型號取景器會
public static Finder<Long,Student> find = new Finder(Long.class, Student.class);
public static Student getStudent()
{
// Use setMaxRows(limit_by)
return find.setMaxRows(1).findUnique();
}
感謝這個檢索學生的限制。新的ebean,並寫它setMaxRows(1).findList()。get(0),findUnique()似乎會更有效率。不知道他們爲什麼不僅僅提供findFirst()。 – 2015-11-17 18:47:20