org.iartisan.runtime.support.BaseManagementServiceSupport Maven / Gradle / Ivy
package org.iartisan.runtime.support;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.iartisan.runtime.jdbc.MybatisBaseMapper;
import org.iartisan.runtime.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
/**
*
* management service support
*
* @author King
* @since 2017/6/22
*/
public class BaseManagementServiceSupport, T> implements IBaseManagementService {
@Autowired
protected M baseMapper;
private Class doClass;
public Class getDoClass() {
if (doClass == null) {
Class> result = (Class>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
doClass = (Class) ((ParameterizedType) result.getGenericInterfaces()[0]).getActualTypeArguments()[0];
}
return doClass;
}
@Override
public void updateData(T t) {
baseMapper.updateById(BeanUtil.copyBean(t, getDoClass()));
}
@Override
public void deleteData(T t) {
Class dbDel = BeanUtil.copyBean(t, getDoClass());
Wrapper wrapper = new EntityWrapper(dbDel);
baseMapper.delete(wrapper);
}
@Override
public void saveData(T t) {
baseMapper.insert(BeanUtil.copyBean(t, getDoClass()));
}
@Override
public void deleteDataById(Serializable id) {
baseMapper.deleteById(id);
}
}