1.applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- 加载配置文件 --><context:property-placeholder location="classpath:db.properties"/><!-- dbcp 连接池 --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driver}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="maxActive" value="10" /><property name="maxIdle" value="5" /></bean><!-- mybatis的工厂其中要注入 1连接池(dataSource) 2.--><bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"></property><property name="configLocation" value="classpath:SqlMapConfig.xml"></property></bean><!-- userdao 原始开发--><bean id="userDao" class="com.itheima.dao.UserDaoImpl"><property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property></bean><!-- mapper接口动态代理 --><!-- <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="sqlSessionFactory" ref="sqlSessionFactoryBean"></property>指定MapperFactoryBean要实现的接口<property name="mapperInterface" value="com.itheima.mapper.UserMapper"></property></bean> --><!-- mapper接口动态代理  增强版:扫描--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 基本包   自动实现该包(com.itheima.mapper)下的所有接口--><property name="basePackage" value="com.itheima.mapper"></property></bean>
</beans>

2.SqlMapConcig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- 设置别名 --><typeAliases><!-- 2. 指定扫描包,会把包内所有的类都设置别名,别名的名称就是类名,大小写不敏感 --><package name="com.itheima.domain" /></typeAliases><mappers><package name="com.itheima.mapper"/></mappers>
</configuration>

3.xxxMapper.xml

<?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="com.itheima.mapper.UserMapper"><!-- 根据用户id查询 --><select id="queryUserById" parameterType="int" resultType="user">select * from user where id = #{id}</select></mapper>

转载于:https://www.cnblogs.com/houchen/p/10726703.html

mybatis整合spring下的的各种配置文件相关推荐

  1. MyBatis整合Spring原理分析

    目录 MyBatis整合Spring原理分析 MapperScan的秘密 简单总结 假如不结合Spring框架,我们使用MyBatis时的一个典型使用方式如下: public class UserDa ...

  2. Mybatis——Mybatis整合Spring详解

    mybatis-spring官网 1. MyBatis整合Spring实现 我们首先实现MyBatis和Spring的整合操作. 1.1 添加相关的依赖 这些是整合的依赖,不包括其他分页插件等依赖. ...

  3. MyBatis整合Spring的实现(2)

    2019独角兽企业重金招聘Python工程师标准>>> 分析 MyBatis整合Spring的实现(1)中代码实现的4.1可以知道,XMLConfigBuilder类读取MyBati ...

  4. (转)MyBatis框架的学习(六)——MyBatis整合Spring

    http://blog.csdn.net/yerenyuan_pku/article/details/71904315 本文将手把手教你如何使用MyBatis整合Spring,这儿,我本人使用的MyB ...

  5. 【Mybatis+spring整合源码探秘】--- mybatis整合spring事务原理

    文章目录 1 mybatis整合spring事务原理 1 mybatis整合spring事务原理 本篇文章不再对源码进行具体的解读了,仅仅做了下面一张图: 该图整理了spring+mybatis整合后 ...

  6. MyBatis(五)MyBatis整合Spring原理分析

    前面梳理了下MyBatis在单独使用时的工作流程和关键源码,现在看看MyBatis在和Spring整合的时候是怎么工作的 也先从使用开始 Spring整合MyBatis 1.引入依赖,除了MyBati ...

  7. mybatis 整合spring之mapperLocations配置的问题

    今天尝试spring整合mybatis时遇到这么一个问题,就是在配置sqlSessionFactory时是否要配置mapperLocations的问题. <bean id="sessi ...

  8. Mybaits整合Spring自动扫描 接口,Mybaits配置文件.xml文件和Dao实体类

    1.转自:https://blog.csdn.net/u013802160/article/details/51815077 1 <?xml version="1.0" en ...

  9. Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)

    http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...

最新文章

  1. python3.0视频教程_python中文视频教程(全38集),全套视频教程学习资料通过百度云网盘下载...
  2. SpirngMVC jsp页面空指针
  3. Python使用matplotlib进行3D可视化分析:3d柱状图、3d直方图、3d线框图、3d曲面图、3d翼面图(莫比乌斯环)
  4. python入门教程 官方-Python自学入门?
  5. linux——管理系统设备之LVM的管理
  6. C#中读取“已注册的文件类型”的图标及读取指定文件图标的方法 (转)
  7. const与指针变量
  8. Linux 线程控制
  9. Oracle 闪回特性(Flashback Query、Flashback Table)
  10. caffe教程笔记《Blobs, Layers, and Nets》
  11. 修改.class文件内容
  12. VMware提示“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”打不开
  13. html文件做屏保win10,win10系统把屏保设置为桌面壁纸的处理方法
  14. mysql导数据出现Incorrect string value: '\xF0\x9F\x90\x82'报错
  15. 使用笔记本的不良习惯
  16. 6.Servlet、JSP总结
  17. 递归算法:爬楼梯问题
  18. 阿里云域名申请 + 七牛云CDN加速
  19. JimuReport - 积木报表(一款免费Web报表工具)
  20. Android产品定制多语言

热门文章

  1. 关于在本地idea当中提交spark代码到远程的错误总结(第二篇)
  2. win7+centos7.2双系统安装
  3. 并发Goroute、定时器、信号处理、单元测试
  4. 修复使用codeXmlDocument/code加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误...
  5. css布局详解(一)——盒模型
  6. emacs org mode 中的标签全参考
  7. 21.使用委托表达回调
  8. IPC 之 Binder 初识
  9. C#设计模式之十七中介者模式(Mediator Pattern)【行为型】
  10. SIGTERM等信号含义【转】