【发布时间】:2014-08-24 18:13:00
【问题描述】:
首先请看下面的代码。我以前使用过各种 ORM(Hibernate、DataMapper),但在 ORMLite 中我面临一个非常棘手的问题。查看我的代码,我将设置 where 条件子句。根据 ormlite api and() 方法应该放在两个 where 子句的中间。在我的例子中,还有一个额外的 and() 方法在 ORMLite 中是不允许的。
那么在这种情况下最好的解决方案是什么?
if(filter.getInstituionId() != null)
builder.where().eq(BuyPostItem.FIELD_INSTITUTION_ID, filter.getInstituionId()).and();
if(filter.getBookCategoryId() != null)
builder.where().eq(BuyPostItem.FIELD_CATEGORY_ID, filter.getBookCategoryId()).and();
if(filter.getMinPrice() != null)
builder.where().ge(BuyPostItem.FIELD_EXPECTED_PRICE, filter.getMinPrice()).and();
if(filter.getMaxPrice() != null)
builder.where().le(BuyPostItem.FIELD_EXPECTED_PRICE, filter.getMaxPrice()).and();
【问题讨论】:
标签: android sql hibernate orm ormlite