做性能優化的最重要的功能就是降低數據庫的交互。非常多程序猿一般在開發的時候僅僅考慮簡單的實現功能,無論業務簡單復雜,僅僅要實現即可。
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">
select
t.id,t.name,s.t_s_id,s.sid,s.sname
from teacher t join student s on t.id
= s.t_s_id
where t.id = #{id}
</select>
</mapper>
collection這個應用使我們在服務層降低數據庫連接次數。從而達到優化性能的效果
mybatis性能優化之降低數據庫連接projectdemo下載:
http://download.csdn.net/detail/luozhonghua2014/8953781
