mybatis

作者: 我是三人禾 | 来源:发表于2020-10-30 23:02 被阅读0次

    一对多的某个情况

    <?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.qin.repository.ClassesRepository">
        <resultMap id="classesMap" type="com.qin.entity.Classes">
            <id column="id" property="id"/>
            <result column="classname" property="className"/>
            <collection property="students" ofType="com.qin.entity.Student" column="s">
                <id column="sid" property="id"/>
                <result column="sname" property="name"/>
                <result column="sage" property="age"/>
            </collection>
        </resultMap>
        <select id="findById" parameterType="int" resultMap="classesMap">
            select c.*,s.id as sid,s.name as sname,s.age as sage
                    from t_class c
                      join t_student s
                     on c.id =2 and s.cid =2;
        </select>
    </mapper>
    

    相关文章

      网友评论

          本文标题:mybatis

          本文链接:https://www.haomeiwen.com/subject/zwujvktx.html