mybatis的简单概括
前文:
mybatis封装大量JDBC连接配置,使程序员更加注重sql语句的编写。其核心为参数的输入和结果集的返回。
零、基本工作流程
一、全局配置文件
spring_mybatis。xml
二、子清单映射文件
mapper/user.xml
三、原生myabtis的API的使用
在实现类(service层)中需要使用到sqlSession及其携带的方法。
四、使用mapper代理的mybatis
使用dao接口,封装了sqlSession,直接调用dao接口即可
使用mapper层的前后对比
原生mybatis的API:
//实现类(service层)中:
sqlSession=MybatisUtil.getSqlSession();
user=(User)sqlSession.selectOne(
//对应子清单映射文件的完全限定名
"com.xx.yy.findUserById", id);
使用mapper层的mybatis
//实现类(service层)中:
User user = userMapper.findUserById(1);//查询id为1的user
//userMapper.java类中:
User findUserById(Integer id);
五、mybatis通用持久层
1.持久层对比
2.ssm中的通用持久层
3.在springboot中的通用持久层
pom.xml中配置
<!-- 通用Mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>2.3.2</version>
</dependency>
mybatis官方中文配置:http://www.mybatis.org/mybatis-3/zh/configuration.html
还没有评论,来说两句吧...