Mapper.xml
//查询总记录数
<select id="getPagerList" parameterType="java.util.Map" resultMap="map">
SELECT
<choose>
<!--查询总记录数-->
<when test="iscount!=null and iscount!=''">
COUNT(*) id
</when>
<otherwise>
c.*,
cs.name as cname,
i.realname as iname,
s.realname as sname
</otherwise>
</choose>
FROM comment c
LEFT JOIN course cs ON cs.id = c.cid
LEFT JOIN instructor i ON i.id = c.iid
LEFT JOIN student s ON s.id = c.sid
WHERE 1=1
<if test="cid != null and cid != ''">
AND c.cid like concat('%', #{cid}, '%')
</if>
<if test="iid != null and iid != ''">
AND c.iid like concat('%', #{iid}, '%')
</if>
<if test="sid != null and sid != ''">
AND c.sid like concat('%', #{sid}, '%')
</if>
<!--条件查询-->
<select id="getAllWhere" parameterType="java.util.Map" resultMap="map">
SELECT
c.*,
cs.name as cname,
i.realname as iname,
s.realname as sname
FROM comment c
LEFT JOIN course cs ON cs.id = c.cid
LEFT JOIN instructor i ON i.id = c.iid
LEFT JOIN student s ON s.id = c.sid
WHERE 1=1
<if test="cid != null and cid != ''">
AND c.cid like concat('%', #{cid}, '%')
</if>
<if test="iid != null and iid != ''">
AND c.iid like concat('%', #{iid}, '%')
</if>
<if test="sid != null and sid != ''">
AND c.sid like concat('%', #{sid}, '%')
</if>
</select>
<resultMap id="map" type="cn.educate.model.commentModel" autoMapping="true">
<association property="course" javaType="cn.educate.model.courseModel">
<result property="name" column="cname" />
</association>
<association property="instructor" javaType="cn.educate.model.instructorModel">
<result property="realname" column="iname"/>
</association>
<association property="student" javaType="cn.student.model.studentModel">
<result property="realname" column="sname"/>
</association>
</resultMap>