MyBatis_[tp_48]_动态sql_内置参数_parameter&_databaseId
笔记要点-----内置参数_parameter&_databaseId 用处: 迅速切换数据库,执行一条多分支的sql语句即可;
1.定义接口
public interface EmployeeMapper_DynamicSQL {
public List<Employee> getEmpsTestInnerParameter(Employee employee);//测试内部参数
}
2.定义XML映射文件
<!--两个内置参数;不只是方法传递过来的参数可以用来判断,取值
mubatis默认还有两个内置参数:
_parameter : 代表整个参数;
单个参数: _parameter就是这个参数
多个参数: 会被封装成一个map,map就是_parameter _databaseId : 如果配置了databaseIdProvider标签;
_databaseId就是代表了当前数据库的别名mysql !
-->
<!--public List<Employee> getEmpsTestInnerParameter(Employee employee);//测试内部参数-->
<select id="getEmpsTestInnerParameter" resultType="com.bean.Employee">
<if test="_databaseId=='mysql'">
select * from tbl_employee
<if test="_parameter!=null">
where last_name = #{_parameter.lastName}
</if>
</if>
<if test="_databaseId=='oracle'">
select * from tbl_employee
</if>
3.编写测试代码
public class test_tp48 {
public SqlSessionFactory getSqlSessionFactory() throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
return new SqlSessionFactoryBuilder().build(inputStream);
}
@Test
public void test11() throws Exception {
SqlSession openSession = getSqlSessionFactory().openSession();
try {
System.out.println("++++++++++---- tp48.测试动态sql_内置参数_parameter&_databaseId");
EmployeeMapper_DynamicSQL mapper = openSession.getMapper(EmployeeMapper_DynamicSQL.class);
List<Employee> list = mapper.getEmpsTestInnerParameter(null);
for(Employee e:list)
System.out.println(e);
openSession.commit();
} finally {
openSession.close();
}
}
}
测试结果
++++++++++---- tp48.测试动态sql_内置参数_parameter&_databaseId
DEBUG 12-05 17:45:17,805 ==> Preparing: select * from tbl_employee (BaseJdbcLogger.java:145)
DEBUG 12-05 17:45:17,828 ==> Parameters: (BaseJdbcLogger.java:145)
DEBUG 12-05 17:45:17,845 <== Total: 8 (BaseJdbcLogger.java:145)
Employee{id=1, lastName='Jerry2333', email='233@...', gender='1', dept=null}
Employee{id=4, lastName='葫芦娃', email='葫芦娃@163.com', gender='0', dept=null}
Employee{id=5, lastName='葫芦娃e', email='qwq@qq.com', gender='1', dept=null}
Employee{id=6, lastName='null', email='xxx@qq.com', gender='1', dept=null}
Employee{id=7, lastName='tom', email='tom@163.com', gender='0', dept=null}
Employee{id=8, lastName='frak', email='frak@163.com', gender='1', dept=null}
Employee{id=9, lastName='smith', email='smith@qq.com', gender='1', dept=null}
Employee{id=10, lastName='aliex', email='aliex@qq.com', gender='0', dept=null}
MyBatis_[tp_48]_动态sql_内置参数_parameter&_databaseId的更多相关文章
- Mybatis学习笔记15 - 两个内置参数_parameter和_databaseId
两个内置参数:除了方法传递过来的参数可以被用来判断,取值外,mybatis默认还有两个内置参数: _parameter:代表整个参数 单个参数:_parameter就代表这个单个参数 多个参数:参数会 ...
- mybatis动态sql中的两个内置参数(_parameter和_databaseId)
mybatis动态sql中的两个内置参数(_parameter和_databaseId) <!-- mybatis动态sql的两个内置参数 不只是方法传递过来的参数可以被 ...
- Mybatis输入输出映射_动态sql_关联关系(一对一、一对多、多对多)
Mybatis输入输出映射_动态sql_关联关系(一对一.一对多.多对多)输入输出映射parameterType完成输入映射parameterType可以传入的参数有,基本数据类型(根据id查询用户的 ...
- 6、前端--DOM操作(查找标签、节点操作、获取值操作、class操作、样式操作、绑定事件、内置参数this)
DOM操作之查找标签 前缀关键字>>>:document # 基本查找(核心) document.getElementById 根据ID获取一个标签 document.getElem ...
- Python成长之路第二篇(2)_列表元组内置函数用法
列表元组内置函数用法list 元组的用法和列表相似就不一一介绍了 1)def append(self, p_object):将值添加到列表的最后 # real signature unknown; r ...
- for 循环常见内置参数
系统相关的信息模块: import sys sys.argv 是一个 list,包含所有的命令行参数. sys.stdout sys.stdin sys.stderr 分别表示标准输入输出,错误输出的 ...
- python 入门基础21 --面向对象_多态、内置方法、反射
内容: 1.接口思想 2.抽象类思想 3.多态 4.内置方法 5.反射 1.接口思想 建立关联的桥梁,方便管理代码 接口类:用来定义功能的类,位继承它的子类提供功能 该类的功能方法一般不需要实现体,实 ...
- log4j日志相对路径,Tomcat(第三方和Springboot内置)参数catalina.home和catalina.base的设置
关于Log4j日志相对路径的配置请看:log4j 产生的日志位置设置 和 catalina.home.catalina.base . 由于我们在Log4j的配置中引入了系统属性${catalina.b ...
- Python3中string内置参数
说明: 使用ipython查看python3的内置函数 ,只需要输入字符串按两下tab键 capitalize():将字符串中第一个字符大写 casefold:将字符串中的所有大写字母转为小写 cen ...
随机推荐
- Pyhon时间参数的应用
Python获取 本周,上周,本月,上月,本季,上季,今年, 去年 # -*- coding: utf-8 -*-# @time: 2019-05-13 17:30 import datetime f ...
- Django 操作已经存在的数据库
反向操作数据库 何为反向操作.即是数据库在项目之前已经存在,不需要新建表,操作已经存在的表 # 进入站点目录下执行 python manage.py inspectdb #可以看到settings中连 ...
- use azure-cli to manage resources
登陆 注意: 在Azure China中使用Azure CLI 2.0之前,请首先切换环境, 运行: az cloud set -n AzureChinaCloud 如果想切回全球的版本: az cl ...
- git config命令详解
Git有一个工具被称为git config,它允许你获得和设置配置变量:这些变量可以控制Git的外观和操作的各个方面. 一. 配置文件的存储位置 这些变量可以被存储在三个不同的位置: 1./etc/ ...
- PAT(B) 1043 输出PATest(Java)统计
题目链接:1043 输出PATest (20 point(s)) 题目描述 给定一个长度不超过 104 的.仅由英文字母构成的字符串.请将字符重新调整顺序,按 PATestPATest- 这样的 ...
- 1183: 零起点学算法90——海选女主角(C语言)
一.题目 http://acm.wust.edu.cn/problem.php?id=1183&soj=0 二.分析 从描述来看,就是找出一个二维数组中绝对值最大的数: 带符号的32位整数,刚 ...
- Linux下实现web服务器
说明:暂时只是实现了静态网页的响应 #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include < ...
- OpenCV学习笔记3
OpenCV学习笔记3 图像平滑(低通滤波) 使用低通滤波器可以达到图像模糊的目的.这对与去除噪音很有帮助.其实就是去除图像中的高频成分(比如:噪音,边界).所以边界也会被模糊一点.(当然,也有一些模 ...
- TZOJ3591这个真不会
#include<stdio.h> int main() { ],b[],c,x,y; scanf("%d",&t); while(t--) { c=; x=; ...
- go String方法的实际应用
让 IPAddr 类型实现 fmt.Stringer 以便用点分格式输出地址. 例如,`IPAddr{1,`2,`3,`4}` 应当输出 `"1.2.3.4"`. String() ...