在啟動類上加引入的服務中的mapper路徑,在配置文件中將mapperLocations的值改為classpath*:mapper/.xml:
@MapperScan(basePackages = {"com.ruoyi..mapper"}) 和 mapperLocations: classpath*:mapper/*.xml 是 MyBatis 在 Spring Boot 中配置 Mapper 掃描和 XML 文件加載的兩種不同方式。
@MapperScan(basePackages = {“com.ruoyi.*.mapper”}):
這是通過在 Spring Boot 應用程序的配置類上使用 @MapperScan 注解來指定需要掃描的 Mapper 接口所在的包路徑。通常情況下,你會在啟動類或者配置類上使用這個注解,并指定需要掃描的包路徑,以便能夠將這些 Mapper 接口注冊為 Spring 的 Bean。
mapperLocations: classpath*:mapper/.xml:
這是在 application.yml 或 application.properties 配置文件中指定 MyBatis Mapper XML 文件的位置。在這個例子中,classpath:mapper/*.xml 表示 MyBatis 會在類路徑下的 mapper 目錄中查找所有以 .xml 結尾的文件作為 Mapper 文件,用于 SQL 映射。
這兩種配置方式分別用于掃描 Mapper 接口并注冊為 Bean,以及指定 Mapper XML 文件的位置。通過這些配置,你可以方便地讓 MyBatis 與 Spring Boot 集成,并正確地加載 Mapper 接口和 XML 文件,從而實現數據操作功能。