- 需求分析:课程表(course)里有一个跟studet_id的字段,是对应student表里的id
现在想要通过查询course表在根据课程表里的student_id查询到student表里的学生姓名name一并返回
<select id="selectCourse" resultMap="BaseResultMap">
select course.*,student.name
from course,student
where course.student_id = student.id
and course.del_flag = 0
order by id desc
</select>
也可用类似下面的语句:
SELECT project_store.*,construction_unit.`name` from project_store
INNER JOIN construction_unit ON project_store.constru_unit_id = construction_unit.id
ORDER BY id DESC
- 而且你需要在BaseResultMap原表基础上增加返回结果的字段:
<result column="name" jdbcType="VARCHAR" property="studentName"/>
- modal层也应该增加studentName字段
private String studentName;