1.MyBatis配置文件(mybatis-config)

<?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>
<mappers></mappers>
</configuration>

2.Spring配置sqlSessionFactory

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:conf/mybatis-config.xml"
p:mapperLocations="classpath:com/**/dao/sql/*xml"/>

configLocation:MyBatis配置文件路径;

SqlSessionFactoryBean提供了mapperLocations属性,支持扫描式加载SQL映射文件;

3.Spring配置MapperScannerConfigurer

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.dogstore.dao"/>

MapperScannerConfigurer将扫描basePackage所指定的报下所有接口类,如果他们在SQL映射文件中定义过,则将他们动态定义为一个Spring Bean。这样,我们就可以在Service直接注入映射接口的Bean了。

Spring配置MyBatis的更多相关文章

  1. spring配置mybatis的sqlsessionfactory

    <!--读入配置文件 --> <bean id="propertyConfigurer" class="org.springframework.bean ...

  2. Spring+SpringMvc+Mybatis框架集成搭建教程二(依赖配置及框架整合)

    依赖导入以及框架整合 (1).打开项目的pom.xml文件,声明依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" x ...

  3. MyBatis学习(一)、MyBatis简介与配置MyBatis+Spring+MySql

    一.MyBatis简介与配置MyBatis+Spring+MySql 1.1MyBatis简介 MyBatis 是一个可以自定义SQL.存储过程和高级映射的持久层框架.MyBatis 摒除了大部分的J ...

  4. Spring+springmvc+Mybatis整合案例 xml配置版(myeclipse)详细版

    Spring+springmvc+Mybatis整合案例 Version:xml版(myeclipse) 文档结构图: 从底层开始做起: 01.配置web.xml文件 <?xml version ...

  5. Spring+SpringMVC+MyBatis+Maven 服务端XML配置

    项目目录结构 spring-mybatis.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...

  6. spring和mybatis整合配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. spring mvc+myBatis配置详解

    一.spring mvc Spring框架(框架即:编程注解+xml配置的方式)MVC是Spring框架的一大特征,Spring框架有三大特征(IOC(依赖注入),AOP(面向切面),MVC(建模M- ...

  8. MyBatis学习 之 一、MyBatis简介与配置MyBatis+Spring+MySql

    目录(?)[-] 一MyBatis简介与配置MyBatisSpringMySql MyBatis简介 MyBatisSpringMySql简单配置 搭建Spring环境 建立MySql数据库 搭建My ...

  9. MyBatis简介与配置MyBatis+Spring+MySql

    MyBatis学习 之 一.MyBatis简介与配置MyBatis+Spring+MySql MyBatis学习 之 二.SQL语句映射文件(1)resultMap MyBatis学习 之 二.SQL ...

随机推荐

  1. C: 数组形参

    知识这个东西,真是知道的越多就不知道的越多,C/C++这塘水得多深啊,哈哈.看下面3个片段:<一> 1 void fun(char a[100]) { 2         fprintf( ...

  2. iphone绘图的几个基本概念CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)

    我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是装B,而是刚从vi转到xcode不久,不太习惯interface builder而已.当然如果需要我也会使用 ...

  3. CentOS 报no acceptable C compiler found in $PATH的解决办法

    CentOS 6.2下安装tcpreplay工具的时候,先安装libpcap-1.3.0,configure libpcap时出错. #./configure 提示没有GCC编译器环境) config ...

  4. hibernate 数据行数统计 count(*)

    Hibernate关于sql中的count(*)数据统计: ①如果使用的是HQL: 直接在HQL中使用count(*)即可获取行数 Long count = (Long)HibernateUtil.g ...

  5. Android工具:延展图片NinePatch

    NinePatch能够对.png图片进行处理,生成一个.9.png格式的图片,图像拉伸操作时,图片就会有失真,而.9.png是Android里所支持的一种特殊的图片格式,可以实现部分拉伸. 制作图片方 ...

  6. Ubuntu 12.04上编译Vim7.4的时候遇到“no terminal library found”问题

    错误如下: no terminal library foundchecking for tgetent()... configure: error: NOT FOUND!      You need ...

  7. Application.CommonAppDataPath的路径

    Application.CommonAppDataPath; win7的路径 C:\ProgramData\CompanyName\ProductName\2.0.5.1 [assembly: Ass ...

  8. Oracle EBS Report 输出字符字段前部"0"被Excel自动去掉问题

    Oracle  EBS 提供多种报表的开发和输出形式,由于MS Excel在处理数据方面的优势明显,报表输出用Excel打开是很常见的开发项. 但是正是由于Excel的"过于智能而不智能&q ...

  9. bzoj1412

    比较裸的最小割 注意狼和羊的领地可以通过空地相连 ;       dx:..] ,,,-);       dy:..] ,,,); type node=record        next,point ...

  10. 纯干货,Spring-data-jpa详解,全方位介绍

    本篇进行Spring-data-jpa的介绍,几乎涵盖该框架的所有方面,在日常的开发当中,基本上能满足所有需求.这里不讲解JPA和Spring-data-jpa单独使用,所有的内容都是在和Spring ...