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相同,它会通过映射找到相应属性进行封装。

MyBatis两张表字段名相同产生的问题的更多相关文章

  1. struts+spring+hibernate两张表字段名一样处理方法

    在利用struts2+spring+hibernate(利用Hibernate进行分页查询)三大框架进行开发项目的时候,出现一个问题:居然要进行关联查询的十几张表中有两张表的字段一样,并且这两张表中的 ...

  2. mysql 两张表字段模糊匹配--字符串拼接函数

    concat(A,B,C,...)  拼接字符串 例如concat('123','***','345')  =>123***345 SELECT concat( substr(t1.CODE, ...

  3. MyBatis:当表字段名和实体类属性名不一致

    第一种解决方法:在sql中使用别名 <select id="getRoleList" resultType="com.ttpfx.domain.Role" ...

  4. sql 根据指定条件获取一个字段批量获取数据插入另外一张表字段中+MD5加密

    /****** Object: StoredProcedure [dbo].[getSplitValue] Script Date: 03/13/2014 13:58:12 ******/ SET A ...

  5. mysql中修改表字段名/字段长度/字段类型详解

    在mysql中我们对数据表字段的修改命令只要使用alter就可以了,下面我来给大家详细介绍mysql中修改表字段名/字段长度/字段类型等等一些方法介绍,有需要了解的朋友可参考. 先来看看常用的方法 M ...

  6. ef core 数据类型 && 表字段名设置

    HasColumnType HasColumnType是指定字段类型 [Column(TypeName = "decimal(18, 2)")] public decimal Mo ...

  7. mybatis使用中类属性名和数据库表字段名问题

    起初我以为上述二者必须一致,后来发现也是可以像Hibernate那样在xml文件中进行映射的. <mapper namespace="com.tenghu.mybatis.model. ...

  8. mysql存储过程或函数中传入参数与表字段名相同引发的悲剧

    真实案例.如下的一个存储过程: create procedure Apple(in user_id int) begin delete from users where user_id = user_ ...

  9. mysql多表字段名重复的情况

    CREATE TABLE `card` ( `id` ) unsigned NOT NULL AUTO_INCREMENT, `json_str` ) NOT NULL, `f` ,) unsigne ...

随机推荐

  1. The file will have its original line endings in your working directory.

    在空仓库的情况下,add,出现一下问题 The file will have its original line endings in your working directory. 当报这个警告时是 ...

  2. 怎么将maven项目打包成war包

    问题:我在eclipse上能运行,然后我想将这个maven项目打包成war然后放到另外一台机子上(其实是手动放在tomcat的webapp目录中),提供外部访问.现在问题是,一直maven项目打包一直 ...

  3. LOJ.2587.[APIO2018]铁人两项Duathlon(圆方树)

    题目链接 LOJ 洛谷P4630 先对这张图建圆方树. 对于S->T这条(些)路径,其对答案的贡献为可能经过的所有点数,那么我们把方点权值设为联通分量的大小,可以直接去求树上路径权值和. 因为两 ...

  4. Codeforces Round #281 (Div. 2) D. Vasya and Chess 镜面对称 博弈论

    D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. linux命令-每天一点进步

    2018-05-28 1.yum install -y,这里的-y表示,在安装软件的过程中,无需用户输入yes or no,默认yes 2../sbin/nginx -s reload,重启nginx ...

  6. MySQL: 查看一次SQL的执行时间都花在哪些环节上

    select @@profiling -- 看看当前的session的profiling打开没有 set profiling = 1 -- 如果没打开,打开一下 -- 执行一些sql select c ...

  7. 解决IE11下载文件 文件名乱码问题

    1.Win + R输入gpedit.msc打开组策略编辑器:(不会请看下图) 2.定位到计算机配置→管理模板→windows组件→Internet Explorer→自定义用户代理字符串(有些系统用的 ...

  8. .Net中的插件框架Managed Extensibility Framework

    Managed Extensibility Framework(MEF)是微软的一个用来扩展.NET应用程序的框架,它最初为了满足Visual Studio里的编辑器的需求,比如说,延迟加载所有东西和 ...

  9. Make a DAC with a microcontroller's PWM timer

    http://www.edn.com/design/analog/4337128/Make-a-DAC-with-a-microcontroller-s-PWM-timer Many embedded ...

  10. xvcd – The Xilinx Virtual Cable Daemon

    http://debugmo.de/2012/02/xvcd-the-xilinx-virtual-cable-daemon/ I recently discovered an almost undo ...