随笔分类 - 3.4 Mybatis系列
摘要:1.引入日志依赖包(pom.xml) 会自动引入log4j以及slf4j-api <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.5</version> </d
阅读全文
摘要:1.一级缓存 在mybatis中,一级缓存默认是开启的,并且无法关闭。一级缓存存在于SqlSession的生命周期中,在同一个SqlSession中查询时,mybatis会把执行的方法和参数生成缓存的键值,将键值和查询结果存入一个Map对象中。如果同一个SqlSession中执行的方法和参数完全一致
阅读全文
摘要:1.动态sql 场景:查询男性用户,如果输入了姓名,按姓名模糊查询 1.1.if 场景:查询男性用户,如果输入了姓名,则按姓名查询 定义接口: /** * 查询男性用户,如果输入了姓名,则按姓名查询 * @param name * @return */ List<User> queryUserLis
阅读全文
摘要:1.CRUD标签 1.1.select select – 书写查询sql语句 select中的几个属性说明: id属性:当前名称空间下的statement的唯一标识。必须。要求id和mapper接口中的方法的名字一致。 resultType:将结果集映射为java的对象类型。必须(和 resultM
阅读全文
摘要:mybatis-config.xml讲究严格的顺序,具体顺序遵循文档的顺序 1.properties属性读取外部资源 properties配置的属性都是可外部配置且可动态替换的,既可以在典型的 Java 属性文件中配置,亦可通过 properties 元素的子元素来传递。例如: <propertie
阅读全文
摘要:1.创建UserMapper接口 import java.util.List; public interface UserMapper { /** * 根据Id查询用户信息 */ public User queryUserById(Long id); /** * 查询所有用户信息 */ public
阅读全文
摘要:1.引入依赖(pom.xml) <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <dependenc
阅读全文
摘要:MyBatis介绍 官方文档 http://www.mybatis.org/mybatis-3/getting-started.html Mybaits整体架构
阅读全文
摘要:Q:mybatis框架里$和#的区别? A: 1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端把id值1,传入到后台的时候,就相当于 select id,name,age from student whe
阅读全文