MyBatis在Spring配置文件中注册

news/2025/2/25 14:08:44

Spring集成Mybatis的配置文件中,

1.引入jdbc.properties,是为了注册数据源。

2.注册数据源是为了引入SqlSessionFactoryBean。

3.SqlSessionFactoryBean才是真正Spring与Mybatis的桥梁,引入SqlSessionFactoryBean是为了操作Mapper。

4.所以第四步,要引入扫描Mapper。

<?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: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/beans/spring-context.xsd
">

<!--    这个文件是Spring集成mybatis-->


<!--    引入jdbc.properties-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
<!--    引入数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"> </property>
        <property name="url" value="${jdbc.url}"> </property>
        <property name="username" value="${jdbc.username}"> </property>
        <property name="password" value="${jdbc.password}"> </property>
    </bean>

<!--    引入SqlSessionFactoryBean-->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--            配置数据源-->
        <property name="dataSource" ref="dataSource"/>
<!--        加载mybatis核心配置 目的是myBatis 的核心配置交由 Spring 容器管理 -->
        <property name="configuration" value="classpath:SqlMapCofig.xml"/>
        <property name="typeAliasesPackage" value="org.mini.pojo"/>
    </bean>

<!--    扫描mapper-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="org.mini.mapper"/>
    </bean>

</beans>


http://www.niftyadmin.cn/n/5865583.html

相关文章

angular登录页

说明:登录 logindialog 效果图&#xff1a; step1: import { Component } from angular/core; import {FormGroup, FormControl, Validators, FormsModule, ReactiveFormsModule} from angular/forms; import { MatDialog } from angular/material/dialog; import { AlertDia…

FFmpeg进化论:从av_register_all手动注册到编译期自动加载的技术跃迁

介绍 音视频开发都知道 FFmpeg,因此对 av_register_all 这个 API 都很熟悉,但ffmpeg 4.0 版本开始就已经废弃了,是旧版本中用于全局初始化的重要接口。 基本功能 核心作用:av_register_all() 用于注册所有封装器(muxer)、解封装器(demuxer)和协议处理器(protocol),…

什么是 OCP 数据库专家

OCP 即 Oracle Certified Professional&#xff0c;Oracle 认证专业人员&#xff0c;代表持证人在 Oracle 数据库领域具备专业的技能和知识。获得 OCP 数据库专家认证意味着你在 Oracle 数据库管理、开发、优化等方面达到了较高的水平&#xff0c;能够独立承担复杂的数据库相关…

**模式的好处 (设计模式)

what’s up !? 这样整理下发现更容易理解设计模式了 学习嘛&#xff0c;就是拿着 rua 横着rua 竖着rua 前面rua 后面rua 【’ _ ’ 】 目录 简单工厂模式工厂模式抽象工厂模式单例模式建造者模式原型模式代理模式适配器 模式桥梁 模式装饰 模式门面 模式 &#xff08;也叫 外…

前端(layui表单对应行颜色、登陆页面、轮播)

1&#xff1a;动态获取数据根据数据的不同改变对应行颜色&#xff08;JavaScript&#xff09; done: function (res, curr, count) {console.log(res);// 检查返回的数据是否包含code字段&#xff0c;并且code为0if (res.code "0") {// 数据加载成功console.log(…

免费PDF工具

Smallpdf.com - A Free Solution to all your PDF Problems Smallpdf - the platform that makes it super easy to convert and edit all your PDF files. Solving all your PDF problems in one place - and yes, free. https://smallpdf.com/#rappSmallpdf.com-解决您所有PD…

Postman操作(接口测试、生成测试报告、MockServer等)

文章目录 前言Postman简介Postman下载和安装下载安装注册与登录 Postman工具介绍界面说明发送第一个请求1. 创建一个工程目录2. 创建collection合集3. 创建一个接口请求4. 输入接口请求参数5. 发送请求 CollectionFolderRequset请求基础功能响应 全局变量、集合变量、环境变量全…

字符型验证码自动识别与填充提交——OCR浏览器插件的完整实现

【创作不易&#xff0c;切勿抄袭&#xff0c;转载请注明出处&#xff0c;侵权必究】 本文概览 本文结合开源的tesseract OCR库共尝试三种方法实现了字符型验证码识别与填充提交浏览器插件&#xff08;非通用型&#xff0c;具体得根据自己网页内容改造&#xff0c;可借鉴本文方…