grain-Edu-Note part09 向mapper接口添加自定义功能,并将xml打包

    科技2024-01-07  93

    写mapper

    <?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.ezerbel.grain.service.edu.mapper.SubjectMapper"> <select id="selectNestedListByParentId" resultMap="nestedSubject"> select id,title,sort from edu_subject where parent_id = #{parentId} </select> <resultMap id="nestedSubject" type="com.ezerbel.grain.service.edu.entity.vo.SubjectVo"> <id property="id" column="id"/> <result property="title" column="title"/> <result property="sort" column="sort"/> <!-- select语句传入参数为cloumn对应的id --> <collection property="children" column="id" select="selectNestedListByParentId" ofType="com.ezerbel.grain.service.edu.entity.vo.SubjectVo"/> </resultMap> </mapper>

    默认源码包内的xml不会被打包

    maven添加源码包内xml打包配置

    <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <!-- 不过滤掉 --> <filtering>false</filtering> </resource> </resources> </build>

    yml 配置中指明mapper文件的所在位置

    #mybatis日志 mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: classpath:com/ezerbel/grain/service/edu/mapper/xml/*.xml
    Processed: 0.013, SQL: 8