com.magic80.springBootCommon.service.BaseService Maven / Gradle / Ivy
package com.magic80.springBootCommon.service;
import com.magic80.springBootCommon.dao.BaseDao;
import com.magic80.springBootCommon.model.BaseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;
import java.lang.reflect.ParameterizedType;
import java.util.List;
public abstract class BaseService {
@Autowired
protected D dao;
private Class entityClass;
public BaseService() {
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
entityClass = (Class) pt.getActualTypeArguments()[1];
}
public void insert(E entity) {
dao.insertSelective(entity);
}
public void updateById(E entity) {
dao.updateByPrimaryKeySelective(entity);
}
public void deleteById(Integer id) {
dao.deleteByPrimaryKey(id);
}
public E findById(Integer id) {
return (E) dao.selectByPrimaryKey(id);
}
public List findAll() {
Example example = new Example(entityClass);
example.setOrderByClause("id desc");
return dao.selectByExample(example);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy