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">
		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性能优化之减少数据库连接工程demo下载:

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










posted @ 2015-08-02 16:29  172257861  阅读(659)  评论(0编辑  收藏  举报