可以直接加载一个包文件名,将这个包里的所有*mapper.xml文件加载进来。

指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载;

必须按一定的标准:即xml文件和java文件的名字必须一样,且在同一个目录(包)内,如:userMapper.xml和userMapper.java两个文件在一个目录,且文件名相同;

在sqlMapConfig.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> <!-- 加载属性文件 -->
<properties resource="db.properties">
<!--properties中还可以配置一些属性名和属性值 -->
<!-- <property name="jdbc.driver" value=""/> -->
</properties>
<!-- 全局配置参数,需要时再设置 -->
<!-- <settings> </settings> --> <!-- 别名定义 -->
<typeAliases> <!-- 针对单个别名定义
type:类型的路径
alias:别名
-->
<!-- <typeAlias type="cn.itcast.mybatis.po.User" alias="user"/> -->
<!-- 批量别名定义
指定包名,mybatis自动扫描包中的po类,自动定义别名,别名就是类名(首字母大写或小写都可以)
-->
<package name="cn.itcast.mybatis.po"/> </typeAliases> <!-- 和spring整合后 environments配置将废除-->
<environments default="development">
<environment id="development">
<!-- 使用jdbc事务管理,事务控制由mybatis-->
<transactionManager type="JDBC" />
<!-- 数据库连接池,由mybatis管理-->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
</environments>
<!-- 加载 映射文件 -->
<mappers>
<mapper resource="sqlmap/User.xml"/> <!--通过resource方法一次加载一个映射文件 -->
<!-- <mapper resource="mapper/UserMapper.xml"/> --> <!-- 通过mapper接口加载单个 映射文件
遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中
上边规范的前提是:使用的是mapper代理方法
-->
<!-- <mapper class="cn.itcast.mybatis.mapper.UserMapper"/> --> <!-- 批量加载mapper
指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载
遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中
上边规范的前提是:使用的是mapper代理方法
-->
<package name="cn.itcast.mybatis.mapper"/> </mappers> </configuration>

在mybatis 中批量加载mapper.xml的更多相关文章

  1. DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载  吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...

  2. DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载    系列目录连接 DB数据源之Spr ...

  3. Mybatis 中延时加载

    1 为了处理N+1 问题,Mybatis 引入了延时加载功能,意义是一开始并不取出关联数据,只有当使用时,才发送sql语句去取. mybatis中两个全局设置 lazyLoadingEnabled 和 ...

  4. Mybatis热加载Mapper.xml

    开发的时候,写Mybatis Mapper.xml文件的时候,每次修改SQL都需要重启服务,感觉十分麻烦,于是尝试写了一个Mybatis的Mapper.xml热加载. 能在修改Mapper.xml之后 ...

  5. MyBatis使用懒加载mybatis-config.xml配置

    在mybatis-config.xml添加如下配置 <settings> <!--要使延迟加载生效必须配置下面两个属性--> <setting name="la ...

  6. MyBatis中动态加载where条件

    1.trim 2.where 1 = 1 where 1=1 <if test="beginDate !=null and beginDate !='' "> and ...

  7. 解决 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 以及MyBatis批量加载xml映射文件的方式

    错误 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 的出现,意味着项目需要xml文件来 ...

  8. 精尽MyBatis源码分析 - MyBatis初始化(二)之加载Mapper接口与XML映射文件

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  9. (转)MyBatis框架的学习(四)——Mapper.xml文件中的输入和输出映射以及动态sql

    http://blog.csdn.net/yerenyuan_pku/article/details/71893689 前面对MyBatis框架的学习中,我们对Mapper.xml映射文件多少有些了解 ...

随机推荐

  1. Android笔记——UI开发

    概述: 布局(Layout)的概念是针对Activity的,Activity就是布满整个Android设备的窗体或者悬浮于其它窗体上的交互界面.在一个应用程序中通常由多个Activity构成.每一个须 ...

  2. tornado ThreadPoolExecutor

    import os import sys import time import tornado.httpserver import tornado.ioloop import tornado.opti ...

  3. python __set__ __get__ __delete__

    class Attr(object): def __init__(self,attrname,attrtype): self.attrname=attrname self.attrtype=attrt ...

  4. U3D实现与iOS交互

    原地址:http://502317120.blog.51cto.com/4062300/1077733 在开发中有很多情况下会用到U3D调用iOS中的函数. 例如在U3D中,我们需要调用到一个iOS ...

  5. ionic build android log

    RubertdeMacBook-Pro:~ Rubert$ ionic build android Current working directory is not a Cordova-based p ...

  6. 类非静态成员的函数指针 的使用 Function pointer of a non-static member function of a class

    you can get the pointer of the method, but it has to be called with an object typedef void (T::*Meth ...

  7. c++11 学习

    #include <iostream> // std::cout #include <functional> // std::ref #include <thread&g ...

  8. hibernate session的load和get方法

    @Test public void testLoad() {     Session session = sessionFactory.getCurrentSession();     session ...

  9. test_login

    import unittest,requestsimport ddtfrom BeautifulReport import BeautifulReport as bffrom urllib impor ...

  10. Layui 弹出层组件——layer的模块化开发实例应用

    Layui 弹出层组件——layer的模块化开发实例应用 1.首先在package.json中引入layer组件依赖 2.在源码中应用这个依赖 3.在源码中编写代码应用此组件 4.效果验证:点击日历上 ...