问题描述:
pojo的定义如下图,在ExamSubject对象中内嵌TeacherInformation对象。
通过联表查询,获取从数据库中获取数据
<select id="findExamSubjectForAdmin" resultMap="exam">
select e.id, e.subjectName, e.createTime,t.teacherName,t.teacherId, t.username, t.className, t.tel
from exam_subject as e, teacher_information as t
where e.teacherName=t.teacherName
</select>
<resultMap id="exam" type="ExamSubject">
<id property="id" column="id"/>
<result property="subjectName" column="subjectName"/>
<result property="createTime" column="createTime"/>
<result property="teacherName" column="teacherName"/>
<association property="teacher" javaType="TeacherInformation">
<id property="teacherId" column="teacherId"/>
<result property="username" column="username"/>
<result property="className" column="className"/>
<result property="tel" column="tel"/>
<result property="teacherName" column="teacherName"/>
</association>
</resultMap>
获取的数据格式如下图所示:
在ExamSubject对象中的基本类型属性(字段)可以直接通过easyUI中的field
关键字取出
如果要取出TeacherInformation对象,teacher实例中的className属性,通过以下方法。
解决方法
通过data-options的formatter方法解决。
<th width="200" align="center" data-options="field:'teacher',
formatter:function(value){
if(value.className){
return value.className;
}} ">班级名</th>