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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值