mybatis效能最佳化之減少資料庫連接,mybatis效能最佳化

來源:互聯網
上載者:User

mybatis效能最佳化之減少資料庫連接,mybatis效能最佳化

做效能最佳化的最重要的功能就是減少資料庫的互動,很多程式員一般在開發的時候只考慮簡單的實現功能,不管業務簡單複雜,只要實現就行。

mybatis有個重要的功能就是考慮在聯集查詢時技巧:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.cn.dao.TeacherMapper">  <resultMap type="com.cn.vo.Teacher" id="teacher"><id property="id" column="id" javaType="int" jdbcType="INTEGER" /><result property="name" column="name" javaType="string"jdbcType="VARCHAR" /><collection property="students" column="t_s_id" ofType="com.cn.vo.Student"><id property="sid" column="sid" javaType="int" jdbcType="INTEGER" /><result property="sname" column="sname" javaType="string"jdbcType="VARCHAR" /></collection></resultMap><select id="one2many" parameterType="int" resultMap="teacher">selectt.id,t.name,s.t_s_id,s.sid,s.snamefrom teacher t join student s on t.id= s.t_s_id where t.id = #{id}      </select> </mapper>  

collection 
這個應用使我們在服務層減少資料庫連接次數,從而達到最佳化效能的效果


mybatis效能最佳化之減少資料庫連接工程demo下載:

http://download.csdn.net/detail/luozhonghua2014/8953781










著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.