做性能优化的最重要的功能就是降低数据库的交互。非常多程序猿一般在开发的时候仅仅考虑简单的实现功能,无论业务简单复杂,仅仅要实现即可。
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.youkuaiyun.com/detail/luozhonghua2014/8953781