1、环境

a.  jar包

(mybatis+spring mvc运行包+两者整合包mybatis-spring.jar)

b.工程目录

c. 配置文件

mybatis:SqlMapConfig.xml、mapper.xml等

spring mvc: applicationContext.xml

a) applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

      http://www.springframework.org/schema/mvc

      http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

      http://www.springframework.org/schema/context

      http://www.springframework.org/schema/context/spring-context-3.2.xsd

      http://www.springframework.org/schema/aop

      http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

      http://www.springframework.org/schema/tx

      http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

<!-- 加载配置文件 db.properties -->

<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="15" />

<property name="maxIdle" value="3" />

</bean>

<!-- sqlSessionFactory -->

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<!-- 加载mybatis的配置文件 -->

<property name="configLocation" value="mybatis/SqlMapConfig.xml" />

<!-- 数据源 -->

<property name="dataSource" ref="dataSource" />

</bean>

</beans>

 理解

2.原始dao开发

a. dao

b.user.xml

c.SqlMapConfig.xml

d.impl(要继承SqlSessionDaoSupport)

纯mybatis的话,这里是注入一个SqlSession来操作的。整合spring后通过SqlSessionDaoSupport的getSqlSession来操作。

e.applicationContext配置bean

f.测试程序

3.mapper代理

a.UserMapper.java

b.UserMapper.xml

c.SqlMapConfig.xml(不需要配置Mapper和数据源)

d.applicationContext配置

方法一,单个

方法二,批量

e.测试程序

mybatis和spring mvc整合的更多相关文章

  1. Java基础-SSM之Spring和Mybatis以及Spring MVC整合案例

    Java基础-SSM之Spring和Mybatis以及Spring MVC整合案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 能看到这篇文章的小伙伴,详细你已经有一定的Java ...

  2. Java框架搭建-Maven、Mybatis、Spring MVC整合搭建

    1. 下载eclipse 到网站下载 http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/marsr 选择 ...

  3. MyBatis+Spring+Spring MVC整合开发

    MyBatis+Spring+Spring MVC整合开发课程观看地址:http://www.xuetuwuyou.com/course/65课程出自学途无忧网:http://www.xuetuwuy ...

  4. OSGI企业应用开发(十四)整合Spring、Mybatis、Spring MVC

    作为一个企业级的Web应用,MVC框架是必不可少的.Spring MVC目前使用也比较广泛,本文就来介绍一下如何在OSGI应用中实现Spring.Mybatis.Spring MVC框架的整合,其中S ...

  5. 由“单独搭建Mybatis”到“Mybatis与Spring的整合/集成”

    在J2EE领域,Hibernate与Mybatis是大家常用的持久层框架,它们各有特点,在持久层框架中处于领导地位. 本文主要介绍Mybatis(对于较小型的系统,特别是报表较多的系统,个人偏向Myb ...

  6. OSGI企业应用开发(十五)基于Spring、Mybatis、Spring MVC实现一个登录应用

    前面文章中,我们已经完成了OSGI应用中Spring.Mybatis.Spring MVC的整合,本篇文章我们就在这个基础上来完成一个简单的登录应用,其中用户名和密码需要从数据库中查询. 前面文章中, ...

  7. spring mvc整合mybaitis和log4j

    在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...

  8. mybatis :与Spring MVC 的集成

    用mybatis与Spring mvc 的方式集成起来,源码在本文结尾处下载.主要有以下几个方面的配置1. web.xml 配置 spring dispatchservlet ,比如为:mvc-dis ...

  9. 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】

    一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...

随机推荐

  1. Window下MySql 5.6 安装后内存占用很高的问题

    Window下MySql 5.6 安装后内存占用很高的问题 刚刚准备玩一把mysql,初学者 环境是window 7和window sever 2008, mysql是最新的5.6, 发现的问题是安装 ...

  2. Array 数组类

    除了 Object 之外, Array 类型恐怕是 ECMAScript 中最常用的类型了.而且,ECMAScript 中的数组与其他多数语言中的数组有着相当大的区别.虽然 ECMAScript 数组 ...

  3. FastQC 测序质量

    文章转载于 Original 2017-07-06 Jolvii 生信百科 介绍一下如何理解 FastQC 各模块的结果 FastQC 的使用 FastQC的安装介绍请看这里.FastQC 支持 fa ...

  4. Django学习---CSRF

    CSRF xss攻击:假设我们网站的评论里面允许用户写js的时候,每个人就会看到页面会执行这个js代码,有的是alert,不停的跳出弹框.这个还不算严重的,关键是如果js代码运行的结果不显示在页面上, ...

  5. Netty的ChannelHandler,ChannelHandlerContext,ChannelPipeline

    本小节一起学习一下ChannelHandler,ChannelHandlerContext,ChannelPipeline这三个Netty常用的组件,不探究它们的底层源码,我们就简单的分析一下用法 首 ...

  6. GNU Bash Shell 编程图解笔记

    bash,Unix shell的一种,在1987年由布莱恩·福克斯为了GNU计划而编写.1989年发布第一个正式版本,原先是计划用在GNU操作系统上,但能运行于大多数类Unix系统的操作系统之上,包括 ...

  7. GNU/Linux操作系统总览

    计算机科学本科的专业课包括高等数学.离散数学.模拟电子技术.数字电子技术.微机原理.汇编语言原理.高级程序语言.操作系统原理.高级编译原理.嵌入式原理.网络原理.计算机组成与结构等诸多科目.GNU计算 ...

  8. 关于BigDecimal类型在jsp页面中进行除法运算问题

    出自:http://blog.csdn.net/u011910290/article/details/52935337 问题描述: 在项目编写过程中,发现BigDecimal在jsp中进行除法运算时, ...

  9. Window虚拟内存管理(转)

    内存管理是操作系统非常重要的部分,处理器每一次的升级都会给内存管理方式带来巨大的变化,向早期的8086cpu的分段式管理,到后来的80x86 系列的32位cpu推出的保护模式和段页式管理.在应用程序中 ...

  10. JDBC读取配置文件

    Properties prop = new Properties(); prop.load(this.class.getClassLoader().getResourceAsStream(" ...