这个错误是由于在使用MyBatis-Plus的ServiceImpl类时,出现了多个与baseMapper属性匹配的bean。 解决这个问题的方法有两种:

  1. 使用@Primary注解标记一个bean作为主要的bean。在多个bean中,选择其中一个作为主要的bean,可以解决这个问题。在你的多个mapper接口实现中,给其中一个添加@Primary注解。

  2. 使用@Qualifier注解指定使用哪个bean。在你的ServiceImpl类中,使用@Qualifier注解指定要使用的bean。可以根据bean的名称或ID来指定。

例如,如果有两个mapper接口实现类分别命名为mapperA和mapperB,你可以在ServiceImpl类中使用@Qualifier注解来指定使用哪个bean,如下所示:

@Service
public class YourServiceImpl extends ServiceImpl<YourMapper, YourEntity> {

    @Autowired
    public YourServiceImpl(@Qualifier("mapperA") YourMapper yourMapper) {
        this.baseMapper = yourMapper;
    }
}

这样就可以明确指定要使用的bean,解决这个错误。记得根据你实际的情况修改上面的代码

Field baseMapper in combaomidoumybatisplusserviceimplServiceImpl required a single bean but 2 were found 。mybatis继承mapper接口扩展多层dao接口报错

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

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