MyBatis使用总结和整合Spring

<?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.mybatis.classesMapper"> <!-- 根据班级id查询班级信息(包括老师信息) --> <select parameterType="int" resultMap="ClassesMap"> SELECT * FROM class c, teacher t WHERE c.teacher_id = t.t_id and c.c_id = #{id} </select> <!-- 联表查询 --> <resultMap type="com.mybatis.Classes"> <id property="id" column="c_id"/> <result property="name" column="c_name"/> <association property="teacher" column="teacher_id" javaType="com.mybatis.Teacher"> <id property="id" column="t_id"/> <result property="name" column="t_name"/> </association> </resultMap> <!-- 嵌套查询 --> <select parameterType="int" resultMap="ClassesMap2"> SELECT * FROM class WHERE c_id=#{id} </select> <select parameterType="int" resultType="com.mybatis.Teacher"> SELECT t_id id, t_name FROM teacher WHERE t_id=#{id} </select> <resultMap type="com.mybatis.Classes"> <id property="id" column="c_id"/> <result property="name" column="c_name"/> <association property="teacher" column="teacher_id" select="getTeacher"> </association> </resultMap> </mapper>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/af1e9c1267f3ade9ffa627216a31205e.html