@Mapper报红

检查pom.xml,导入 org.mybatis.spring.boot 依赖:

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.3</version>
        </dependency>

刷新maven

解决:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你在使用 `@Mapper` 注解时出现了报红的情况,可能是因为你的 IDE 未正确识别该注解所在的包。你可以尝试以下方法解决: 1. 确认已经引入了正确的依赖。如果你使用的是 MyBatis,你需要引入 MyBatis 的依赖,如: ```xml <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.x.x</version> </dependency> <!-- MyBatis-Spring --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.x.x</version> </dependency> <!-- Mapper --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-3-mapper</artifactId> <version>1.4.0</version> </dependency> ``` 2. 确认你的 IDE 已正确识别了 `@MapperScan` 注解所在的包路径。如果你使用的是 Spring Boot,你可以在启动类上添加 `@MapperScan("包路径")` 注解,如: ```java @SpringBootApplication @MapperScan("com.example.mapper") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` 这样,就可以让 Spring Boot 在启动时自动扫描指定包下的 Mapper 接口,并生成相应的实现类。 3. 确认你的 IDE 已正确识别了 `@Mapper` 注解所在的包路径或类路径。如果你使用的是 IntelliJ IDEA,你可以在项目的 `pom.xml` 文件中配置 `org.jetbrains:annotations` 依赖,如: ```xml <dependency> <groupId>org.jetbrains</groupId> <artifactId>annotations</artifactId> <version>20.1.0</version> <scope>provided</scope> </dependency> ``` 然后,在 `@Mapper` 注解上方添加 `@org.jetbrains.annotations.Mapper` 注解,这样就可以让 IntelliJ IDEA 正确识别 `@Mapper` 注解了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值