2014-11-14 3 views
4

"첫 번째"방법과 같이 play.db.ebean.Model.Finder를 사용하여 데이터베이스에서 테이블의 첫 번째 레코드를 가져 오는 것이 어떻게 가능합니까? 해당 SQL은 다음과 같습니다Play & Ebean - 첫 번째 레코드 받기

SELECT * FROM my_table LIMIT 1; 

답변

12

이의이

public static Finder<Long,Student> find = new Finder(Long.class, Student.class); 

이 1 개

public static Student getStudent() 
{ 
    // Use setMaxRows(limit_by) 
    return find.setMaxRows(1).findUnique(); 
} 
+0

감사에 의해 학생의 제한을 검색 할 것이다 모델 Student

@Entity public class Student{ @Id public int id; public String name; } 

모델 찾기를 가정 해 보자. ebean을 처음 접했을 때 setMaxRows (1) .findList(). get (0)으로 쓰면 findUnique()가 더 효율적으로 보입니다. 왜 그들은 단지 findFirst()를 제공하지 않는지 확실하지 않습니다. –

관련 문제