zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mybatis性能优化之减少数据库连接

2023-09-14 09:04:36 时间
做性能优化的最重要的功能就是减少数据库的交互,很多程序员一般在开发的时候只考虑简单的实现功能,不管业务简单复杂,只要实现就行。 mybatis有个重要的功能就是考虑在联合查询时技巧: ?xml version= 1.0 encoding= UTF-8 ? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3

做性能优化的最重要的功能就是减少数据库的交互,很多程序员一般在开发的时候只考虑简单的实现功能,不管业务简单复杂,只要实现就行。

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











Mybatis是如何向Spring注册Mapper的? 有时候我们需要自行定义一些注解来标记某些特定功能的类并将它们注入Spring IoC容器。比较有代表性的就是Mybatis的Mapper接口。假如有一个新的需求让你也实现类似的功能你该如何下手呢?今天我们就从Mybatis的相关功能入手来学习其思路并为我所用。
MyBatis 学习笔记(三)MyBatis与Spring 和SpringBoot整合 接上一篇MyBatis 学习笔记(二)MyBatis常用特性运用 在真实的项目我们几乎不会将MyBatis 单独运用到项目中,而是将其整合到Spring框架或者SpringBoot中,本文将通过两个demo演示MyBatis 与Spring和SpringBoot的整合。