MyBatis-Plus does not support multiple inheritance for mapper DAO interfaces. However, you can achieve similar functionality by using MyBatis-Plus's built-in features such as QueryWrapper, UpdateWrapper, and LambdaQueryWrapper.

Here's an example of how you can implement multiple inheritance-like behavior using MyBatis-Plus:

  1. Define the base mapper interface with common CRUD operations:
public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T> {
    // Additional common methods go here
}
  1. Create other mapper interfaces by extending the base mapper interface and adding additional methods as needed:
public interface UserMapper extends BaseMapper<User> {
    // User-specific methods go here
}

public interface OrderMapper extends BaseMapper<Order> {
    // Order-specific methods go here
}
  1. Implement the mapper interfaces using MyBatis-Plus's QueryWrapper, UpdateWrapper, and LambdaQueryWrapper:
@Repository
public class UserMapperImpl extends BaseMapperImpl<User> implements UserMapper {
    // User-specific methods implementation goes here
}

@Repository
public class OrderMapperImpl extends BaseMapperImpl<Order> implements OrderMapper {
    // Order-specific methods implementation goes here
}

public class BaseMapperImpl<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapperWrapper<T> implements BaseMapper<T> {
    // Additional common methods implementation goes here
}

By following this approach, you can achieve the behavior of multiple inheritance for mapper DAO interfaces in MyBatis-Plus

mybatisplus mapper dao层多继承实现

原文地址: http://www.cveoy.top/t/topic/i1Q3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录