• MyBatis两张表字段名相同产生的问题


    MyBatis两张表字段名相同, 会导致bean属性都映射为第一个表的列,

    解决方法:

    通过设置别名的方式让其产生区别,如

    <select id="queryBySekillId" resultMap="successKilled">
     
            select
                sk.seckill_id  "seckill_id",
                sk.user_phone  "user_phone",
                sk.state  "state",
                sk.create_time  "create_time",
                s.seckill_id  "seckill_id",
                s.name  "name",
                s.number  "number",
                s.start_time  "start_time",
                s.end_time  "end_time",
                <strong>s.create_time  "screate_time"</strong>
            from success_killed sk
            inner join seckill s
            on sk.seckill_id = s.seckill_id
            where sk.seckill_id = #{seckill_id} ;
     
    </select>
    

      上 success_killed表和seckill表中有相同字段 create_time (id字段其实确实是相同的故在此忽略),通过将表seckill的create_time字段命名为screate_time用以区别。

    <resultMap type="Seckill" id="seckill">
            <id column="seckill_id"  property="seckill_id"/>
            <result column="name" property="name"/>
            <result column="number" property="number"/>
            <result column="start_time" property="start_time" />
            <result column="end_time"  property="end_time"/>
            <result column="screate_time"  property="create_time" /> 
    </resultMap>
    

      同时将 resultMap中该段的 column 属性该为 screate_time.故只要让查询出的字段名与column相同,它会通过映射找到相应属性进行封装。

  • 相关阅读:
    Java并发包线程池之ThreadPoolExecutor
    Java并发包之线程池概述
    Java同步数据结构之ConcurrentHashMap
    new 操作符
    javascript-类型转换
    javascript-引用类型
    JS-数组与伪数组
    SVG-JS操作
    SVG-变换
    SVG-标签
  • 原文地址:https://www.cnblogs.com/pangguoming/p/7299699.html
Copyright © 2020-2023  润新知