随笔分类 -  Mybatis

摘要:一个SqlSession就类似一个数据库连接 二级缓存的含义 需要手动开启 二级缓存是基于 mapper文件的namespace级别的缓存,也就是说,只要namespace相同,多个sqlSession可以共享一个mapper中的二级缓存区域。 开启二级缓存 1、在配置文件中 开启二级缓存的总开关 阅读全文
posted @ 2021-03-11 16:06 林被熊烟岛 阅读(92) 评论(0) 推荐(0)
摘要:1.如果参数是英文数字混杂的 使用forEach循环分割 <select id="selectNetSatutration" resultMap="BaseResultMap" parameterType="NetSatutrationVo" > SELECT <include refid="Bas 阅读全文
posted @ 2020-11-26 16:58 林被熊烟岛
摘要:使用when、otherwise可以实现类似if else的效果 <insert id="insertTest" parameterType="com.demo.entity.TBtest"> INSERT INTO table ( xx, xxx, xx, xx ) <choose> <when 阅读全文
posted @ 2020-11-13 15:38 林被熊烟岛 阅读(319) 评论(0) 推荐(0)
摘要:使用mybatis进行日期格式插入的时候发现没有时分秒 在pojo中日期格式使用java.util.Date 不要使用Java.sql.Date 否则查询出来的时候 显示也会有问题 但是在xml中指定了jdbcType jdbcType 指定为DATE的时候,数据库只会保存 年月日 jdbcType 阅读全文
posted @ 2020-07-07 17:50 林被熊烟岛 阅读(1704) 评论(0) 推荐(0)
摘要:单条插入(oracle)返回主键 通常我们执行一个inser语句,即使有返回,也只是会返回影响了多少条数据 @insert("insert into t_user (id,name) values (suser.nextval,#{item.name,jdbcType=VARCHAR})") voi 阅读全文
posted @ 2020-05-13 23:58 林被熊烟岛 阅读(621) 评论(0) 推荐(0)
摘要:mybatis中的#和$的区别: 1、#将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号。如:where username=#{username},如果传入的值是111,那么解析成sql时的值为where username="111", 如果传入的值是id,则解析成的sql为where 阅读全文
posted @ 2020-05-12 23:55 林被熊烟岛 阅读(2533) 评论(0) 推荐(0)
摘要:Mybatis的分页查询 (1)无条件的分页 mapper文件配置和Java代码实现 <!-- 传入的参数类型为map,此时无需使用map.get("key")去获得实际值,只需填入key值便可 --> <select id="findByPage" parameterType="map" resu 阅读全文
posted @ 2020-04-25 12:43 林被熊烟岛 阅读(815) 评论(0) 推荐(0)
摘要:XML批量查询 collection: 指定要遍历的集合(三种情况 list,array,map) !!!!在这种使用注解sql的情况下,这里请填写mapper方法中集合的名称 item:将当前遍历出的元素赋值给指定的变量 (相当于for循环中的i)separator:每个元素之间的分隔符 open 阅读全文
posted @ 2020-04-23 23:51 林被熊烟岛 阅读(308) 评论(0) 推荐(0)
摘要:引入pom依赖: <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.0</version> </dependency> 阅读全文
posted @ 2020-03-29 18:31 林被熊烟岛 阅读(220) 评论(0) 推荐(0)