mybatis-plus EntityWrapper in
环境:springBoot+mybatis源码:/*** <p>* IN 条件语句,目前适配mysql及oracle* </p>** @param column 字段名称* @param value匹配值 集合* @return this*/public Wrapper<T> in(String column, Collection<?&
·
环境:springBoot+mybatis
源码:
/**
* <p>
* IN 条件语句,目前适配mysql及oracle
* </p>
*
* @param column 字段名称
* @param value 匹配值 集合
* @return this
*/
public Wrapper<T> in(String column, Collection<?> value) {
return in(true, column, value);
}
/**
* <p>
* IN 条件语句,目前适配mysql及oracle
* </p>
*
* @param condition 拼接的前置条件
* @param column 字段名称
* @param value 匹配值 集合
* @return this
*/
public Wrapper<T> in(boolean condition, String column, Collection<?> value) {
if (condition && CollectionUtils.isNotEmpty(value)) {
sql.WHERE(formatSql(inExpression(column, value, false), value.toArray()));
}
return this;
}
如果condition不传,等同于:condition: true;
如果传入的value不为空,相当于改 in 查询语句为拼接;
举个例子:
//代码
@Override
public List<User> selectByCaseIdSet(Set<String> idSet) {
EntityWrapper<User> wrapper = new EntityWrapper<>();
wrapper.in(!CollectionUtils.isEmpty(idSet), "id", idSet);
return this.selectList(wrapper);
}
/**
* 如果idSet 为空,sql: select * from user
* 如果idSet 不为空, sql: select * from user where id in (idSet)
** /
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)