首页 > 技术文章 > mybatis连接池以及事务管理 day3

wjune-0405 2020-03-31 14:18 原文

1、连接池技术可以帮助我们更快的与数据库进行连接

mybaits框架中实现连接池技术,pooled中有一个具有先进先出性质的连接池,有需要时取出连接,用完后还会连接池

如果连接数量不足连接池最大size,就生成新的连接,如果已满,就去申请最老的连接

unpooled就是原始的jdbc

2、事务

什么是事务:
事务的四大特性ACID:
不考虑隔离性会产生的3个问题:
解决办法:四种隔离级别

mybatis通过sqlsession对象的commit方法和rollback方法实现事务的提交和回滚

3、动态sql语句

<if>
<where>
<foreach>

collection="ids" 列表属性 
语句开始拼接open="and id in ("
语句结束拼接close=")"
语句中放入的值item="id"
分割符号separator=","
select * from user where id in(41,42,43);
 <!--根据id列表进行查询-->
    <select id="findUserByIds" resultMap="userMap" parameterType="QueryVo">
        select * from user
        <where>
            <if test="ids != null">
                <foreach collection="ids" open="and id in (" close=")" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>

  


<sql>

使用sql将一些默认标签提取

 

推荐阅读