sql性能優化第三篇之mybait接收多數據集(分頁數據和count數據)

廢話不多說,直接上代碼:

1、xml代碼:

<!-- 獲取學生列表數據-分頁-+count數據 -->
<select id="getStudentManagePage" resultMap="StudentManageVoMap,count">
   SELECT sql_calc_found_rows 這裏是字段 FROM 
        tbl_student_infomation AS tsi
        LEFT JOIN tbl_college AS tco ON tsi.college_id=tco.id
        LEFT JOIN tbl_profession AS tp ON tsi.profession_id=tp.id
        LEFT JOIN tbl_class AS tcl ON tsi.class_id=tcl.id
        WHERE 1=1
        ORDER BY tcs.score DESC,tsi.is_track DESC,tsi.sno DESC limit #{offset},#{limit};
   SELECT found_rows() as count;
</select>
<!--接收count數據集-->
<resultMap type="Integer" id="count">
    <result column="count" jdbcType="INTEGER" javaType="Integer" />
</resultMap>
<!--接收分頁數據集-->
<resultMap type="com.atage.entity.vo.StudentManageVo" id="StudentManageVoMap">
        <result column="sno" jdbcType="VARCHAR" property="sno" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="sex" jdbcType="INTEGER" property="sex" />
        <result column="imgUrl" jdbcType="VARCHAR" property="imgUrl" />
        <result column="brithday" jdbcType="DATE" property="brithday" />
        <result column="sourcePlace" jdbcType="VARCHAR" property="sourcePlace" />
        <result column="singleton" jdbcType="INTEGER" property="singleton" />
        <result column="parentFamily" jdbcType="INTEGER" property="parentFamily" />
        <result column="enrollment" jdbcType="VARCHAR" property="enrollment" />
        <result column="collegeId" jdbcType="VARCHAR" property="collegeId" />
        <result column="professionId" jdbcType="VARCHAR" property="professionId" />
        <result column="classId" jdbcType="VARCHAR" property="classId" />
        <result column="isTrack" jdbcType="INTEGER" property="isTrack" />
        <result column="score" jdbcType="DOUBLE" property="score" />
        <result column="gradeC" jdbcType="DOUBLE" property="gradeC" />
        <result column="gradeQ" jdbcType="DOUBLE" property="gradeQ" />
        <result column="gradeId" jdbcType="VARCHAR" property="gradeId" />
        <result column="clollegeName" jdbcType="VARCHAR" property="clollegeName" />
        <result column="yearName" jdbcType="VARCHAR" property="yearName" />
        <result column="professionName" jdbcType="VARCHAR" property="professionName" />
        <result column="className" jdbcType="VARCHAR" property="className" />
        <result column="teacherId" jdbcType="VARCHAR" property="teacherId" />
    </resultMap>

2、Mapper代碼:

//接收用list<?>
List<?> getStudentManagePage(這裏是傳遞的條件參數);

 3、service代碼:

//接收用list<?>
List<?> getStudentManagePage(這裏是傳遞的條件參數);

4、serviceimpl代碼:

@Override
    public List<?> getStudentManagePage(參數) {
        return tblStudentInfomationMapper.getStudentManagePage(參數);
    }

5、controller代碼:

//這裏是接收數據
List<?> list = tblStudentInfomationService.getStudentManagePage(參數);
List<StudentManageVo> studentManageVoList = new ArrayList<StudentManageVo>();
//接收分頁數據
studentManageVoList = (List<StudentManageVo>)list.get(0);
//接收count數據
count = ((List<Integer>) list.get(1)).get(0);

6、看完點個贊,關注下唄~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章