mybatis学习高级映射一对一之resultMap映射
来源:互联网 发布:工资核算软件 编辑:程序博客网 时间:2024/05/29 19:47
- 使用resultMap来进行一对一结果映射,它是将关联对象添加到主信息的对象中,具体说是对象嵌套对象的一种映射方式。
- 在写映射之前先把sql语句写好,然后在xml文件中进行配置
<select id="findMapperOrderUser" resultMap="MapperOrderUser" > Select orders.*, user.username, user.sex, user.address from orders, user where orders.user_id=user.id </select>
,id表示映射的接口方法名,遵循mapper代理规范,resultMap与下面的相对应。sql语句中查询了orders表中的全部数据和user表中的部分数据,现在我要把这些查询的结果映射到orders表中,那么我就在orders表中增加一个User对象属性。在xml中用到的resultMap配置就多了一个步骤,分别是映射关联单个对象,也就是orders本身需要配置,还有一个与user表相关的配置。
<resultMap type="com.itsky.day02.Orders" id="MapperOrderUser"> <id column="id" property="id"/> <result column="user_id" property="userId"/> <result column="number" property="number"/> <result column="createtime" property="createtime"/> <result column="note" property="note"/>
type表示映射的对象。id和resultMap的值相对应。列表的唯一标识,column表示数据库列表的属性,property对应的是bean类的属性。
<association property="user" javaType="com.itsky.day02.User"><id column="user_id" property="id"/> <result column="username" property="username"/> <result column="sex" property="sex"/> <result column="address" property="address"/></association>
association:用于映射关联查询单个对象的信息;property:要将关联查询的用户信息映射到Orders中的哪个属性.
- 测试结果
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.[Orders [id=1, userId=null, number=1, createtime=Wed Mar 11 00:00:00 CST 2015, note=1, user=null]]
0 0
- mybatis学习高级映射一对一之resultMap映射
- 框架学习系列 mybatis 第十八篇 高级结果一对一结果映射之resultMap的使用
- mybatis高级结果映射学习之一对一映射(六)
- MyBatis之使用resultMap实现高级映射
- MyBatis-高级映射:一对一
- MyBatis高级映射:一对一
- Mybatis(高级映射,一对一)
- 【MyBatis学习08】高级映射之一对一查询
- mybatis学习之高级映射中的一对一查询
- 【MyBatis学习08】高级映射之一对一查询
- 【MyBatis学习08】高级映射之一对一查询
- Mybatis学习(07)-高级映射之一对一查询
- 【MyBatis学习08】高级映射之一对一查询
- 【Mybatis】---高级映射之一对一查询
- MyBatis高级映射之一对一查询
- MyBatis高级映射之-一对一(一对多)关联映射
- Mybatis高级映射一对一查询
- Mybatis 高级结果映射 ResultMap Association Collection
- leetcode125. Valid Palindrome
- TCP/IP协议栈分析(1)-概述
- jquery判断字符串中是否包含特定字符的方法总结
- 计算机科学和编程导论-week3-作业
- jQuery取消冒泡排序事件
- mybatis学习高级映射一对一之resultMap映射
- 计算几何 基础算法 + 题目(转)
- CF-Codeforces Round #410 (Div. 2)-A~C
- 使用模态框进行登录
- LeetCode-M-Unique Binary Search Trees II
- Python
- Android自动关机
- 集合框架-ArrayList存储字符串、自定义对象并遍历泛型版
- poj 1852 Ants 发现问题,解决问题