在实现实列中我们在学生表里面增加了一个地址表用于与学生表的一对一

1.创建地址实体类:

package com.java1234.mappers;

import com.java1234.model.Address;

public interface AddressMapper {

public Address findById(Integer id);

}

2.创建地址实体类关联的映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java1234.mappers.AddressMapper">

<resultMap type="Address" id="AddressResult">
<result property="id" column="id"/>
<result property="sheng" column="sheng"/>
<result property="shi" column="shi"/>
<result property="qu" column="qu"/>
</resultMap>

<select id="findById" parameterType="Integer" resultType="Address">
select * from t_address where id=#{id}
</select>

</mapper>

3.在学生表的映射文件里面关联地址

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.java1234.mappers.StudentMapper">

<resultMap type="Student" id="StudentResult">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<association property="address" column="id" select="com.java1234.mappers.AddressMapper.findById"></association>
</resultMap>

<select id="findStudentWithAddress" resultMap="StudentResult" parameterType="Integer">
select * from t_student t1,t_address t2 where t1.addressId=t2.id and t1.id=#{id}
</select>

<insert id="add" parameterType="Student" >
insert into t_student values(null,#{name},#{age})
</insert>

<update id="update" parameterType="Student">
update t_student set name=#{name},age=#{age} where id=#{id}
</update>

<delete id="delete" parameterType="Integer">
delete from t_student where id=#{id}
</delete>

<select id="findById" parameterType="Integer" resultType="Student">
select * from t_student where id=#{id}
</select>

<select id="find" resultMap="StudentResult">
select * from t_student
</select>
</mapper>

最新文章

  1. PHP如何获取二个日期的相差天数?
  2. bug--service--Caused by java.lang.SecurityException: Unable to start service Intent { }:user 0 is restricted
  3. mysql闪退或者can not connect 127.0.0.1
  4. linux更改文件所有者命令chown命令的使用困惑
  5. Struts2应用的开发流程
  6. 通用权限底层研究:Web应用限制IP访问的功能实现
  7. Jeally Bean中MonekyRunner 帮助文件
  8. 事务Isolation Level 例子详解
  9. Structs2中Action返回json到前台方法
  10. hdu1042(大数模板)
  11. NSA永恒之蓝病毒,如何通过360工具修复?
  12. jquery实现导航栏效果
  13. JavaScript 第一课
  14. 第二次项目冲刺(Beta阶段)--第四天
  15. canvas将图片转为base64
  16. es6变量声明和解构赋值
  17. 大型网站架构演进(6)使用NoSQL和搜索引擎
  18. kubernetes之ingress及ingress controller
  19. Django之BBS博客项目
  20. 解决git中upstream丢失问题Your branch is based on &#39;origin/xxxx&#39;, but the upstream is gone.

热门文章

  1. 解决spring mybatis 整合后mapper接口注入失败
  2. 39、生鲜电商平台-redis缓存在商品中的设计与架构
  3. C# 5.0中新增特性
  4. api接口访问限制
  5. JVM 零散知识
  6. Unity 行为树-节点间数据传递
  7. codeforces1016 D. Vasya And The Matrix(思维+神奇构造)
  8. 解决spark-shell输出日志信息过多
  9. Jmeter4.0----正则表达式提取器(12)
  10. eclipse导入maven项目有时出现web.xml is missing的问题