<mappers> <mapper resource="com/bjpowernode/manager/data/mappers/UserMapper.xml" /> <mapper resource="com/bjpowernode/manager/data/mappers/StudentMapper.xml" /> <mapper resource="com/bjpowernode/manager/data/mappers/ClassMapper.xml" /> <mapper resource="com/bjpowernode/manager/data/mappers/TeacherMapper.xml" /> </mappers>
<resultMap type="bjpowernodestudentmanagerdatamodelStudentEntity" id="studentResultMap"> <id property="studentId" column="STUDENT_ID" javaType="String" jdbcType="VARCHAR"/> <result property="studentName" column="STUDENT_NAME" javaType="String" jdbcType="VARCHAR"/> <result property="studentSex" column="STUDENT_SEX" javaType="int" jdbcType="INTEGER"/> <result property="studentBirthday" column="STUDENT_BIRTHDAY" javaType="Date" jdbcType="DATE"/> <result property="studentPhoto" column="STUDENT_PHOTO" javaType="byte[]" jdbcType="BLOB" typeHandler="orgapacheibatistypeBlobTypeHandler" /> </resultMap>
|
属性
|
描述
|
|
|
property
|
需要映射到JavaBean 的属性名称。
|
|
|
column
|
数据表的列名或者标签别名。
|
|
|
javaType
|
一个完整的类名,或者是一个类型别名。如果你匹配的是一个JavaBean,那MyBatis 通常会自行检测到。然后,如果你是要映射到一个HashMap,那你需要指定javaType 要达到的目的。
|
|
|
jdbcType
|
数据表支持的类型列表。这个属性只在insert,update 或delete 的时候针对允许空的列有用。JDBC 需要这项,但MyBatis 不需要。如果你是直接针对JDBC 编码,且有允许空的列,而你要指定这项。
|
|
|
typeHandler
|
使用这个属性可以覆写类型处理器。这项值可以是一个完整的类名,也可以是一个类型别名。
|
|
<resultMap type="StudentEntity" id="studentResultMap" >
<constructor>
<idArg javaType="String" column="STUDENT_ID"/>
<arg javaType="String" column="STUDENT_NAME"/>
<arg javaType="String" column="STUDENT_SEX"/>
<arg javaType="Date" column="STUDENT_BIRTHDAY"/>
</constructor>
</resultMap>
public StudentEntity(String studentID, String studentName, String studentSex, Date studentBirthday){
this.studentID = studentID;
this.studentName = studentName;
this.studentSex = studentSex;
this.studentBirthday = studentBirthday;
}
private TeacherEntity teacherEntity;
<resultMap type="ClassEntity" id="classResultMap">
<id property="classID" column="CLASS_ID" />
<result property="className" column="CLASS_NAME" />
<result property="classYear" column="CLASS_YEAR" />
<association property="teacherEntity" column="TEACHER_ID" select="getTeacher"/>
</resultMap>
<select id="getClassByID" parameterType="String" resultMap="classResultMap">
SELECT * FROM CLASS_TBL CT
WHERE CTCLASS_ID = #{classID};
</select>
<resultMap type="TeacherEntity" id="teacherResultMap">
<id property="teacherID" column="TEACHER_ID" />
<result property="teacherName" column="TEACHER_NAME" />
<result property="teacherSex" column="TEACHER_SEX" />
<result property="teacherBirthday" column="TEACHER_BIRTHDAY"/>
<result property="workDate" column="WORK_DATE"/>
<result property="professional" column="PROFESSIONAL"/>
</resultMap>
<select id="getTeacher" parameterType="String" resultMap="teacherResultMap">
SELECT *
FROM TEACHER_TBL TT
WHERE TT.TEACHER_ID = #{teacherID}
</select>
<resultMap type="ClassEntity" id="classResultMap">
<id property="classID" column="CLASS_ID" />
<result property="className" column="CLASS_NAME" />
<result property="classYear" column="CLASS_YEAR" />
<association property="teacherEntity" column="TEACHER_ID" resultMap="teacherResultMap"/>
</resultMap>
<select id="getClassAndTeacher" parameterType="String" resultMap="classResultMap">
SELECT *
FROM CLASS_TBL CT LEFT JOIN TEACHER_TBL TT ON CT.TEACHER_ID = TT.TEACHER_ID
WHERE CT.CLASS_ID = #{classID};
</select>
private List<StudentEntity> studentList;
<resultMap type="ClassEntity" id="classResultMap">
<id property="classID" column="CLASS_ID" />
<result property="className" column="CLASS_NAME" />
<result property="classYear" column="CLASS_YEAR" />
<association property="teacherEntity" column="TEACHER_ID" select="getTeacher"/>
<collection property="studentList" column="CLASS_ID" javaType="ArrayList" ofType="StudentEntity" select="getStudentByClassID"/>
</resultMap>
<select id="getClassByID" parameterType="String" resultMap="classResultMap">
SELECT * FROM CLASS_TBL CT
WHERE CT.CLASS_ID = #{classID};
</select>
<!-- java属性,数据库表字段之间的映射定义 -->
<resultMap type="StudentEntity" id="studentResultMap">
<id property="studentID" column="STUDENT_ID" />
<result property="studentName" column="STUDENT_NAME" />
<result property="studentSex" column="STUDENT_SEX" />
<result property="studentBirthday" column="STUDENT_BIRTHDAY" />
</resultMap>
<!-- 查询学生list,根据班级id -->
<select id="getStudentByClassID" parameterType="String" resultMap="studentResultMap">
<include refid="selectStudentAll" />
WHERE STCLASS_ID = #{classID}
</select>
<resultMap type="ClassEntity" id="classResultMap">
<id property="classID" column="CLASS_ID" />
<result property="className" column="CLASS_NAME" />
<result property="classYear" column="CLASS_YEAR" />
<association property="teacherEntity" column="TEACHER_ID" resultMap="teacherResultMap"/>
<collection property="studentList" column="CLASS_ID" javaType="ArrayList" ofType="StudentEntity" resultMap="studentResultMap"/>
</resultMap>
<select id="getClassAndTeacherStudent" parameterType="String" resultMap="classResultMap">
SELECT *
FROM CLASS_TBL CT
LEFT JOIN STUDENT_TBL ST
ON CT.CLASS_ID = ST.CLASS_ID
LEFT JOIN TEACHER_TBL TT
ON CT.TEACHER_ID = TT.TEACHER_ID
WHERE CT.CLASS_ID = #{classID};
</select>
<resultMap type="bjpowernodestudentmanagerdatamodelStudentEntity" id="resultMap_studentEntity_discriminator">
<id property="studentId" column="STUDENT_ID" javaType="String" jdbcType="VARCHAR"/>
<result property="studentName" column="STUDENT_NAME" javaType="String" jdbcType="VARCHAR"/>
<result property="studentSex" column="STUDENT_SEX" javaType="int" jdbcType="INTEGER"/>
<result property="studentBirthday" column="STUDENT_BIRTHDAY" javaType="Date" jdbcType="DATE"/>
<result property="studentPhoto" column="STUDENT_PHOTO" javaType="byte[]" jdbcType="BLOB" typeHandler="orgapacheibatistypeBlobTypeHandler" />
<result property="placeId" column="PLACE_ID" javaType="String" jdbcType="VARCHAR"/>
<discriminator column="CLASS_ID" javaType="String" jdbcType="VARCHAR">
<case value="20000001" resultType="bjpowernodestudentmanagerdatamodelStudentEntity" >
<result property="classId" column="CLASS_ID" javaType="String" jdbcType="VARCHAR"/>
</case>
</discriminator>
</resultMap>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有