关于EntityWrapper的in用法
作者:luo_yu_1106
这篇文章主要介绍了关于EntityWrapper的in用法详解,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
EntityWrapper的in用法
EntityWrapper<UserLife> wrapper = new EntityWrapper<>();
wrapper.eq("is_valid", 1);
wrapper.in("life_name", "ge,edu,career");
List<UserLife> userLabelList = userLabelService.selectList(wrapper);in的第二个参数可以是字符串也可以是list但是注意字符串中","间不能有空格,不然会查出来的语句就是这样的

mybatis-plus EntityWrapper in
环境:
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)
** /以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
