mybatis plus 3.3.0中iservice中的getBaseMapper怎么映射
时间: 2024-02-09 08:11:26 浏览: 25
在 Mybatis Plus 3.3.0 中,IService 接口中的 getBaseMapper 方法的映射方式与之前的版本有所不同。在 3.3.0 中,IService 接口中的 getBaseMapper 方法默认是通过泛型获取对应的 BaseMapper 对象。
例如,假设有一个 User 实体类和对应的 UserMapper 接口,代码如下:
```
public interface UserMapper extends BaseMapper<User> {
// other methods
}
```
这里的 UserMapper 继承了 BaseMapper 接口,并且指定了泛型类型为 User。那么,在 IService 接口的实现类中,可以通过使用 @Autowired 或者 @Resource 注解将 UserMapper 对象注入进来,例如:
```
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
// other methods
}
```
在上面的示例中,UserServiceImpl 类继承了 ServiceImpl 类,该类实现了 IService 接口,同时指定了泛型类型为 UserMapper 和 User,这样在 UserServiceImpl 类中就可以使用 UserMapper 对象进行数据库操作。同时,IService 接口中的 getBaseMapper 方法也就被映射为了 UserMapper 对象。