目前我的代码是
int customerId = 4;
String sql = "select id from coupon as A join coupon_use "
+ "as B on A.id=B.coupon where B.customer=" + customerId
+ " and B.like_at is not null;";
RawSql rawSql = RawSqlBuilder.parse(sql).create();
Query<Coupon> query = Ebean.find(Coupon.class);
query.setRawSql(rawSql);
List<Coupon> list = query.findList();
return ok(Json.toJson(list));
如何避免编写手动 SQL 查询,但仍然让 ORM 生成该查询并向我返回结果?
最佳答案
Ebean 将根据 where 和 order by 等中使用的路径/属性添加适当的联接。
其中 couponUse.likeAt 不为空。
假设 couponUse.likeAt 是正确的表达式路径...Ebean 将添加一个连接来自动支持表达式。
关于java - 如何用Ebean Java ORM语言编写join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765218/