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. 【洛谷】P3908 异或之和(异或)

    题目描述 求1 \bigoplus 2 \bigoplus\cdots\bigoplus N1⨁2⨁⋯⨁N 的值. A \bigoplus BA⨁B 即AA , BB 按位异或. 输入输出格式 输入格 ...

  2. 03-22 Ajax验证用户登录

    在网页中一般是通过表单提交数据,而表单获取信息,抛弃当前页面重新加载一个新页面. 现在,在webform网页中可以通过JueryAjax提交.处理数据的方式,达到异步刷新页面. 表单提交数据和Juer ...

  3. webpy简单使用

    #!/usr/bin/env python import web import pymysql.cursors # Connect to the database connection = pymys ...

  4. 利用 Django admin 完成更多任务(转)

    利用 Django admin 完成更多任务   Django admin Django 为未来的开发人员提供了许多功能:一个成熟的标准库,一个活跃的用户社区,以及 Python 语言的所有好处.虽然 ...

  5. 加密算法blowfish 多语言

    php加密算法blowfish <?php /** * Created by PhpStorm. * User: Administrator * Date: 2016-02-14 * Time: ...

  6. Mysql在spring中jdbc.properties连接配置

    ############################## mysql的数据源 ############################## jdbc.driver=com.mysql.jdbc.D ...

  7. 前端Blob对象的使用

    最近移动端界面给后台传数据时用到Blob,它可以看做是存放二进制数据的容器: //上传图片数据封装 function uploadPhotoData(data,fileName){ var imgAr ...

  8. matching书页匹配例子

    detect_brochure_pages.hdev   *这个例子主要描述了从图片库中寻找有相应页面的那一页 *第一步中,不同的纸张页面用来做训练,最后创建好model *第二步,在未知的页面图片中 ...

  9. PHP获取页面执行时间的方法(推荐)

    一些循环代码,有时候要知道页面执行的时间,可以添加以下几行代码到页面头部和尾部: 头部:$stime=microtime(true); 尾部: $etime=microtime(true);//获取程 ...

  10. Setup Apache2 in Debian 9 and enable two ports for two sites

    root@debian:~# apt-get install apache2 root@debian:~# cd /etc/apache2/ root@debian:/etc/apache2# ls ...