feat: add UpdateChain.of(entity) method

This commit is contained in:
开源海哥 2023-07-26 10:32:55 +08:00
parent 03579122f3
commit d67ef64c6c

View File

@ -35,6 +35,7 @@ import java.lang.reflect.Type;
* @author michale
* @since 2023-07-25
*/
@SuppressWarnings("unchecked")
public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
private final BaseMapper<T> baseMapper;
@ -46,12 +47,27 @@ public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
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) {
this.baseMapper = baseMapper;
this.entity = createEntity(ClassUtil.getUsefulClass(baseMapper.getClass()));
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) {
Type type = mapperClass.getGenericInterfaces()[0];
if (type instanceof ParameterizedType) {