mybatis整体流程
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- <properties>
<property name="jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties> --> <!--
<properties>:设置或引入资源文件
resource:在类路径下访问资源文件
url:在网络路径或磁盘路径下访问资源文件
-->
<properties resource="jdbc.properties"></properties> <settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings> <typeAliases>
<!--
为类型设置类型别名
type:Java 类型,若只设置type,默认的别名就是类型,且不区分大小写
-->
<!-- <typeAlias type="com.atguigu.bean.User" alias="u"/> 不建议-->
<!-- 这种写法在XxxMapper.xml的resultType只需要写个Xxx就可以 -->
<package name="com.atguigu.bean"/>
</typeAliases> <!--
<environments>:设置连接数据库的环境
default:设置默认使用的数据库环境
-->
<environments default="mysql">
<!--
<environment>:设置某个具体的数据库的环境
id:数据库环境的唯一标示
-->
<environment id="mysql">
<!-- type="JDBC|MANAGED" -->
<transactionManager type="JDBC" />
<!-- type="POOLED|UNPOOLED|JNDI" -->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment> <environment id="oracle">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/ssm" />
<property name="username" value="root" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>
<!-- 引入映射文件 -->
<mappers>
<!-- 引入具体的映射文件 -->
<mapper resource="UserMapper.xml" />
</mappers>
</configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 这个用来指定对应的dao接口 -->
<mapper namespace="com.atguigu.mapper.UserMapper"> <!--
<select>:定义查询语句
id:设置SQL语句的唯一标示
resultType:结果类型,即实体类的全限定名
resultType如果在sqlMapConfig.xml中配置过typeAlisas,则按起的别名来,不建议
-->
<select id="getUserByUid" resultType="com.atguigu.bean.User">
select uid,username,password,age,sex from user where uid = ${value}
</select> </mapper>
package com.atguigu.mapper;
import com.atguigu.bean.User;
public interface UserMapper {
//和UserMapper.xml中的sql的id对应的
/**
* <!--
<select>:定义查询语句
id:设置SQL语句的唯一标示
resultType:结果类型,即实体类的全限定名
-->
<select id="getUserByUid" resultType="com.atguigu.bean.User">
select uid,username,password,age,sex from user where uid = ${value} 或者#{id}
</select>
* @param uid
* @return
*/
User getUserByUid(String uid);
}
package com.atguigu.mapper; import static org.junit.Assert.*; import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test; import com.atguigu.bean.User; public class TestMybatis { @Test
public void test() throws IOException { InputStream is = Resources.getResourceAsStream("mybatis-config.xml");//org.apache.ibatis.io.Resources
//InputStream is = TestMybatis.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
SqlSessionFactory sqlSessionFactory =
new SqlSessionFactoryBuilder().build(is);
SqlSession sqlSession = sqlSessionFactory.openSession();
//getMapper():会通过动态代理动态生成UserMapper的代理实现类
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
System.out.println(mapper.getClass().getName());//com.sun.proxy.$Proxy4这个为生成的代理对象
User user = mapper.getUserByUid("1");
System.out.println(user);
//user_name ---> userName
} }

mybatis整体流程的更多相关文章
- Mybatis技术原理理——整体流程理解
前言:2018年,是最杂乱的一年!所以你看我的博客,是不是很空! 网上有很多关于Mybatis原理介绍的博文,这里介绍两篇我个人很推荐的博文 Mybatis3.4.x技术内幕和 MyBaits源码分析 ...
- MyBatis整体架构
Mybatis整体架构 基础支持层 反射模块 Java中的反射很强大,但是还是需要封装的.MyBatis专门提供了反射模块,对元素的反射进行了封装,提供了简洁的API,对反射进行了优化,例如缓存了类的 ...
- 使用git整体流程
一.git提交代码走meger请求的整体流程 工作中使用git推代码时,如果走merge请求,那么也就是说拉代码时拉公共代码库的代码,但是提交时需要先提交到自己的代码库,然后在gitlab上提交mer ...
- iOS开发从申请开发账号到APP上架的整体流程详解
应公司要求,写一份文档从申请账号一直到APP上架的整体流程,下面进入正文. https://blog.csdn.net/qq_35612929/article/details/78754470 首先第 ...
- enzyme design 整体流程及感想
想起什么来写什么吧. 整体流程(以Ceas2, TPP, G3P为例): 准备蛋白即配体参数文件: 设置CST文件: 准备protocol和flag文件: 运行enzyme_design: 结果处理. ...
- 【驱动】input子系统整体流程全面分析(触摸屏驱动为例)【转】
转自:http://www.cnblogs.com/lcw/p/3294356.html input输入子系统整体流程 input子系统在内核中的实现,包括输入子系统(Input Core),事件处理 ...
- vue框架整体流程
1.整体流程 (1)模板解析成render函数 (2)响应式监听 (3)首次渲染,显示页面,绑定依赖 (4)data属性变化,触发rerender 2.模板解析为render函数 参考上一篇博客. 模 ...
- springmvc 运行原理 Spring ioc的实现原理 Mybatis工作流程 spring AOP实现原理
SpringMVC的工作原理图: SpringMVC流程 . 用户发送请求至前端控制器DispatcherServlet. . DispatcherServlet收到请求调用HandlerMappin ...
- MyBatis 工作流程及插件开发
1. MyBatis 框架分层架构 2. MyBatis 工作流程 获取 SqlSessionFactory 对象: 解析配置文件(全局映射,Sql映射文件)的每一个信息,并保存在Configurat ...
随机推荐
- C#如何生成setup安装文件
当前项目状况如图: ,如何把test1打包成setup文件,用户安装后即可完成相应功能. 第一,右击“解决方案test1”->添加“新建项目”->“其他项目类型”->“安装和部署”- ...
- 四、SpringBoot整合mybatis——配置mybatis驼峰命名规则自动转换
简述: mybatis驼峰式命名规则自动转换: 使用前提:数据库表设计按照规范“字段名中各单词使用下划线"_"划分”:使用好处:省去mapper.xml文件中繁琐编写表字段列表与表 ...
- Linux之vnc启动及异常处理
1)启动桌面1的服务 [root@testdb ~]# vncserver :1 New 'testdb:1 (root)' desktop is testdb:1 Starting applicat ...
- beautifulsoup 安装
pip install beautifulsoup4
- 【面试】Spring 执行流程
Spring Aop的实现原理: AOP 的全称是 Aspect Orient Programming ,即面向切面编程.是对 OOP (Object Orient Programming) 的一 ...
- Node.js自学完全总结
零.什么是Node.js? 引用Node.js官方网站的解释如下: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript e ...
- PL/SQL的命令行窗口中执行脚本
注意脚本路径中不能有空格, 格式如下:SQL>@D:\1211_Export\all.sql 备注: @后面接本地sql文件的路径及执行文件
- OGG-01201
OGG-01201 Table of Contents 1. OGG-01201 1.1. 案例1 1.2. 案例2 1 OGG-01201 这种错误,出现的场景之一是 direct load 加载数 ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- [SQL]学习中遇到的错误
1.中英文模式切换 查找语句中不能出现中文字符!!!