Spring整合Mybatis应用

1、整合步骤介绍

  基于SpringMVC和Mybatis技术开发的主要步骤如下

    1>创建工程,搭建SpringMVC和Mybatis技术环境

    2>基于MapperScannerConfigurer方式整合Mybatis的Mapper接口(推荐)

    3>编写和配置SpringMVC的主要组件,例如Controller,HandlerMapping,ViewResolver等

    4>编写JSP视图组件,利用标签和表达式显示模型数据

    5>测试程序

2、如何搭建SpringMVC和Mybatis技术环境

  创建一个Web工程

  添加Mybatis相关技术环境

    引入数据库驱动包和Mybatis开发包

    引入dbcp连接池开发包

  添加SpringMVC相关技术环境

    引入Spring ioc,jdbc,tx等支持的开发包

    引入Spring webmvc支持的开发包

    在src下添加applicationContext.xml配置文件

    在web.xml中配置DispatcherServlet主控制器

  引入Mybatis和Spring整合开发包mybatis-spring.jar

3、如何基于MapperScannerConfigurer方式整合Mybatis的Mapper接口?

  根据数据表编写实体类

  编写Mapper映射文件,在XML中添加SQL操作的定义

  编写Mapper接口,定义 SQL操作方法

  在Spring配置文件中定义以下

时间: 2024-08-26 21:53:30

Spring整合Mybatis应用的相关文章

spring整合mybatis遇到的bug java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

出bug的原因:mybatis-spring版本问题. 查看SqlSessionDaoSupport源码 1.2以上的版本: 1.1.1版本: 解决方法:1.2版本移除了@Autowired的注解,所以如果是1.2版本以上,要在BaseDaoImpl里面手动 注入SetSessionTemplate或者SetSessionFactory spring整合mybatis遇到的bug java.lang.IllegalArgumentException: Property 'sqlSessionFa

Spring整合Mybatis解决 Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

在Spring4和Mybatis3整合的时候,dao层注入'sqlSessionFactory'或'sqlSessionTemplate'会报错解决办法如下: package com.alibaba.webx.MyWebxTest.myWebX.module.dao.impl; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; import org.m

spring 整合Mybatis 《错误集合,总结更新》

错误:nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor  运行环境:jdk1.7.0_17 + tomcat 7 + eclipse spring整合mybatis启动时候出现這个错误: SEVERE: Exception sending context initialized event to listener instance of class org

spring源码剖析(八)spring整合mybatis原理

前言 MyBatis相信很多人都会使用,但是当MyBatis整合到了Spring中,我们发现在Spring中使用更加方便了.例如获取Dao的实例,在Spring的我们只需要使用注入的方式就可以了使用Dao了,完全不需要调用SqlSession的getMapper方法去获取Dao的实例,更不需要我们去管理SqlSessionFactory,也不需要去创建SqlSession之类的了,对于插入操作也不需要我们commit. 既然那么方便,Spring到底为我们做了哪些工作呢,它如何将MyBatis整

spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist 错误原因:找不到我的springmvc.xml,在下面web.xml中是我引用路径,网上找到问题classpath指向路径不是resource路

Spring整合MyBatis完整示例

为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简单的图书管理功能,主要使用到的技术包含Spring.MyBatis.Maven.MySQL及简单MVC等.最后的运行效果如下所示: 项目结构如下: 一.新建一个基于Maven的Web项目 1.1.创建一个简单的Maven项目,项目信息如下: 1.2.修改层面信息,在项目上右键选择属性,再选择“Project

Mybatis入门——Spring整合MyBatis

Spring整合MyBatis 对Teacher表进行添加数据和查看数据 1. 创建数据库表 CREATE TABLE `teacher` (  `t_id` varchar(15) NOT NULL,  `t_name` varchar(30) DEFAULT NULL,  PRIMARY KEY (`t_id`)) 2.创建Spring工程 3.导入相关包 mybatis-spring-1.3.0.jar mybatis-3.3.0.jar mysql-connector-java-5.1.

分析下为什么spring 整合mybatis后为啥用不上session缓存

因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验下(spring整合mybatis略,网上一堆),先看看mybatis级别的session的缓存 放出打印sql语句 configuration.xml 加入 <settings> <!-- 打印查询语句 --> <setting name="logImpl"

Spring整合Mybatis的注意事项

初学 Spring 整合 Mybatis,虽然网贴无数,但是每次试行下来,总会发生这样那样的问题.最终经过数天的不断尝试,总算是成功运行了,遇到的多数坑也一一绕过,特此记录已备查: 一.关于依赖包 网上的很多帖子杂七杂八加入了各种依赖包,有时看的人头晕脑胀,经过实测,实际需要的依赖包,只有下面三组: <!-- 1.基础Spring依赖 --> <dependency> <groupId>org.springframework</groupId> <ar

spring整合mybatis(hibernate)配置

一.Spring整合配置Mybatis spring整合mybatis可以不需要mybatis-config.xml配置文件,直接通过spring配置文件一步到位.一般需要具备如下几个基本配置. 1.配置数据源(连接数据库最基本的属性配置,如数据库url,账号,密码,和数据库驱动等最基本参数配置) 1 <!-- 导入properties配置文件 --> 2 <context:property-placeholder location="classpath*:/jdbc.prop