在 Spring Boot 中使用 MyBatis,可以通过注解方式或者 XML 文件方式来实现 Mapper 接口和 Mapper XML 的处理。

  1. 注解方式:

    • 创建一个 AppsDmMapper 接口,继承自 AppsMapper 接口。
    @Mapper
    public interface AppsDmMapper extends AppsMapper {
        // 可以在这里添加自定义的方法
    }
    
    • 在 @MapperScan 注解中扫描该接口所在的包,以将其注册为 Mapper 接口。
    @SpringBootApplication
    @MapperScan("com.example.mapper")
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    
    • 在需要使用 AppsDmMapper 的地方,通过 @Autowired 进行注入使用即可。
  2. XML 文件方式:

    • 创建一个 AppsDmMapper 接口,继承自 AppsMapper 接口。
    public interface AppsDmMapper extends AppsMapper {
        // 可以在这里添加自定义的方法
    }
    
    • 创建一个与 AppsDmMapper 对应的 XML 文件 AppsDmMapper.xml,并在其中编写 SQL 语句。
    <!-- AppsDmMapper.xml -->
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.example.mapper.AppsDmMapper">
        <!-- 可以在这里编写 SQL 语句 -->
    </mapper>
    
    • 在 application.properties 或 application.yml 中配置 MyBatis 的 XML 文件路径。
    # application.properties
    mybatis.mapper-locations=classpath*:com/example/mapper/*.xml
    
    # application.yml
    mybatis:
        mapper-locations: classpath*:com/example/mapper/*.xml
    
    • 在需要使用 AppsDmMapper 的地方,通过 @Autowired 进行注入使用即可。

以上是在 Spring Boot 中使用 MyBatis 的一种实现方式,具体的使用方式可以根据项目的需求进行调整。

springboot mybatis mapper interface AppsDmMapper extends AppsMapper 怎么实现mapperxml怎么处理