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. JAVAEE——宜立方商城03:商品类目选择、Nginx端口或域名区分虚拟机、Nginx反向代理、负载均衡、keepalived实现高可用

    1. 学习计划 第三天: 1.商品类目选择(EasyUI的tree实现) 2.图片上传 a) 图片服务器FastDFS(Nainx部分) 2. 商品类目选择 2.1. 原型 2.2. 功能分析 展示商 ...

  2. 在Tomcat中部署web项目的三种方式

    搬瓦工搭建SS教程 SSR免费节点:http://www.xiaokeli.me 在这里介绍在Tomcat中部署web项目的三种方式: 1.部署解包的webapp目录 2.打包的war文件 3.Man ...

  3. 虚拟多Mac地址工具Multimac

    虚拟多Mac地址工具Multimac   Mac地址采用唯一标识标记网络的各种设备.在同一个时间内,Linux系统中的网卡只能使用一个Mac地址.在渗透测试中,为了隐藏自己的身份,往往需要以不同的Ma ...

  4. 1014 Waiting in Line (30)(30 point(s))

    problem Suppose a bank has N windows open for service. There is a yellow line in front of the window ...

  5. python 乘法表、打印菱形

    for i in range(1,10): print ' '.join(map(lambda x:"%d x %d = %d"%(x,i,i*x),range(1,i+1))) ...

  6. IO编程

    1.文件读写 >>>f = open('/Users/michael/test.txt', 'r') >>> f.read() 'Hello, world!' &g ...

  7. Linux 下安装软件包的方法

    Linux应用软件的安装包有三种: 1) tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. 2) rpm包,如software-1.2.3-1. ...

  8. DEX 可视化查阅

    参考: http://bbs.pediy.com/thread-208828.htm 010 Editor 下载地址: http://www.sweetscape.com/download/ //-- ...

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

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

  10. PHP-输入变量

    在Web开发过程中,我们经常需要获取系统变量或者用户提交的数据,这些变量数据错综复杂,而且一不小心就容易引起安全隐患,但是如果利用好ThinkPHP提供的变量获取功能,就可以轻松的获取和驾驭变量了. ...