ClassesMapper.xml <?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.nantian.mybatis.one2one.ClassesMapper"> <resultMap type="Classes" id="classes"> <id property="id" column="c_id" javaType="int" jdbcType="INTEGER"/> <result property="name" column="c_name" javaType="string" jdbcType="VARCHAR"/> <association property="teacher" column="c_t_id" javaType="Teacher"> <id property="id" column="t_id" javaType="int" jdbcType="INTEGER"/> <result property="name" column="t_name" javaType="string" jdbcType="VARCHAR"/> </association> </resultMap> <select id="one2one" parameterType="int" resultMap="classes"> select c.c_id,c.c_name,c.c_t_id,t.t_id,t.t_name from classes c join teacher t on c.c_t_id = t.t_id where c.c_id = #{id} </select> </mapper> Classes package com.nantian.mybatis.one2one; public class Classes { private int id; private String name; private Teacher teacher; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Teacher getTeacher() { return teacher; } public void setTeacher(Teacher teacher) { this.teacher = teacher; } } ClassesMapper package com.nantian.mybatis.one2one; public interface ClassesMapper { public Classes one2one(int id); } Teacher package com.nantian.mybatis.one2one; public class Teacher { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } T package com.nantian.mybatis.one2one; import org.apache.ibatis.session.SqlSession; import com.nantian.mybatis.data.DBUtil; public class T { public static void main(String[] args) { SqlSession sqlSession = DBUtil.getInstance().getSqlSessionFactory() .openSession(); try { ClassesMapper classesMapper = sqlSession .getMapper(ClassesMapper.class); Classes classes = classesMapper.one2one(1); Teacher teacher = classes.getTeacher(); System.out.println(classes.getId()); System.out.println(classes.getName()); System.out.println(teacher.getId()); System.out.println(teacher.getName()); } finally { sqlSession.close(); } } }