mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
update和delete添加链式调用
This commit is contained in:
parent
fde21a04dd
commit
34e4acdc6a
@ -9,6 +9,7 @@ import com.github.yulichang.toolkit.Asserts;
|
|||||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
import com.github.yulichang.toolkit.TableList;
|
import com.github.yulichang.toolkit.TableList;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.DeleteChain;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -21,7 +22,7 @@ import java.util.stream.Collectors;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.5
|
* @since 1.4.5
|
||||||
*/
|
*/
|
||||||
public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoinWrapper<T>> {
|
public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoinWrapper<T>> implements DeleteChain<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除表
|
* 删除表
|
||||||
|
@ -12,6 +12,7 @@ import com.github.yulichang.toolkit.LambdaUtils;
|
|||||||
import com.github.yulichang.toolkit.TableHelper;
|
import com.github.yulichang.toolkit.TableHelper;
|
||||||
import com.github.yulichang.toolkit.TableList;
|
import com.github.yulichang.toolkit.TableList;
|
||||||
import com.github.yulichang.wrapper.interfaces.Update;
|
import com.github.yulichang.wrapper.interfaces.Update;
|
||||||
|
import com.github.yulichang.wrapper.interfaces.UpdateChain;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoinWrapper<T>>
|
public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoinWrapper<T>>
|
||||||
implements Update<UpdateJoinWrapper<T>> {
|
implements Update<UpdateJoinWrapper<T>>, UpdateChain<T> {
|
||||||
/**
|
/**
|
||||||
* SQL 更新字段内容,例如:name='1', age=2
|
* SQL 更新字段内容,例如:name='1', age=2
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||||
|
import com.github.yulichang.toolkit.SqlHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错<br />
|
||||||
|
* new DeleteJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.delete(User.class)<br />
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.10
|
||||||
|
*/
|
||||||
|
public interface DeleteChain<T> {
|
||||||
|
|
||||||
|
Class<T> getEntityClass();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错 <br />
|
||||||
|
* new DeleteJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.delete(User.class)<br />
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unused", "unchecked"})
|
||||||
|
default int deleteJoin() {
|
||||||
|
return SqlHelper.exec(getEntityClass(), mapper -> {
|
||||||
|
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
|
||||||
|
return ((MPJBaseMapper<T>) mapper).deleteJoin((MPJBaseJoin<T>) this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||||
|
import com.github.yulichang.toolkit.SqlHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错<br />
|
||||||
|
* new UpdateJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.update(User.class)<br />
|
||||||
|
*
|
||||||
|
* @author yulichang
|
||||||
|
* @since 1.4.10
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
|
public interface UpdateChain<T> {
|
||||||
|
|
||||||
|
Class<T> getEntityClass();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错 <br />
|
||||||
|
* new UpdateJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.update(User.class)<br />
|
||||||
|
*/
|
||||||
|
default int update() {
|
||||||
|
return SqlHelper.exec(getEntityClass(), mapper -> {
|
||||||
|
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
|
||||||
|
return ((MPJBaseMapper<T>) mapper).updateJoin(null, (MPJBaseJoin<T>) this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错 <br />
|
||||||
|
* new UpdateJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.update(User.class)<br />
|
||||||
|
*/
|
||||||
|
default int update(T entity) {
|
||||||
|
return SqlHelper.exec(getEntityClass(), mapper -> {
|
||||||
|
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
|
||||||
|
return ((MPJBaseMapper<T>) mapper).updateJoin(entity, (MPJBaseJoin<T>) this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错 <br />
|
||||||
|
* new UpdateJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.update(User.class)<br />
|
||||||
|
*/
|
||||||
|
default int updateAndNull() {
|
||||||
|
return SqlHelper.exec(getEntityClass(), mapper -> {
|
||||||
|
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
|
||||||
|
return ((MPJBaseMapper<T>) mapper).updateJoinAndNull(null, (MPJBaseJoin<T>) this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链式调用
|
||||||
|
* <p>
|
||||||
|
* 构造方法必须传 class 或 entity 否则会报错 <br />
|
||||||
|
* new UpdateJoinWrapper(User.class)<br />
|
||||||
|
* JoinWrappers.update(User.class)<br />
|
||||||
|
*/
|
||||||
|
default int updateAndNull(T entity) {
|
||||||
|
return SqlHelper.exec(getEntityClass(), mapper -> {
|
||||||
|
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName());
|
||||||
|
return ((MPJBaseMapper<T>) mapper).updateJoinAndNull(entity, (MPJBaseJoin<T>) this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user