我只想检索virtualfile等于我的virtualfile_id的记录(使用Ebean保留)

http://localhost:9000/transactionRecords路线上,我有一些记录:

[{"id":1,"virtualfile":"1","record_type":"D","transaction_type":"MA","card_number":"0000122000200123456","expiry_date":"0000"},
{"id":2,"virtualfile":"1","record_type":"D","transaction_type":"MA","card_number":"0000122000200123456","expiry_date":"0000"},
{"id":3,"virtualfile":"1","record_type":"D","transaction_type":"MA","card_number":"0000122000200123456","expiry_date":"0000"},
{"id":4,"virtualfile":"1","record_type":"D","transaction_type":"MA","card_number":"0000122000200123456","expiry_date":"0000"},
{"id":5,"virtualfile":"1","record_type":"D","transaction_type":"MA","card_number":"0000122000200123456","expiry_date":"0000"}]

我到的路线获取他们:
GET     /generator/:id             controllers.Application.generateFile(id: String)

我的控制器方法来获取它们:
public Result generateFile(String virtualfile_id) {
    List<TransactionRecord> transactionRecords = TransactionRecord.find.where()
            .ilike("virtualfile", "1") //set to "1" for testing
            .orderBy("id asc")
            .findPagedList(1, 25)
            .getList();
    return ok(toJson(transactionRecords));
}

*根据https://www.playframework.com/documentation/2.4.x/JavaEbean的建议获取列表的方法

还有我的TransactionRecord.class
@Entity
public class TransactionRecord extends Model {

  @Id
  Long id;
  String virtualfile;
  String record_type;
  String transaction_type;
  String card_number;
  String expiry_date;

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

  public TransactionRecord(String virtualfile, String transaction_type, String card_number, String expiry_date) {
      this.virtualfile = virtualfile;
      this.record_type = "D";
      this.transaction_type = transaction_type;
      this.card_number = card_number;
      this.expiry_date = expiry_date;
  }

  getters & setters

}

但是我在http://localhost:9000/generator/1路线上的输出为空:(:

java - 在Play Framework中使用WHERE子句返回List &lt;Type&gt;-LMLPHP

编辑:

如果我仅将.iLike更改为.eq,则不会发生任何事情。

.ilike更改为.eq并删除.findPagedList的结果:

java - 在Play Framework中使用WHERE子句返回List &lt;Type&gt;-LMLPHP

最佳答案

您有5条记录,但是在对getPagedList的调用中,您跳过了前25条记录。因此,您将跳过所有记录。

Ebean documentation

参数:
pageIndex-页面的基于从零开始的索引。
pageSize-每页要返回的bean数。

因此,最初需要将findPagedList 1的参数更改为0

public Result generateFile(String virtualfile_id) {
    List<TransactionRecord> transactionRecords = TransactionRecord.find.where()
        .ilike("virtualfile", "1") //set to "1" for testing
        .orderBy("id asc")
        .findPagedList(0, 25)
        .getList();
    return ok(toJson(transactionRecords));
}

为了正确地支持客户端(或至少来自控制器层)的分页,您需要更改的签名。
public Result generateFile(String virtualfile_id)


public Result generateFile(String virtualfile_id, int page)

并使用page参数作为findPagedList的参数。
public Result generateFile(String virtualfile_id,
                           int page) {
    List<TransactionRecord> transactionRecords = TransactionRecord.find.where()
        .ilike("virtualfile", "1") //set to "1" for testing
        .order().asc("id")
        .findPagedList(page, 25)
        .getList();
    return ok(toJson(transactionRecords));
}

07-24 09:33