摘要: MyBatis 一级缓存最大的共享范围就是一个SqlSession内部,那么如果多个 SqlSession 需要共享缓存,则需要开启二级缓存,开启二级缓存后,会使用 CachingExecutor 装饰 Executor,进入一级缓存的查询流程前,先在CachingExecutor 进行二级缓存的查 阅读全文
posted @ 2020-02-26 00:10 Arbitrary233 阅读(267) 评论(0) 推荐(0)
摘要: /*测试一级缓存(本地缓存):sqlSession的缓存级别。一级缓存是一直开启的 * 与数据库同一次会话期间查询到的数据会放在本地缓存中。 * 以后如果需要获取相同的数据,直接从缓存中拿,不需要再去查数据库; * * 一级缓存失效情况: * 1、sqlSession不同 * 2、sqlSessio 阅读全文
posted @ 2020-02-25 21:53 Arbitrary233 阅读(191) 评论(0) 推荐(0)
摘要: StudentMapper中的配置 抽取的sql用<sql>标签;属性id即该sql的唯一标识 需要引用时使用<include>标签;属性refid填写要引用sql的id <!-- 通过foreach批量插入数据 --> <insert id="insertStusByForeach"> inser 阅读全文
posted @ 2020-02-25 17:24 Arbitrary233 阅读(794) 评论(0) 推荐(0)
摘要: <select id="getStuByTrim" resultType="student"> select * from student <!-- 绑定参数拼接字符串 --> <bind name="stuName" value="'%'+name+'%'"/> <trim prefix="whe 阅读全文
posted @ 2020-02-25 17:12 Arbitrary233 阅读(257) 评论(0) 推荐(0)
摘要: foreach元素的属性主要有item,index,collection,open,separator,close。 item:集合中元素迭代时的别名,该参数为必选。 index:在list和数组中,index是元素的序号,在map中,index是元素的key,该参数可选 open:foreach代 阅读全文
posted @ 2020-02-25 13:52 Arbitrary233 阅读(3357) 评论(0) 推荐(0)
摘要: Student.java StudentMapper接口定义方法 StudentMapper配置文件进行相应配置 方式一(<set>和<if>结合) <update id="updateStu"> update student <!-- set会去掉拼接后的字符串多余的(逗号), 比如只修改id时则 阅读全文
posted @ 2020-02-25 00:26 Arbitrary233 阅读(973) 评论(0) 推荐(0)
摘要: StudentMapper接口中定义方法 StudentMapper配置文件进行相应的配置(这里没有写<otherwise>标签,接在<when>标签即可) <select id="getStuByChoose" resultType="student"> select * from student 阅读全文
posted @ 2020-02-25 00:05 Arbitrary233 阅读(429) 评论(0) 推荐(0)
摘要: Student.java: StudentMapper接口定义方法: StudentMapper配置文件进行配置 <select id="getStuByIf" resultType="student"> select * from student where <!-- test:判断表达式;里面使 阅读全文
posted @ 2020-02-24 22:22 Arbitrary233 阅读(543) 评论(0) 推荐(0)
摘要: 这个例子只是重在为了理解discriminator的使用 一对多的实体类Student.java 多对一的实体类College.java StudentMapper接口定义测试discriminator的方法 StudentMapper的sql配置文件中进行相对应接口方法配置 <!-- 测试鉴别器d 阅读全文
posted @ 2020-02-23 18:20 Arbitrary233 阅读(888) 评论(0) 推荐(0)
摘要: 举例注释中说明: <collection property="students" select="com.pxxy.bean.StudentMapper.getStusByColId" column="id" fetchType="lazy"> <!-- 多列值传递时:将多列的值封装成map进行传递 阅读全文
posted @ 2020-02-23 17:01 Arbitrary233 阅读(390) 评论(0) 推荐(0)