mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
feat: add UpdateChain.of(entity) method
This commit is contained in:
parent
03579122f3
commit
d67ef64c6c
@ -35,6 +35,7 @@ import java.lang.reflect.Type;
|
|||||||
* @author michale
|
* @author michale
|
||||||
* @since 2023-07-25
|
* @since 2023-07-25
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
|
public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
|
||||||
|
|
||||||
private final BaseMapper<T> baseMapper;
|
private final BaseMapper<T> baseMapper;
|
||||||
@ -46,12 +47,27 @@ public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
|
|||||||
return new UpdateChain<>(baseMapper);
|
return new UpdateChain<>(baseMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> UpdateChain<T> of(T entityObject) {
|
||||||
|
Class<T> entityClass = (Class<T>) ClassUtil.getUsefulClass(entityObject.getClass());
|
||||||
|
BaseMapper<T> baseMapper = Mappers.ofEntityClass(entityClass);
|
||||||
|
return new UpdateChain<>(baseMapper, entityObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public UpdateChain(BaseMapper<T> baseMapper) {
|
public UpdateChain(BaseMapper<T> baseMapper) {
|
||||||
this.baseMapper = baseMapper;
|
this.baseMapper = baseMapper;
|
||||||
this.entity = createEntity(ClassUtil.getUsefulClass(baseMapper.getClass()));
|
this.entity = createEntity(ClassUtil.getUsefulClass(baseMapper.getClass()));
|
||||||
this.entityWrapper = (UpdateWrapper) entity;
|
this.entityWrapper = (UpdateWrapper) entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public UpdateChain(BaseMapper<T> baseMapper, T entityObject) {
|
||||||
|
this.baseMapper = baseMapper;
|
||||||
|
entityObject = (T) UpdateWrapper.of(entityObject);
|
||||||
|
this.entity = entityObject;
|
||||||
|
this.entityWrapper = (UpdateWrapper) entityObject;
|
||||||
|
}
|
||||||
|
|
||||||
private T createEntity(Class<?> mapperClass) {
|
private T createEntity(Class<?> mapperClass) {
|
||||||
Type type = mapperClass.getGenericInterfaces()[0];
|
Type type = mapperClass.getGenericInterfaces()[0];
|
||||||
if (type instanceof ParameterizedType) {
|
if (type instanceof ParameterizedType) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user