MyBatis-XML映射文件

1、Mybatis中 # 取参和 $ 取参的区别

  $会直接替换,而#会使用?先进行预处理

 

2、ResultMap的作用

  实体类属性和数据库列名不匹配的时候(比如,数据库采用经典命名法,java 使用驼峰命名法的时候)

    <resultMap id="basicMap" type="cn.wjcoder.domain.Employee">
        <!--        设置数据库id 的对应字段-->
        <id property="id" column="id"></id>
        <result property="empDetail" column="emp_detail"></result>
        <result property="name" column="name"></result>
    </resultMap>
 
    <select id="selectEmpById" resultMap="basicMap">
        select * from employee where id = #{id}
    </select>

 3、association以及collection的区别

  association: 一对一关联(has one)
  collection:一对多关联(has many)

  注意,只有在做select查询时才会用到这两个标签;

 

参考文章

【1】https://blog.csdn.net/m0_71212413/article/details/129128550

posted @ 2023-10-10 11:50  先娶国王后取经  阅读(2)  评论(0编辑  收藏  举报