MyBatis高级映射:一对一
来源:互联网 发布:淘宝描述不符处罚 编辑:程序博客网 时间:2024/05/29 11:22
说一下mybatis复杂映射,一对一,定义内嵌的resultMap。一个用户对应一个地址:简单的映射用resultType就好了
用户表:
地址表:
javabean实体类:
public class Persons implements Serializable{ private static final long serialVersionUID = 1396106231553523339L; private int ID; private String name; private String age; private String sal; private int addressID; private Addresst address;
public class Addresst implements Serializable{ private static final long serialVersionUID = 4125186087709383897L; private int ID; private String city; public int getID() { return ID; }
接口定义的方法:
package cn.xyl.com.dao;import org.springframework.stereotype.Repository;import cn.xyl.com.entity.Persons;@Repository("personDao")public interface PersonDao { Persons getAll(int ID);}
mapper.xml映射文件内容:
<mapper namespace="cn.xyl.com.dao.PersonDao"> <resultMap type="cn.xyl.com.entity.Persons" id="All"> <id property="ID" column="ID"/> <result property="name" column="name"/> <result property="age" column="age"/> <result property="sal" column="sal"/> <result property="addressID" column="addressID"/> <association property="address" javaType="cn.xyl.com.entity.Addresst"> <id property="ID" column="ID"/> <result property="city" column="city"/> </association> </resultMap> <select id="getAll" parameterType="int" resultMap="All"> SELECT p.ID,p.name,p.age,p.sal,p.addressID,a.ID ,a.city FROM person p,addresst a WHERE p.addressID=a.ID AND p.addressID=#{ID} </select></mapper>
上面peoperty指的是javabean的属性,column指的是数据库的字段。映射address(Addresst对象的引用) 实体属性使用association(关联)映射。
结果:
阅读全文
0 0
- MyBatis-高级映射:一对一
- MyBatis高级映射:一对一
- Mybatis(高级映射,一对一)
- Mybatis高级映射一对一查询
- 【MyBatis框架】高级映射-一对一查询
- 【mybatis基础】高级映射:一对一查询
- 【MyBatis框架】高级映射-一对一查询
- 【Mybatis】---高级映射之一对一查询
- MyBatis高级映射(一对一查询)
- MyBatis高级映射之一对一查询
- 第六简单6-mybatis高级映射一对一
- MyBatis高级映射之-一对一(一对多)关联映射
- mybatis映射 一对一、一对多、多对多高级映射
- mybatis高级结果映射学习之一对一映射(六)
- mybatis学习高级映射一对一之resultMap映射
- mybatis高级输出映射(一对一查询输出映射)
- Mybatis高级结果映射一对一或一对多
- Mybatis - 高级映射 (复习,数据表分析,一对一 之 resultType )
- MySQL中列子查询与行子查询操作的学习教程
- 城市计算-数据库索引-Grid-based Spatial Indexing
- 常见排序算法
- poj3624
- [LeetCode]215. Kth Largest Element in an Array
- MyBatis高级映射:一对一
- android进阶-Android控件架构与自定义控件详解(一)
- 深度学习的局部响应归一化LRN(Local Response Normalization)理解
- S0.1 调色板
- SQL语句优化--重点
- HDU 2948 Geometry Darts(点在圆,三角形,矩形内判定)
- poj3195 Generalized Matrioshkas(瞎搞题翻译)
- 【BashuOJ2963】数字游戏-DFS+剪枝
- PHP PDO::execute()执行insert into失败返回错误无错误消息的解决