<?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整体流程的更多相关文章

  1. Mybatis技术原理理——整体流程理解

    前言:2018年,是最杂乱的一年!所以你看我的博客,是不是很空! 网上有很多关于Mybatis原理介绍的博文,这里介绍两篇我个人很推荐的博文 Mybatis3.4.x技术内幕和 MyBaits源码分析 ...

  2. MyBatis整体架构

    Mybatis整体架构 基础支持层 反射模块 Java中的反射很强大,但是还是需要封装的.MyBatis专门提供了反射模块,对元素的反射进行了封装,提供了简洁的API,对反射进行了优化,例如缓存了类的 ...

  3. 使用git整体流程

    一.git提交代码走meger请求的整体流程 工作中使用git推代码时,如果走merge请求,那么也就是说拉代码时拉公共代码库的代码,但是提交时需要先提交到自己的代码库,然后在gitlab上提交mer ...

  4. iOS开发从申请开发账号到APP上架的整体流程详解

    应公司要求,写一份文档从申请账号一直到APP上架的整体流程,下面进入正文. https://blog.csdn.net/qq_35612929/article/details/78754470 首先第 ...

  5. enzyme design 整体流程及感想

    想起什么来写什么吧. 整体流程(以Ceas2, TPP, G3P为例): 准备蛋白即配体参数文件: 设置CST文件: 准备protocol和flag文件: 运行enzyme_design: 结果处理. ...

  6. 【驱动】input子系统整体流程全面分析(触摸屏驱动为例)【转】

    转自:http://www.cnblogs.com/lcw/p/3294356.html input输入子系统整体流程 input子系统在内核中的实现,包括输入子系统(Input Core),事件处理 ...

  7. vue框架整体流程

    1.整体流程 (1)模板解析成render函数 (2)响应式监听 (3)首次渲染,显示页面,绑定依赖 (4)data属性变化,触发rerender 2.模板解析为render函数 参考上一篇博客. 模 ...

  8. springmvc 运行原理 Spring ioc的实现原理 Mybatis工作流程 spring AOP实现原理

    SpringMVC的工作原理图: SpringMVC流程 . 用户发送请求至前端控制器DispatcherServlet. . DispatcherServlet收到请求调用HandlerMappin ...

  9. MyBatis 工作流程及插件开发

    1. MyBatis 框架分层架构 2. MyBatis 工作流程 获取 SqlSessionFactory 对象: 解析配置文件(全局映射,Sql映射文件)的每一个信息,并保存在Configurat ...

随机推荐

  1. noi.ac#458 sequence

    题目链接:戳我 蒟蒻的第一道子序列自动机! 给定两个01串A,B,求一个最短的01串,要求C不是A,B的子序列.要求如果同样短,输出字典序最小的. 那么我们先构建A,B两个串的子序列自动机.然后我们设 ...

  2. python3 使用flask连接数据库出现“ModuleNotFoundError: No module named 'MySQLdb'”

    本文链接:https://blog.csdn.net/Granery/article/details/89787348 在使用python3连接MySQL的时候出现了 ‘ModuleNotFoundE ...

  3. 微信小程序_(组件)icon、text、rich-text、progress四大基础组件

    微信小程序基础组件官方文档 传送门 Learn 一.icon图标组件 二.rich-text富文本组件 三.text文本组件 四.progress进度条组件 一.icon图标组件 type:icon的 ...

  4. 为什么还需要学习TypeScript

    开篇 TypeScript 是由 C#语言的创始人 Anders Hejlsberg 设计的一种编程语言,设计的初衷就是为了帮助 JavaScript 的开发人员能像类似高级语言c#,Java那样编写 ...

  5. xcode6 如何编译64位iOS应用

    原文:http://mobile.51cto.com/hot-412500.htm 随着iPhone5S的推出,大家开始关心5S上所使用的64位CPU A7. 除了关心A7的性能以外,大家还会关心一个 ...

  6. LeetCode 199. 二叉树的右视图(Binary Tree Right Side View)

    题目描述 给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值. 示例: 输入: [1,2,3,null,5,null,4] 输出: [1, 3, 4] 解释: 1 ...

  7. Mac Vmware NAT模式

    1.NAT模式原理 2.MAC上关于Vmware的配置 1)/Library/Preferences/VMware Fusion/networking MacBookPro:~ zhangxm$ vi ...

  8. python正则表达式解析(re)

    正则表达式的使用方法主要有4种: re.search(进行正则匹配), re.match(从头开始匹配)  re.findall(找出所有符合条件的字符列表)  re.split(根据条件进行切分)  ...

  9. ROC和AUC————摘在网络

    ROC曲线 对于0,1两类分类问题,一些分类器得到的结果往往不是0,1这样的标签,如神经网络,得到诸如0.5,0,8这样的分类结果.这时,我们人为取一个阈值,比如0.4,那么小于0.4的为0类,大于等 ...

  10. 查重复出现的字段 SQL

    select * from a where (select count(b.abc) from b where b.abc=a.abc)>1 一般treeview datagridview 都要 ...