mysql如何用Java ORM语言编写join
目前我的代码是
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生成该查询并返回结果
# 1 楼答案
Ebean将根据where和order by等中使用的路径/属性添加适当的联接
库波努斯在哪里。likeAt不是空的
假设是库波努斯。likeAt是正确的表达方式。。。Ebean将自动添加一个连接以支持表达式