笔记要点
出错分析与总结

 include内部使用自定的属性,之能使用$ {}来取值 ,#{}不能用

工程组织
数据库组织
0.重新修改Bean类
1.定义接口

public interface EmployeeMapper_DynamicSQL {
//批量插入,测试sql标签
public void addEmps2(@Param("emps")List<Employee> emps);

2.定义XML映射文件

<!--==================================================-->
<!--sql标签:
抽取可重用的sql片段,方便后面的进行引用;
引用方法:
<include refid="" ></include>
 include内部使用自定的属性,之能使用$ {}来取值 ,#{}不能用
-->
<sql id="insertColumn">
<if test="_databaseId=='mysql'">
last_name , email ,gender , d_id
</if>
</sql>
<insert id="addEmps2">
INSERT INTO tbl_employee(
<include refid="insertColumn"></include>
)
VALUES
<foreach collection="emps" item="emp" separator=",">
(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})
</foreach>
</insert>

3.编写测试代码

@Test
public void test12() throws Exception {
SqlSession openSession = getSqlSessionFactory().openSession();
try {
System.out.println("++++++++++---- tp48.测试动态sql_ sql标签:可重复引用数据内容");
EmployeeMapper_DynamicSQL mapper = openSession.getMapper(EmployeeMapper_DynamicSQL.class);
List<Employee> emps=new ArrayList<>();
emps.add(new Employee(null,"smith2" ,"smith@qq.com" , "1",
new Department(1)));
emps.add(new Employee(null,"aliex2" ,"aliex@qq.com" , "0",
new Department(1))); mapper.addEmps2(emps); openSession.commit();
} finally {
openSession.close();
}
}

测试结果

++++++++++---- tp48.测试动态sql_ sql标签:可重复引用数据内容
DEBUG 12-05 18:24:23,805 ==> Preparing: INSERT INTO tbl_employee( last_name , email ,gender , d_id ) VALUES (?,?,?,?) , (?,?,?,?) (BaseJdbcLogger.java:145)
DEBUG 12-05 18:24:23,821 ==> Parameters: smith2(String), smith@qq.com(String), 1(String), 1(Integer), aliex2(String), aliex@qq.com(String), 0(String), 1(Integer) (BaseJdbcLogger.java:145)
DEBUG 12-05 18:24:23,821 <== Updates: 2 (BaseJdbcLogger.java:145)

最新文章

  1. ELK+redis搭建nginx日志分析平台
  2. 数据结构图文解析之:树的简介及二叉排序树C++模板实现.
  3. winform学习笔记-文档路径
  4. 为ListView组件加上快速滑块以及修改快速滑块图像
  5. go语言之并发
  6. __NSCFConstantString
  7. Android开发-API指南-&lt;meta-data&gt;
  8. IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常
  9. 暑假集训(1)第一弹 -----士兵队列训练问题(Hdu1276)
  10. bzoj1072
  11. CI笔记6 json 传值
  12. Windows Message Queue--hdu1509
  13. macbook连接linuxserver后不显示matlab桌面[问题]
  14. app控件唯一相对Xpath自动生成(增强版uiautomatorviewer)
  15. error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler op
  16. 使用混淆ProGuard压缩代码和资源/减少方法数量
  17. webdriver +浏览器驱动
  18. JAVA基本语法测试
  19. 使用windows性能计数器监控cpu使用率
  20. Matlab中 .&#39; 的作用。

热门文章

  1. 【Tools】HP/惠普v285w 量产工具
  2. 【视频开发】RTSP SERVER(基于live555)详细设计
  3. Apollo环境配置
  4. async + promise 解决回调地狱
  5. TestNG执行顺序控制
  6. docker使用2
  7. 深入浅出JVM(一):运行时数据区域
  8. 环境配置--升级Python 3.6爬坑
  9. js的for循环中出现异步函数,回调引用的循环值始终是最后的值
  10. Docker安装带中文全文搜索插件zhparser的Postgresql数据库