I am using java7, spring 3 and mybatis Pom.xml <org.mybatis-version>3.2.8</org.mybatis-version> <org.mybatis-spring-version>1.2.2</org.mybatis-spring-version> <dependency> <groupId>org.mybatis</groupId> <artifa…
用mybatis将SQL查询语句”select * from user”的封装为配置文件 定义一个xml映射文件,文件名见名知意.如user-mapper.xml,文件内容如下: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/…
示例代码 之前的文章说过,对于MyBatis来说insert.update.delete是一组的,因为对于MyBatis来说它们都是update:select是一组的,因为对于MyBatis来说它就是select. 本文研究一下select的实现流程,示例代码为: public void testSelectOne() { System.out.println(mailDao.selectMailById(8)); } selectMailById方法的实现为: public Mail sele…
映射器 映射器的主要元素有八种: 元素名称 描述 select 查询语句,可自定义参数 insert 插入语句,执行后返回插入的条数 update 更新语句,执行后返回更新的条数 delete 删除语句,执行后返回删除的条数 sql 定义一部分的sql,被各处引用 resultMap 描述从数据库中得到的结果,提供映射规则 cache 给定命名空间的缓存配置 cache-ref 其他命名空间缓存配置的引用   select元素 ①   简单地应用查询的select元素: <select id =…
之前学习的时候,看到别人在使用mybatis时,用到@Select.@Insert.@Delete.@Param这几个注解,故楼主研究了一下,在这里与大家分享 当使用这几个注解的时候,可以省去写Mapper.xml等一系列配置文件 首先来看个例子: import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotation…
(转自:http://blog.csdn.net/canot/article/details/51485955) Mybatis表现关联关系比hibernate简单,没有分那么细致one-to-many.many-to-one.one-to-one.而是只有两种association(一).collection(多),表现很简洁.下面通过一个实例,来展示一下Mybatis对于常见的一对多和多对一关系复杂映射是怎样处理的. 以最简单的用户表订单表这个最简单的一对多做示例: 对应的JavaBean:…
mybatis 3.x源码深度解析与最佳实践 1 环境准备 1.1 mybatis介绍以及框架源码的学习目标 1.2 本系列源码解析的方式 1.3 环境搭建 1.4 从Hello World开始 2 容器的加载与初始化 2.1 config文件解析XMLConfigBuilder.parseConfiguration 2.1.1 属性解析propertiesElement 2.1.2 加载settings节点settingsAsProperties 2.1.3 加载自定义VFS loadCust…
MyBatis是什么 MyBatis是什么,MyBatis的jar包中有它的官方文档,文档是这么描述MyBatis的: MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of para…
本文来自http://www.bubuko.com/infodetail-549184.html 如果不太熟悉MyBatis使用的请先参见MyBatis官方文档,这对理解其架构设计和源码分析有很大好处. 一.概述 MyBatis并不是一个完整的ORM框架,其官方首页是这么介绍自己 The MyBatis data mapper framework makes it easier to use a relational database with object-oriented applicati…
如果不太熟悉MyBatis使用的请先参见MyBatis官方文档,这对理解其架构设计和源码分析有很大好处. 一.概述 MyBatis并不是一个完整的ORM框架,其官方首页是这么介绍自己 The MyBatis data mapper framework makes it easier to use a relational database with object-oriented applications. MyBatis couples objects with stored procedur…