1. 程式人生 > >sql效能優化第三篇之mybait接收多資料集(分頁資料和count資料)

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、看完點個贊,關注下唄~