resultMap 映射
1. sql的重用:定义一个sql片段,可在任何SQL语句中重用该片段。
- <sql id="personColumns"> name, sex, updateTime</sql>
- <select id="selectPerson" parameterType="int" resultType="hashmap">
- select id, <include refid="personColumns"/> from person where id =#{id};
- </select>
2. javabean别名:不用每次写包路径
- <!-- In Config XML file,定义 -->
- <typeAlias type=”com.someapp.model.User” alias=”User”/>
- <!-- In SQL Mapping XML file,使用 -->
- <select id=”selectUsers” parameterType=”int” resultType=”User”>
- select id, username, hashedPassword from some_table where id = #{id}
- </select>
3. 表与实体列名不匹配的解决
a) SQL的别名
- <select id=”selectUsers” parameterType=”int” resultType=”User”>
- select user_id as "id", user_name as userName, hashed_password as hashedPassword from some_table where id = #{id}
- </select>
b)定义外部的resultMap
- <resultMap id="userResult" type="User">
- <id property="id" column="_id" />
- <result property="name" column="_name" />
- <result property="password" column="_password" />
- </resultMap>
- <select id="selectUser" parameterType="int" resultMap="userResult">
- select _id, _name, _password from _user where _id =#{id};
- </select>
resultMap 映射的更多相关文章
- mybatis resultMap映射学习笔记
这几天,百度mybatis突然看不到官网了,不知道百度怎么整的.特此贴出mybatis中文官网: http://www.mybatis.org/mybatis-3/zh/index.html 一个学习 ...
- MyBatis关联查询,表字段相同,resultMap映射问题的解决办法
问题描述:在使用mybatis进行多表联合查询时,如果两张表中的字段名称形同,会出现无法正常映射的问题. 问题解决办法:在查询时,给重复的字段 起别名,然后在resultMap中使用别名进行映射. 给 ...
- Mybatis结果集ResultMap映射
基本使用: 解决属性名和数据库字段名不一致的问题 <resultMap id="user" type="com.guan.bean.UserBean"&g ...
- mybatis resultMap 映射配置
现有数据库表: CREATE TABLE `dept_p` ( `DEPT_ID` ) NOT NULL, `DEPT_NAME` ) DEFAULT NULL, `PARENT_ID` ) DEFA ...
- mybatis - 基于拦截器修改执行语句中的ResultMap映射关系
拦截器介绍 mybatis提供了@Intercepts注解允许开发者对mybatis的执行器Executor进行拦截. Executor接口方法主要有update.query.commit.rollb ...
- 【mybatis源码学习】ResultMap查询结果映射
一.ResultMap包含的元素 constructor - 用于在实例化类时,注入结果到构造方法中 idArg - ID 参数:标记出作为 ID 的结果可以帮助提高整体性能 arg - 将被注入到构 ...
- mybatis入门基础(六)----高级映射(一对一,一对多,多对多)
一:订单商品数据模型 1.数据库执行脚本 创建数据库表代码: CREATE TABLE items ( id INT NOT NULL AUTO_INCREMENT, itemsname ) NOT ...
- MyBatis关联查询 (association) 时遇到的某些问题/mybatis映射
先说下问题产生的背景: 最近在做一个用到MyBatis的项目,其中有个业务涉及到关联查询,我是将两个查询分开来写的,即嵌套查询,个人感觉这样更方便重用: 关联的查询使用到了动态sql,在执行查询时就出 ...
- 20Mybatis_订单商品数据模型_一对一查询——resultType和resultMap两种方式以及两种方式的总结
上一篇文章分析了数据模型,这篇文章就给出一个需求,这个需求是一对一查询,并完成这个需求. ------------------------------------------------------- ...
随机推荐
- How To Set Up an OpenVPN Server on Ubuntu 14.04
Prerequisites The only prerequisite is having a Ubuntu 14.04 Droplet established and running. You wi ...
- PRINCE2七大原则
我们先来回顾一下,PRINCE2七大原则分别是持续的业务验证,经验学习,角色与责任,按阶段管理,例外管理,关注产品,剪裁. 第三个原则:明确定义的角色和职责. 项目离不开人员,错误的人来了,合适的人没 ...
- cookie、sessionStorage、localStorage
转自--http://www.cnblogs.com/fly_dragon/p/3946012.html cookie Cookie的大小.格式.存储数据格式等限制,网站应用如果想在浏览器端存储用户的 ...
- html5图片异步上传/ 表单提交相关
1 form 表单 get/post提交时候. action地址(或者啥ajax的url地址) 会涉及到跨域问题 常见跨域问题http://www.cnblogs.com/rainman/archiv ...
- HD2222 Keywords Search(AC自动机入门题)
然而还不是很懂=_= #include <iostream> #include <cstring> #include <algorithm> #include &l ...
- CLI:如何使用Go开发命令行
CLI或者"command line interface"是用户在命令行下交互的程序.由于通过将程序编译到一个静态文件中来减少依赖,一次Go特别适合开发CLI程序.如果你编写过安装 ...
- jQuery实现的表格展开伸缩效果实例
<table> <thead> <tr> <th>姓名</th> <th>性别</th> <th>暂住地 ...
- 【ESRI论坛6周年征文】ArcEngine注记(Anno/ Label/Element等)处理专题 -入门篇
原发表于ESRI中国社区,转过来.我的社区帐号:jhlong http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=122097 ----------- ...
- linux集群时钟问题
一.ntpd与ntpdate的区别: 摘自:ntpd与ntpdate的区别 - 百事乐 - 博客园 http://www.cnblogs.com/liuyou/archive/2012/07/29/ ...
- 四、Shell输入、输出功能和字符颜色设置
一.Shell输入功能 1.键盘输入 方式一: [root@Salve four]# cat test.sh #!/bin/bash #-e 参数可以解析语句中的转义字符 echo -e &quo ...