• mybatis中collection和association的作用以及用法


    deptDaoMapper.xml
    部门对应员工(1对多的关系)

    <resultMap type="com.hw.entity.Dept" id="deptinfo"><!-- 如果不用resultMap则不写 -->
            <result column="did" property="did" />
            <result column="dname" property="dname" />
            <!-- mybatis中 1方配置多方 -->
            <collection property="per" ofType="com.hw.entity.Person">
                <result column="pid" property="pid" />
                <result column="pname" property="pname" />
                <result column="psex" property="psex" />
                <result column="skilled" property="skilled" />
                <result column="degree" property="degree" />
                <result column="jobtime" property="jobtime" javaType="java.sql.Date" jdbcType="DATE" />
                <result column="resume" property="resume" />
                <result column="filepath" property="filepath" />
            </collection>
        </resultMap>
    

    javabean中的属性是集合set ,这时用collection

    
    

    personDaoMapper.xml
    员工对应部门(多对一的关系)

    <resultMap type="com.hw.entity.Person" id="personinfo"><!-- 如果不用resultMap则不写 -->
            <result column="pid" property="pid" />
            <result column="pname" property="pname" />
            <result column="psex" property="psex" />
            <result column="skilled" property="skilled" />
            <result column="degree" property="degree" />
            <result column="jobtime" property="jobtime" javaType="java.sql.Date"
                jdbcType="DATE" />
            <result column="resume" property="resume" />
            <result column="filepath" property="filepath" />
            <!--多对一的关系, property: 指的是属性的值, javaType:指的是属性的类型 -->
            <association property="dept" javaType="com.hw.entity.Dept">
                <result column="did" property="did" />
                <result column="dname" property="dname" />
            </association>
        </resultMap>
    

    javabean是类与类之间的关联,这时用association
    关联(Association)关系是类与类之间的联接,它使一个类知道另一个类的属性和方法。关联可以是双向的,也可以是单向的。在Java语言中,关联关系一般使用成员变量来实现。



    作者:愤怒的_菜鸟
    链接:https://www.jianshu.com/p/92efd20637ed
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    AS2 tween缓动
    flash 绑定 swc类文件
    jsfl自运行与被调运行
    一键清除fla文件中的TLF文本
    as 2的 Event.REMOVED_FROM_STAGE
    jsfl 添加代码
    jsfl 删除库指定内容
    文件上传待研究
    SpringMVC单文件上传、多文件上传、文件列表显示、文件下载
    shiro配置参考(二)可以和mybatis的配置放在一个文件中(不建议这样,可以拆分开来,注意相关配置即可)
  • 原文地址:https://www.cnblogs.com/yaowen/p/8882100.html
Copyright © 2020-2023  润新知