condition 的使用小技巧

Condition condition = new Condition(Product.class);
Example.Criteria criteria = condition.createCriteria();
for (Map.Entry<String, Object> entry : params.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    if (StringUtils.isEmpty(value)) {
        continue;
    }
    switch (key){
        case "productCategoryIds":
            criteria.andCondition("product_category_id in ("+value.toString()+")");
            break;
        default:
            criteria.andEqualTo(key, params.get(key));
            break;
    }

}

//criteria.andCondition 中的sql语句应该使用表中的实际字段名,与实体类的属性不一样。

猜你喜欢

转载自blog.csdn.net/qq_34638435/article/details/80689659