Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加condition方法,简化手动指定condition的重复工作 #6480

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.baomidou.mybatisplus.core.conditions.interfaces;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.io.Serializable;
import java.util.Map;
import java.util.function.BiPredicate;
Expand Down Expand Up @@ -104,6 +106,18 @@ default Children eq(R column, Object val) {
return eq(true, column, val);
}

/**
* 条件eq,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionEq(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return eq(condition, column, val);
}

/**
* 等于 =
*
Expand All @@ -125,6 +139,18 @@ default Children ne(R column, Object val) {
return ne(true, column, val);
}

/**
* 条件ne,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionNe(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return ne(condition, column, val);
}

/**
* 不等于 <>
*
Expand All @@ -146,6 +172,18 @@ default Children gt(R column, Object val) {
return gt(true, column, val);
}

/**
* 条件gt,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionGt(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return gt(condition, column, val);
}

/**
* 大于 >
*
Expand All @@ -167,6 +205,17 @@ default Children ge(R column, Object val) {
return ge(true, column, val);
}

/**
* 条件ge,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionGe(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return ge(condition, column, val);
}
/**
* 大于等于 >=
*
Expand All @@ -188,6 +237,18 @@ default Children lt(R column, Object val) {
return lt(true, column, val);
}

/**
* 条件lt,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionLt(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return lt(condition, column, val);
}

/**
* 小于 <
*
Expand All @@ -209,6 +270,18 @@ default Children le(R column, Object val) {
return le(true, column, val);
}

/**
* 条件le,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionLe(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return le(condition, column, val);
}

/**
* 小于等于 <=
*
Expand Down Expand Up @@ -277,6 +350,18 @@ default Children like(R column, Object val) {
return like(true, column, val);
}

/**
* 条件like,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionLike(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return like(condition, column, val);
}

/**
* LIKE '%值%'
*
Expand All @@ -298,6 +383,18 @@ default Children notLike(R column, Object val) {
return notLike(true, column, val);
}

/**
* 条件notLike,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionNotLike(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return notLike(condition, column, val);
}

/**
* NOT LIKE '%值%'
*
Expand All @@ -319,6 +416,18 @@ default Children notLikeLeft(R column, Object val) {
return notLikeLeft(true, column, val);
}

/**
* 条件notLikeLeft,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionNotLikeLeft(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return notLikeLeft(condition, column, val);
}

/**
* NOT LIKE '%值'
*
Expand All @@ -340,6 +449,18 @@ default Children notLikeRight(R column, Object val) {
return notLikeRight(true, column, val);
}

/**
* 条件notLikeRight,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionNotLikeRight(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return notLikeRight(condition, column, val);
}

/**
* NOT LIKE '值%'
*
Expand All @@ -361,6 +482,18 @@ default Children likeLeft(R column, Object val) {
return likeLeft(true, column, val);
}

/**
* 条件leftLike,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionLikeLeft(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return likeLeft(condition, column, val);
}

/**
* LIKE '%值'
*
Expand All @@ -382,6 +515,18 @@ default Children likeRight(R column, Object val) {
return likeRight(true, column, val);
}

/**
* 条件leftRight,默认使用StringUtils.checkValNotNull(val)作为condition
*
* @param column 字段
* @param val 值
* @return children
*/
default Children conditionLikeRight(R column, Object val) {
boolean condition = StringUtils.checkValNotNull(val);
return likeRight(condition, column, val);
}

/**
* LIKE '值%'
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.baomidou.mybatisplus.core.conditions.interfaces;

import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;

import java.io.Serializable;
Expand Down Expand Up @@ -88,6 +89,18 @@ default Children in(R column, Collection<?> coll) {
return in(true, column, coll);
}

/**
* 条件in,默认使用CollectionUtils.isNotEmpty(coll)作为condition
*
* @param column 字段
* @param coll 数据集合
* @return children
*/
default Children conditionIn(R column, Collection<?> coll) {
boolean condition = CollectionUtils.isNotEmpty(coll);
return in(condition, column, coll);
}

/**
* 字段 IN (value.get(0), value.get(1), ...)
* <p>例: in(true, "id", Arrays.asList(1, 2, 3, 4, 5))</p>
Expand Down Expand Up @@ -117,6 +130,18 @@ default Children in(R column, Object... values) {
return in(true, column, values);
}

/**
* 条件in,默认使用ArrayUtils.isNotEmpty(values)作为condition
*
* @param column 字段
* @param values 数据数组
* @return children
*/
default Children conditionIn(R column, Object... values) {
boolean condition = ArrayUtils.isNotEmpty(values);
return in(condition, column, values);
}

/**
* 字段 IN (v0, v1, ...)
* <p>例: in(true, "id", 1, 2, 3, 4, 5)</p>
Expand Down Expand Up @@ -146,6 +171,17 @@ default Children notIn(R column, Collection<?> coll) {
return notIn(true, column, coll);
}

/**
* 条件in,默认使用CollectionUtils.isNotEmpty(values)作为condition
*
* @param column 字段
* @param coll coll
* @return children
*/
default Children conditionNotIn(R column, Collection<?> coll) {
boolean condition = CollectionUtils.isNotEmpty(coll);
return notIn(condition, column, coll);
}
/**
* 字段 NOT IN (value.get(0), value.get(1), ...)
* <p>例: notIn(true, "id", Arrays.asList(1, 2, 3, 4, 5))</p>
Expand Down Expand Up @@ -175,6 +211,18 @@ default Children notIn(R column, Object... values) {
return notIn(true, column, values);
}

/**
* 条件notIn,默认使用ArrayUtils.isNotEmpty(values)作为condition
*
* @param column 字段
* @param values 数据数组
* @return children
*/
default Children conditionNotIn(R column, Object... values) {
boolean condition = ArrayUtils.isNotEmpty(values);
return notIn(condition, column, values);
}

/**
* 字段 NOT IN (v0, v1, ...)
* <p>例: notIn(true, "id", 1, 2, 3, 4, 5)</p>
Expand Down
Loading