java-在Play Framework中使用WHERE子句返回列表
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-在Play Framework中使用WHERE子句返回列表,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3009字,纯文字阅读大概需要5分钟。
内容图文
![java-在Play Framework中使用WHERE子句返回列表](/upload/InfoBanner/zyjiaocheng/663/453007a6ee2b46b7a02613f6833f42ad.jpg)
我只想检索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上的输出为空:(:
编辑:
如果仅将.iLike更改为.eq,则什么也不会发生.
将.ilike更改为.eq并删除.findPagedList的结果:
解决方法:
您有五个记录,但是在调用getPagedList时,您跳过了前25个记录.因此,您将跳过所有记录.
Parameters:
pageIndex – The zero based index of the page.
pageSize – The number of beans to return per page.
因此,最初需要将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)
并使用该页面参数作为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));
}
内容总结
以上是互联网集市为您收集整理的java-在Play Framework中使用WHERE子句返回列表全部内容,希望文章能够帮你解决java-在Play Framework中使用WHERE子句返回列表所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。