MyBatis-Plus部分方法封装

kyaa111 2年前 ⋅ 857 阅读

在此仅记录一种思路

public interface SuperMapper<T> extends BaseMapper<T> {

    default List<T> idNotInList(List<?> idList) {
        return selectList(new QueryWrapper<T>().notIn("id", idList));
    }
}
public interface UserMapper extends SupperMapper<User> {

}

service基类

public class SupperServiceImpl<M extends SupperMapper<T>, T> extends ServiceImpl<M, T> {


}
public interface UserService extends IService<User> {
    List<User> idNotInList(List<Integer> idList);
}
@Service
public class UserServiceImpl extends SupperServiceImpl<UserMapper, User> implements UserService {


    @Override
    public List<User> idNotInList(List<Integer> idList) {
        //在SupperMapper中定义的默认方法, 可以在此直接使用
        return baseMapper.idNotInList(idList);
    }
}