Mybatis【与Spring整合】

Mybatis与Spring的整合 10.1 整合环境搭建 Spring和MyBatis的整合主要涉及准备所需的JAR包和编写配置文件,下面将详细介绍。 10.1.1 准备所需的JAR包 要实现MyBatis与Spring的整合,需要这两个框架相关的JAR包,除此之外,还需要其他的JAR包来配合使用。 1.所需Spring框架的JAR包 Spring框架所需要准备的JAR包共10个,其中包括4个核心模块JAR、AOP开发使用的JAR、JDBC和事务的JAR(其中核心容器依赖的commons-logging的JAR在MyBatis框架的lib包 阅读详情

Mybatis第五篇【Mybatis与Spring整合】

既然我们已经学了Mybatis的基本开发了,接下来就是Mybatis与Spring的整合了!

以下使用的是Oracle数据库来进行测试

导入jar包

创建表

create table emps(  eid number(5) primary key,  ename varchar2(20),  esal number(8,2),  esex varchar2(2));table emps(
 eid number(5) primary key,
 ename varchar2(20),
 esal number(8,2),
 esex varchar2(2)
);

创建实体

package entity;/** * 员工 * @author AdminTC */public class Emp {    private Integer id;    private String name;    private Double sal;    private String sex;    public Emp(){}    public Emp(Integer id, String name, Double sal, String sex) {        this.id = id;        this.name = name;        this.sal = sal;        this.sex = sex;    }    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public Double getSal() {        return sal;    }    public void setSal(Double sal) {        this.sal = sal;    }    public String getSex() {        return sex;    }    public void setSex(String sex) {        this.sex = sex;    }}

/**
* 员工
* @author AdminTC
*/

public class Emp {
   private Integer id;
   private String name;
   private Double sal;
   private String sex;
   public Emp(){}
   public Emp(Integer id, String name, Double sal, String sex) {
       this.id = id;
       this.name = name;
       this.sal = sal;
       this.sex = sex;
   }
   public Integer getId() {
       return id;
   }
   public void setId(Integer id) {
       this.id = id;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public Double getSal() {
       return sal;
   }
   public void setSal(Double sal) {
       this.sal = sal;
   }
   public String getSex() {
       return sex;
   }
   public void setSex(String sex) {
       this.sex = sex;
   }
}

创建实体与表的映射文件

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="empNamespace">    <resultMap type="entity.Emp" id="empMap">        <id property="id" column="eid"/>        <result property="name" column="ename"/>        <result property="sal" column="esal"/>        <result property="sex" column="esex"/>    </resultMap>        <!-- 增加员工 -->    <insert id="add" parameterType="entity.Emp">        insert into emps(eid,ename,esal,esex) values(#{id},#{name},#{sal},#{sex})    </insert></mapper>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="empNamespace">

   <resultMap type="entity.Emp" id="empMap">
       <id property="id" column="eid"/>
       <result property="name" column="ename"/>
       <result property="sal" column="esal"/>
       <result property="sex" column="esex"/>
   </resultMap>    

   <!-- 增加员工 -->
   <insert id="add" parameterType="entity.Emp">
       insert into emps(eid,ename,esal,esex) values(#{id},#{name},#{sal},#{sex})
   </insert>

</mapper>

创建Mybatis映射文件配置环境

数据库的信息交由Spring管理!Mybatis配置文件负责加载对应映射文件即可

    <mappers>        <mapper resource="zhongfucheng/entity/EmpMapper.xml"/>    </mappers></configuration>
       <mapper resource="zhongfucheng/entity/EmpMapper.xml"/>

   </mappers>
</configuration>

配置Spring核心过滤器【也是加载总配置文件】

    <!-- 核心springmvc核心控制器 -->    <servlet>        <servlet-name>DispatcherServlet</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:spring.xml</param-value>        </init-param>    </servlet>    <servlet-mapping>        <servlet-name>DispatcherServlet</servlet-name>        <url-pattern>*.action</url-pattern>    </servlet-mapping>
   <servlet>
       <servlet-name>DispatcherServlet</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:spring.xml</param-value>
       </init-param>
   </servlet>
   <servlet-mapping>
       <servlet-name>DispatcherServlet</servlet-name>
       <url-pattern>*.action</url-pattern>
   </servlet-mapping>

配置数据库信息、事务

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"       xmlns:aop="http://www.springframework.org/schema/aop"       xmlns:context="http://www.springframework.org/schema/context"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">    <!-- 配置C3P0连接池,目的:管理数据库连接 -->    <bean id="comboPooledDataSourceID" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>        <property name="jdbcUrl" value="jdbc:oracle:thin:@127.0.0.1:1521:ZHONGFUCHENG"/>        <property name="user" value="scott"/>        <property name="password" value="tiger"/>    </bean>    <!-- 配置SqlSessionFactoryBean,目的:加载mybaits配置文件和映射文件,即替代原Mybatis工具类的作用 -->    <bean id="sqlSessionFactoryBeanID" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="configLocation" value="classpath:mybatis.xml"/>        <property name="dataSource" ref="comboPooledDataSourceID"/>    </bean>    <!-- 配置Mybatis的事务管理器,即因为Mybatis底层用的是JDBC事务管事器,所以在这里依然配置JDBC事务管理器 -->    <bean id="dataSourceTransactionManagerID" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="comboPooledDataSourceID"/>    </bean>    <!-- 配置事务通知,即让哪些方法需要事务支持 -->    <tx:advice id="tx" transaction-manager="dataSourceTransactionManagerID">        <tx:attributes>            <tx:method name="*" propagation="REQUIRED"/>        </tx:attributes>    </tx:advice>    <!-- 配置事务切面,即让哪些包下的类需要事务 -->    <aop:config>        <aop:pointcut id="pointcut" expression="execution(* zhongfucheng.service.*.*(..))"/>        <aop:advisor advice-ref="tx" pointcut-ref="pointcut"/>    </aop:config>    <!--扫描注解-->    <context:component-scan base-package="zhongfucheng"/></beans>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



   <!-- 配置C3P0连接池,目的:管理数据库连接 -->
   <bean id="comboPooledDataSourceID" class="com.mchange.v2.c3p0.ComboPooledDataSource">
       <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
       <property name="jdbcUrl" value="jdbc:oracle:thin:@127.0.0.1:1521:ZHONGFUCHENG"/>
       <property name="user" value="scott"/>
       <property name="password" value="tiger"/>
   </bean>


   <!-- 配置SqlSessionFactoryBean,目的:加载mybaits配置文件和映射文件,即替代原Mybatis工具类的作用 -->
   <bean id="sqlSessionFactoryBeanID" class="org.mybatis.spring.SqlSessionFactoryBean">
       <property name="configLocation" value="classpath:mybatis.xml"/>
       <property name="dataSource" ref="comboPooledDataSourceID"/>
   </bean>


   <!-- 配置Mybatis的事务管理器,即因为Mybatis底层用的是JDBC事务管事器,所以在这里依然配置JDBC事务管理器 -->
   <bean id="dataSourceTransactionManagerID" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <property name="dataSource" ref="comboPooledDataSourceID"/>
   </bean>

   <!-- 配置事务通知,即让哪些方法需要事务支持 -->
   <tx:advice id="tx" transaction-manager="dataSourceTransactionManagerID">
       <tx:attributes>
           <tx:method name="*" propagation="REQUIRED"/>
       </tx:attributes>
   </tx:advice>

   <!-- 配置事务切面,即让哪些包下的类需要事务 -->
   <aop:config>
       <aop:pointcut id="pointcut" expression="execution(* zhongfucheng.service.*.*(..))"/>
       <aop:advisor advice-ref="tx" pointcut-ref="pointcut"/>
   </aop:config>

   <!--扫描注解-->
   <context:component-scan base-package="zhongfucheng"/>


</beans>

创建Dao、Service、Action

@Repositorypublic class EmpDao {    @Autowired    private SqlSessionFactory sqlSessionFactory;    /**     * 增加员工     */    public void add(Emp emp) throws Exception {        SqlSession sqlSession = sqlSessionFactory.openSession();        sqlSession.insert("empNamespace.add", emp);        sqlSession.close();    }}
public class EmpDao {
   @Autowired
   private SqlSessionFactory sqlSessionFactory;
   /**
    * 增加员工
    */

   public void add(Emp emp) throws Exception {
       SqlSession sqlSession = sqlSessionFactory.openSession();
       sqlSession.insert("empNamespace.add", emp);
       sqlSession.close();
   }


}
@Servicepublic class EmpService {    @Autowired    private zhongfucheng.dao.EmpDao empDao;    public void addEmp(Emp emp) throws Exception {        empDao.add(emp);    }}
public class EmpService {


   @Autowired
   private zhongfucheng.dao.EmpDao empDao;
   public void addEmp(Emp emp) throws Exception {
       empDao.add(emp);
   }
}
@Controller@RequestMapping("/emp")public class EmpAction {    @Autowired    private EmpService empService;    @RequestMapping("/register")    public void register(Emp emp) throws Exception {        empService.addEmp(emp);        System.out.println("注册成功");    }}
@RequestMapping("/emp")
public class EmpAction {

   @Autowired
   private EmpService empService;

   @RequestMapping("/register")
   public void register(Emp emp) throws Exception {
       empService.addEmp(emp);
       System.out.println("注册成功");
   }

}

JSP页面测试

<%@ page language="java" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>员工注册</title>  </head>  <body>    <form action="${pageContext.request.contextPath}/emp/register.action" method="POST">        <table border="2" align="center">            <tr>                <th>编号</th>                <td><input type="text" name="id"></td>            </tr>            <tr>                <th>姓名</th>                <td><input type="text" name="name"></td>            </tr>            <tr>                <th>薪水</th>                <td><input type="text" name="sal"></td>            </tr>            <tr>                <th>性别</th>                <td>                    <input type="radio" name="sex" value="男"/>男                    <input type="radio" name="sex" value="女" checked/>女                </td>            </tr>            <tr>                <td colspan="2" align="center">                    <input type="submit" value="注册"/>                </td>            </tr>        </table>    </form>       </body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
   <title>员工注册</title>
 </head>
 <body>
   <form action="${pageContext.request.contextPath}/emp/register.action" method="POST">
       <table border="2" align="center">
           <tr>
               <th>编号</th>
               <td><input type="text" name="id"></td>
           </tr>
           <tr>
               <th>姓名</th>
               <td><input type="text" name="name"></td>
           </tr>
           <tr>
               <th>薪水</th>
               <td><input type="text" name="sal"></td>
           </tr>
           <tr>
               <th>性别</th>
               <td>
                   <input type="radio" name="sex" value="男"/>男
                   <input type="radio" name="sex" value="女" checked/>女
               </td>
           </tr>
           <tr>
               <td colspan="2" align="center">
                   <input type="submit" value="注册"/>
               </td>
           </tr>
       </table>
   </form>    
 </body>
</html>

总结

如果文章有错的地方欢迎指正,大家互相交流。习惯在微信看技术文章,想要获取更多的Java资源的同学,可以关注微信公众号:Java3y


MyBatis与Spring整合 Mybatis和spring整合后的事务管理是由Spring管理的,事务管理器依然使用jdbc的事务管理器。mapper是交给spring管理了,但是如果mapper多了需要一个个设置,也比较繁琐;2)添加spring配置文件applicationContext.xml到resources/spring资源配置目录下。注意:因为这里没有整合web内容,所以没有web.xml文件,也就不需要在其中添加spring 的监听器。 阅读详情

相关推荐

Spring 如何整合 Mybatis 的详细讲解

文章目录一、jar 包介绍1、 Mybatis 的 jar 包:2、 Mybatis 整合 Spring 的 jar 包:3、 Spring 的 jar 包:4、 数据库驱动 jar 包:二、搭建环境1、 创建项目2、 添加 jar 包3、 创建配置文件4、 添加 log4j 配置文件5、 创建映射配置文件与接口6、 创建实体类7、 创建业务层三、配置 Spring 与 Mybatis 整合1、 配置解析 properties 文件1.1、 添加 db.properties 文件1.2、 修改 Spring

康康要加油的博客 3083

Spring——Spring整合MyBatis

Spring——Spring整合MyBatis

贝尔摩德苦艾酒 2万+

无刷电机控制避坑指南:六步换向 vs FOC的5个关键差异

本文深入对比了无刷电机控制中六步换向与FOC(磁场定向控制)的五大核心差异。从控制逻辑、性能表现、效率能耗、硬件成本到应用场景,详细解析了FOC如何通过矢量合成实现平滑的正弦波控制与更高效率,而六步换向则以低成本实现简单开关驱动。旨在帮助工程师根据项目需求,在性能、成本与复杂度间做出最佳选择。

weixin_29216957的博客 519

Spring 整合Mybatis。

▶ Junit运行后是基于Spring环境运行的,所以Spring提供了一个专用的类运行器,这个务必要设置,这个类运行器就在Spring的测试专用包中提供的,导入的坐标就是这个东西`SpringJUnit4ClassRunner`○ SqlSessionFactoryBean是前面我们讲解FactoryBean的一个子类,在该类中将SqlSessionFactory的创建进行了封装,简化对象的创建,我们只需要将其需要的内容设置即可。在运行类中,从IOC容器中获取Service对象,调用方法获取结果。

yzh2776680982的博客 2363

VSCode + Latex 配置

1. 安装VSCode VSCode下载 next,next就安装好了。 2. 配置VSCode 2.1 安装LaTeX Workshop插件 install,安装LaTeX Workshop插件 2.2 修改 user setting 点击左下角,进入用户设置 点击上图标记的部分,选择 打开settings.json 具体配置文件如下: { "latex-workshop.la...

一只特立独行的猪 10万+

win10自动修复-无限循环【通用完美】超简单解决办法

2020.02.14今个我的笔记本电脑(Thinkpad Carbon 7 X1)(win10)早晨起来发现蓝屏,上面显示自动修复失败,重启后依然自动修复失败,不断手动重启,始终是修复失败。然后上网开始搜集资料找解决办法。 前边介绍关闭自动修复,如何找出错文件的方法;如果想看最终解决办法,直接看第三部分 上网就会发现这种现象很常见,同时是电脑自动安装系统更新,或者安装某些驱动出现。解决办法也大...

y15941300574的博客 19万+

Spring:Spring整合Mybatis

对其中分析,看看哪些可以交给spring管理:Mybatis程序核心对象分析从图中可以获取到,真正需要交给Spring管理的是整合Mybatis,就是将Mybatis用到的内容交给Spring管理,分析下配置文件第一行读取外部properties配置文件,Spring有提供具体的解决方案,需要交给Spring第二行起别名包扫描,为SqlSessionFactory服务的,需要交给Spring第三行主要用于做连接池,Spring之前我们已经整合了Druid连接池,这块也需要交给Spring。

qq_41187116的博客 1524

【AI生成】市面上主流自组网厂家的技术及市场研究

经过对全球自组网产业技术特征与市场格局的系统分析,本文得出以下核心结论:技术演进呈现智能化与融合化双轨路径 当前自组网技术创新已突破传统组网架构局限,形成"协议优化-架构创新-场景适配"的递进式发展路径。国际厂商聚焦智能算法应用,如Silvus采用深度学习实现动态拓扑优化,传输时延较传统方案降低37%;国内企业则侧重异构网络融合,中国移动设计院提出的5G LAN架构使工业场景通信可靠性提升至99.99%。

qq_31310977的博客 1700

Spring和Mybatis的整合

spring和mybatis的整合,回顾之前的笔记

beautifulsen的博客 6026

《HiVT: Hierarchical Vector Transformer for Multi-Agent Motion Prediction》论文阅读之HiVT

目录摘要1.介绍2.相关工作3.方法3.1. 总体框架3.2 场景表示 3.3 分层向量Transformer3.3.1 局部编码器3.3.2 全局交互模块3.3.3 多模态未来解码器3.4 训练4.实验4.1 实验设置4.2 消融研究 4.3. 结果5.结论 准确预测周围交通参与者的未来运动对于自动驾驶车辆的安全至关重要。最近,矢量化方法由于能够捕捉交通场景中的复杂交互而在运动预测领域占据主导地位。然而,现有的方法忽略了问题的对称性并且受到昂贵的计算成本的影响,面临着在不牺牲预测性能的情况

Gavinmiaoc的博客 3345

【75】OpenCV C++实战篇——OpenCV 图像拼接、全景拼接(教程合集)

本文整理了OpenCV实现图像拼接的技术教程合集,涵盖C++和Python两种语言实现方案。图像拼接技术旨在将多张重叠图像融合为无缝全景图,既扩大视角又保持高分辨率。内容包含水平矫正等关键步骤(附对比效果图),提供多个实战案例的完整代码和详细讲解,涉及单应性矩阵、图像变换等核心技术。不同案例展示了从两张到多张图像的拼接效果,适合不同层次的学习者参考实践。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 530

【Spring】Spring 整合 MyBatis

在实际项目开发中,将 Spring 和 MyBatis 进行整合可以提高开发效率、简化配置、增强事务管理和可维护性,同时利用 Spring 的强大功能来提升系统的稳定性。这里从独立使用 MyBatis 开始,逐步实现与 Spring 框架的整合。

zzy_NIC的博客 1446

Open Dynamics Engine(ODE)物理引擎基础教程(I)——特点介绍

下一教程 Open Dynamics Engine(ODE)物理引擎基础教程(II)——相关概念 (在这一教程中将学习刚体、关节、碰撞的概念在ODE中的特点) 本文结构引言介绍特点使用ODE总结 引言 本文翻译自ODE官方教程英文版,有些地方增加了自己的理解。这一节介绍ODE的相关概念。 基础教程英文原版链接【http://ode.org/wiki/index.php?title=Manua...

腿足机器人领域 1683

Spring与mybatis整合

spring与mybatis整合spring与mybatis整合mybatis是一个持久层框架,实现了对数据库操作的封装。可以单独使用mybatis,使用mybatis主要包括以下几个部分:1、编写各个映射文件xxMapper.xml,以及对应的各个接口文件xxMapper.java。

cxbtdd的博客 1481

Electron vue3 - 使用SerialPort与串口交互教程,计算机串行端口(COM口、USB转串口等)进行通信连接读取或写入Arduino、单片机、PLC、扫码枪、打印机、老式调制解调器!

实战Electron使用SerialPort与串口交互详细全过程,Electron-vue3与串口交互示例,Electron vue使用serialport实现串口交互通讯,Electron-vue使用serialport连接本地串口,electron-vue 台称串口对接 SerialPort,electron串口调试工具,electron+vue+serialport实现串口通信,串口通信serialport使用和调试,electron-vue使用serialport串口通信及踩过的坑(已解决!)ele

🏆 前端领域优质创作者 4648

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Mybatis整合Spring详解

mybatis最常见的用法是整合进spring项目中,组成ssm项目(spring+springMVC+mybatis),而springboot也是java生态中使用量最大的框架,本文介绍mybatis如何与spring和springboot进行整合。

qq_43408971的博客 1138

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Spring整合MyBatis——超详细

(2)将MyBatis的SqlSessionFactory交给Spring IoC容器创建并管理,使用spring-mybatis整合jar包中提供的SqlSessionFactoryBean类代替项目中的MyBatisUtil工具类。映射文件中的select 的id为findUserList,因此接口文件中的方法名就为findUserList,出现红线也不用着急,运行的时候不影响。把上方的mapper接口文件都自动注入到IoC容器中,实现类Bean的名称默认为接口类名的首字母小写。选择自动导入jar包。

web15085415935的博客 1709

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Spring整合Mybatis

需维护独立的mybatis-config.xml文件:数据源、事务、映射配置分散在不同文件:修改配置需要重启应用。

2302_77465225的博客 1919

Spring与Mybatis整合

一、 MyBatis与Spring的集成 在学习mybatis配置时,对于mybatis-config配置的时候我们发现,大致是需要配置三个方面:setting、datasource、mappers 而mybatis的setting往往使用默认配置,所以我们经常配置datasource数据源与mappers映射,但学习spring之后发现,对于datasource的配置交由spring进行管理,所以在spring与mybatis整合后mybatis的配置文件中将不需要配置datasource,mybatis

Amour恋空的博客 1433

Spring之整合Mybatis底层源码

有很多框架需要与Spring进行整合,而整合的核心思路就是把其他框架所产生的对象放到Spring容器中,让其成为一个bean。

qq_43456605的博客 1422

Spring整合MyBatis详解

企业级开发中,Spring(负责依赖管理和事务控制)与MyBatis(负责持久层操作)的整合是主流方案,本文我将详细讲解Spring整合MyBatis的完整流程,这种整合能充分发挥两者优势:Spring的IoC容器管理MyBatis的核心组件,AOP实现事务控制;MyBatis简化数据库操作。

aa_hdkf_vg的博客 1577

Mybatis的spring整合

mybatis和spring的整合

AYGZC233的博客 1555

spring整合mybatis原理

我们先来实现MyBatis和Spring的整合操作。

m0_73671382的博客 1332

Spring 整合 Mybatis

Spring整合Mybatis 详细配置及源码分析

2301_78163113的博客 269

spring整合Mybatis(Mybatis-Spring)

什么是 MyBatis-Spring? MyBatis-Spring 会帮助你将 MyBatis 代码无缝地整合到 Spring 中。它将允许 MyBatis 参与到 Spring 的事务管理之中,创建映射器 mapper 和 SqlSession 并注入到 bean 中,以及将 Mybatis 的异常转换为 Spring 的 DataAccessException。 最终,可以做到应用代码不依赖于 MyBatis,Spring 或 MyBatis-Spring。 准备工作 导入maven依赖 <

weixin_45608165的博客 196

Spring+Mybatis的整合

所以,该整合,只需要将 SqlSessionFactory 的对象生成器 SqlSessionFactoryBean 注册在 Spring 容器中,再将其注入给 Dao 的实现类即可完成整合。实现 Spring 与 MyBatis 的整合常用的方式:扫描的 Mapper 动态代理 Spring 像插线板一样,mybatis 框架是插头,可以容易的组合到一起。使用mybatis,需要创建mybatis框架中的某些对象,使用这些对象,就可以使用mybatis提供的功能了。在基础的 MyBatis 中,通过。

weixin_65824274的博客 2110
上一篇: Mybatis面试题
下一篇: Mybatis【配置文件】
Java3y
Java3y 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 1万+粉丝 509原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址