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. Java中RMI远程调用demo

    Java远程方法调用,即Java RMI(Java Remote Method Invocation),一种用于实现远程过程调用的应用程序编程接口.它使客户机上运行的程序可以调用远程服务器上的对象.远 ...

  2. 未注册在本地的Windows 2008 / Windows 7 X64的:'Microsoft.Jet.OLEDB.4.0'提供

    在服务器上部署项目的时候遇到如下错误:'Microsoft.Jet.OLEDB.4.0'提供在本地没有注册 服务器是WIN2008 导致这个错误主要有几个原因: 1,服务器上没有装MS Excel中的 ...

  3. MyBatis Generator模板

    注:注意替换红色部分   <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generator ...

  4. Python实践练习:strip()的正则表达式版本

    题目: 写一个函数,它接受一个字符串,做的事情和 strip()字符串方法一样.如果只传入了要去除的字符串,没有其他参数,那么就从该字符串首尾去除空白字符.否则,函数第二个参数指定的字符将从该字符串中 ...

  5. Memcached的过期数据的过期机制及删除机制(LRU)

    Memcached的过期数据的过期机制及删除机制1.当某个值过期后,并没有从内存删除,因此,使用stats命令统计时,curr_item参数有信息(不为0)2.当某个新值去占用他的位置时,当成空chu ...

  6. interrupt 1 using 1

    释疑:void Timer0() interrupt 1 using 1 Timer0   是函数名,随便取的 interrupt   xx   using   y 跟在interrupt   后面的 ...

  7. python查找文件相同的和包含汉字的

    #!/usr/bin/env python # Version = 3.5.2 import os import time d_path = '/data/media' log_file = 'res ...

  8. views获取数据 -- request包含的方法

    request.GET request.POST request.FILES request.path_info request.xxx.getlist request.method request. ...

  9. nginx-rtmp-module--------------WIKI

    https://github.com/arut/nginx-rtmp-module/wiki/Directives#idle_streams ============================= ...

  10. 【转】iphone - ios app maximum memory budget

    https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget device: (crash amount/tota ...