今日内容:
  • mybatis中的连接池、事务控制【原理了解,应用会用】
    • mybatis中连接池的使用及分析
    • mybatis中事务控制的分析
  • mybatis中基于xml配置的动态SQL语句使用【会用即可】
    • mappers配置文件中的几个标签
      • <if>
      • <where>
      • <foreach>
      • <sql>实现代码片段
  • mybatis中的多表操作【掌握应用】
    • 一对多
    • 一对一(?)
    • 多对多
一、mybatis的连接池和事务控制
1、连接池的介绍
  • 实际开发中都会使用连接池
    • 原因:可以减少获取连接所消耗的时间
  • 图解
  • 分析:
    • 连接池就是用于存储连接的容器
    • 容器其实就是一个集合对象,只不过该集合是线程安全的,两个线程不能拿到同一个连接
    • 该集合还需要实现队列的先进先出特性。
while (conn == null) { //连接为空时创建
synchronized (state) {
if (!state.idleConnections.isEmpty()) {
// Pool has available connection
conn = state.idleConnections.remove(0);
2、mybatis连接池的分类
mybatis连接池提供了三种方式的配置
  • 配置的位置:
    • 主配置文件SqlMapConfig.xml中的dataSource标签,type属性表示采用何种连接池方式
  • type的取值:
    • POOLED:采用传统的javax.sql.DataSource规范中的连接池,mybatis中有针对规范的实现
    • UNPOOLED:采用传统的获取连接的方式,虽然也实现了javax.sql.DataSource接口,但是没有使用池的思想--每次使用都获取一个新的连接
    • 【扩展】JNDI:采用服务器提供的JNDI技术实现,来获取DataSource对象,不同服务器所能拿到的DataSource不同。
      • 注意:如果不是web或者maven的war工程,是不能使用的
      • 我们课程中使用的是tomcat服务器,采用的连接池就是dbcp连接池
3、mybatis中使用unpooled配置连接池的原理分析
  • POOLED是从池中获取一个连接来用
  • UNPOOLED是注册驱动、获取连接
4、mybatis中使用pooled配置连接的原理分析
  • 空闲连接池
  • 活动连接池
5、mybatis中的事务原理和自动提交设置
  • 了解(面试)
    • 什么是事务
    • 事务的四大特性ACID
    • 不考虑隔离性会产生的3个问题
    • 解决方法:四种隔离级别
  • mybatis的事务
    • 通过sqlSession对象的commit方法和rollback方法实现事务的提交和和回滚
  • 如何设置为自动提交
    @Override
public void saveUser(User user) {
//1.根据factory获取SqlSession对象
SqlSession session = factory.openSession(true);
//2.调用SQLSession中的方法实现查询列表
session.insert("com.itcast.dao.IUserDao.saveUser",user);
//3.提交事务
//session.commit();
//4.关闭
session.close();
}
二、mybatis的动态sql语句(mybatis映射文件的sql深入)
与查询相关的查询条件
1、if标签
    <!--根据条件查询-->
<select id="findUserByCondition" resultType="com.itcast.domain.User" parameterType="user">
select * from user where 1=1
<if test="username != null">
and username = #{username}
</if>
</select>
2、where标签
   <!--根据条件查询-->
<select id="findUserByCondition" resultType="com.itcast.domain.User" parameterType="user">
select * from user
<where>
<if test="username != null">
and username = #{username}
</if>
<if test="sex != null">
and sex = #{sex}
</if>
</where>
</select>
3、foreach和sql标签
  • 举例:select * from user where username in(43,44);
    /**
* 根据queryvo中提供的id集合,查询用户集合
* @param vo
* @return
*/
List<User> findByUserInIds(QueryVo vo);
    <!--根据queryvo中的id集合实现查询用户列表-->
<select id="findByUserInIds" resultType="com.itcast.domain.User">
select * from user where id
<where>
<if test="ids != null and ids.size()>0">
<foreach collection="ids" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</if>
</where>
</select>
    /**
* 测试foreach
*/
@Test
public void testfindInIds() throws IOException {
QueryVo vo = new QueryVo();
List<Integer> list = new ArrayList<>();
list.add(41);
list.add(42);
list.add(44);
vo.setIds(list);
List<User> users = userDao.findByUserInIds(vo);
for (User user : users) {
System.out.println(user);
}
}
抽取代码片段及使用
<sql id="defaultUser">
select * from user
</sql>
<select id="findAll" resultType="com.itcast.domain.User" >
<include refid="defaultUser"></include>
</select>
三、mybatis的多表操作
1、mybatis表之间关系分析
  • 一对多
    • 举例:一个用户可以下多个订单
  • 多对一
    • 举例:一个班级有多个学生
  • 一对一
  • 多对多
    • 举例:一个学生可以有多个老师,一个老师可以有多个学生
  • 特例:拿出每一个订单都只属于一个用户,所以mybatis就把多对一看成一对一
2、完成account表的建立及实现单表查询
  • 示例:用户和账户
    • 一个用户可以有多个账户
    • 一个账户只能属于一个用户(多个账户可以只属于同一个用户)
  • 步骤:
    • 建立用户表和账户表
      • 让用户表和账户表之间具备一对多的关系,需要在账户表中添加外键
    • 建立两个实体类:用户实体类和账户实体类
      • 让用户和账户的实体类能体现出一对多的关系
    • 建立两个配置文件
      • 用户的配置文件
      • 账户的配置文件
    • 实现配置:
      • 当查询用户时,可以同时得到用户下所包含的账户信息
      • 当查询账户时,可以同时得到账户的所属用户信息
3、完成account一对一操作---一对多(不常用)
<?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"> <mapper namespace="com.itcast.dao.IAccountDao">
<select id="findAll" resultType="account" >
select * from account
</select>
<!--查询所有账户同时包含用户名和地址信息-->
<select id="findAllAccount" resultType="accountuser" >
SELECT a.*,u.username,u.address FROM account a, USER u WHERE a.uid = u.id
</select>
</mapper>
<?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 resource="jdbcConfig.properties">
</properties>
<!--使用typeAliases配置别名,只能配置domain中类的别名-->
<typeAliases>
<!--typeAliases配置别名,type指定全限定类名,alias指定别名,指定别名后不再区分大小写-->
<!--<typeAlias type="com.itcast.domain.User" alias="user"></typeAlias>
<typeAlias type="com.itcast.domain.Account" alias="account"></typeAlias>-->
<!--package用于指定要配置别名的包,当指定后,该包下的实体类都会注册别名,并且类名就是别名,不再区分大小写-->
<package name="com.itcast.domain"></package>
</typeAliases>
<!--配置环境-->
<environments default="mysql">
<!--配置mysql的环境-->
<environment id="mysql">
<!--配置事务-->
<transactionManager type="JDBC"></transactionManager>
<!--配置连接池-->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</dataSource>
</environment>
</environments>
<!--配置映射文件的位置-->
<mappers>
<!--<mapper resource="com/itcast/dao/IAccountDao.xml"></mapper>-->
<!--用于指定dao接口所在的包,当指定完成之后就不需要再写mapper、resource或class了-->
<package name="com.itcast.dao"/>
</mappers>
</configuration>
    /**
* 测试查询所有账户,同时包含用户名称和地址
*/
@Test
public void testFindAllAccount(){
List<AccountUser> aus = accountDao.findAllAccount();
for (AccountUser au : aus) {
System.out.println(au);
}
}
    @Override
public String toString() {
return super.toString() +
"AccountUser{" +
"username='" + username + '\'' +
", address='" + address + '\'' +
'}';
}
4、完成account一对一操作-建立实体类关系的方式
public class Account implements Serializable {
private Integer id;
private Integer uid;
private Double money;
//从表实体应该包含一个主表实体的对象引用
private User user; public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
}
<?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"> <mapper namespace="com.itcast.dao.IAccountDao">
<!--定义封装account和user的resultMap-->
<resultMap id="accountUserMap" type="account">
<id property="id" column="aid"></id>
<result property="uid" column="uid"></result>
<result property="money" column="money"></result>
<!--应当建立一对一的关系映射:配置封装user的内容-->
<association property="user" column="uid" javaType="user">
<id property="id" column="id"></id>
<result property="username" column="username"></result>
<result property="address" column="address"></result>
<result property="sex" column="sex"></result>
<result property="birthday" column="birthday"></result>
</association>
</resultMap>
<select id="findAll" resultMap="accountUserMap" >
SELECT u.*,a.id AS aid,a.money,a.uid FROM account a, USER u WHERE a.uid = u.id
</select>
<!--查询所有账户同时包含用户名和地址信息-->
<select id="findAllAccount" resultType="accountuser" >
SELECT a.*,u.username,u.address FROM account a, USER u WHERE a.uid = u.id
</select>
</mapper>

    /**
* 测试查询所有
*/
@Test
public void testFindAll(){
List<Account> accounts = accountDao.findAll();
for (Account account : accounts) {
System.out.println("-----每个account的信息-----");
System.out.println(account);
System.out.println(account.getUser());
}
}
5、完成user的一对多查询操作
<?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"> <mapper namespace="com.itcast.dao.IUserDao">
<!--定义user的resultMap-->
<resultMap id="userAccountMap" type="user">
<id property="id" column="id"></id>
<result property="username" column="username"></result>
<result property="address" column="address"></result>
<result property="sex" column="sex"></result>
<result property="birthday" column="birthday"></result>
<!--配置user对象中account集合的映射-->
<collection property="accounts" ofType="account">
<id column="aid" property="id"></id>
<result column="uid" property="uid"></result>
<result column="money" property="money"></result>
</collection>
</resultMap>
<select id="findAll" resultMap="userAccountMap" >
SELECT * FROM USER u LEFT OUTER JOIN account a ON u.id = a.UID
</select>
</mapper>
	/**
* 测试查询所有
*/
@Test
public void testFindAll(){
List<User> users = userDao.findAll();
for (User user : users) {
System.out.println("-----每个account的信息-----");
System.out.println(user);
System.out.println(user.getAccounts());
}
}
public class User implements Serializable {
private Integer id;
private String username;
private String address;
private String sex;
private Date birthday;
//建立一对多关系映射,主表实体应该包含从表实体的集合引用
private List<Account> accounts; public List<Account> getAccounts() {
return accounts;
} public void setAccounts(List<Account> accounts) {
this.accounts = accounts;
}
6、分析mybatis多对多的步骤并搭建环境
多对多
  • 示例:用户和角色(用户的身份)
    • 用户可以有多个角色
    • 一个角色也可以赋予多个用户
  • 步骤:
    • 建立用户表和角色表
      • 让用户表和角色表之间具备一对多的关系
      • 需要使用中间表,中间表中包含各自的主键,在中间表中是外键
    • 建立两个实体类:用户实体类和角色实体类
      • 让用户和角色的实体类能体现出多对多的关系
      • 各自包含对方的集合引用
    • 建立两个配置文件
      • 用户的配置文件
      • 角色的配置文件
    • 实现配置:
      • 当查询用户时,可以同时得到用户下所包含的角色信息
      • 当查询角色时,可以同时得到角色的所赋予的用户信息
7、mybatis多对多准备角色表的实体类和映射配置
public class Role implements Serializable {
private Integer roleId;
private String roleName;
private String roleDesc;
package com.itcast.dao;

import com.itcast.domain.Role;

import java.util.List;

public interface IRoleDao {
/**
* 查询所有角色
* @return
*/
List<Role> findAll();
}
<?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">
<mapper namespace="com.itcast.dao.IRoleDao">
<!--定义role表的resultMap-->
<resultMap id="roleMap" type="role">
<id property="roleId" column="id"></id>
<!--windows不区分大小写,linux区分大小写-->
<result property="roleName" column="role_name"></result>
<result property="roleDesc" column="role_desc"></result>
</resultMap>
<select id="findAll" resultMap="roleMap">
select * from role
</select>
</mapper>
8、mybatis多对多操作-查询角色获取角色下所属用户信息
两次左外连接才能实现功能
public class Role implements Serializable {
private Integer roleId;
private String roleName;
private String roleDesc;
//多对多的关系映射:一个角色可以赋予多个用户
private List<User> users; public List<User> getUsers() {
return users;
} public void setUsers(List<User> users) {
this.users = users;
}
<mapper namespace="com.itcast.dao.IRoleDao">
<!--定义role表的resultMap-->
<resultMap id="roleMap" type="role">
<id property="roleId" column="id"></id>
<!--windows不区分大小写,linux区分大小写-->
<result property="roleName" column="role_name"></result>
<result property="roleDesc" column="role_desc"></result>
<collection property="users" ofType="user">
<id column="id" property="id"></id>
<result column="username" property="username"></result>
<result column="address" property="address"></result>
<result column="sex" property="sex"></result>
<result column="birthday" property="birthday"></result>
</collection>
</resultMap>
<select id="findAll" resultMap="roleMap">
SELECT u.*,r.`ID` rid,r.`ROLE_NAME`,r.`ROLE_DESC` FROM role r
LEFT OUTER JOIN user_role ur ON r.id = ur.`RID`
LEFT OUTER JOIN USER u ON u.id = ur.`UID`
</select>
</mapper>
    /**
* 测试查询所有
*/
@Test
public void testFindAll(){
List<Role> roles = roleDao.findAll();
for (Role role : roles) {
System.out.println("-----每个角色的信息-----");
System.out.println(role);
System.out.println(role.getUsers());
}
}
9、mybatis多对多操作-查询用户获取用户所包含的角色信息
-- 查询角色时查出用户
SELECT * FROM role;
SELECT * FROM USER;
-- 两次左外连接
SELECT u.*,r.`ID` rid,r.`ROLE_NAME`,r.`ROLE_DESC` FROM role r
LEFT OUTER JOIN user_role ur ON r.id = ur.`RID`
LEFT OUTER JOIN USER u ON u.id = ur.`UID`
-- 查询用户对应的角色,并不是所有用户都有角色
SELECT u.*,r.`ID` rid,r.`ROLE_NAME`,r.`ROLE_DESC` FROM USER u
LEFT OUTER JOIN user_role ur ON u.id = ur.`UID`
LEFT OUTER JOIN role r ON r.id = ur.`RID`
<?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"> <mapper namespace="com.itcast.dao.IUserDao">
<!--定义user的resultMap-->
<resultMap id="userAccountMap" type="user">
<id property="id" column="id"></id>
<result property="username" column="username"></result>
<result property="address" column="address"></result>
<result property="sex" column="sex"></result>
<result property="birthday" column="birthday"></result>
<!--配置角色集合的映射-->
<collection property="roles" ofType="role">
<id property="roleId" column="rid"></id>
<result property="roleName" column="role_name"></result>
<result property="roleDesc" column="role_desc"></result>
</collection>
</resultMap>
<select id="findAll" resultMap="userMap" >
SELECT u.*,r.ID rid,r.ROLE_NAME,r.ROLE_DESC FROM USER u
LEFT OUTER JOIN user_role ur ON u.id = ur.UID
LEFT OUTER JOIN role r ON r.id = ur.RID
</select>
</mapper>
public class User implements Serializable {
private Integer id;
private String username;
private String address;
private String sex;
private Date birthday;
//多对多的关系映射:一个用户可以具备多个角色
private List<Role> roles; public List<Role> getRoles() {
return roles;
} public void setRoles(List<Role> roles) {
this.roles = roles;
}
四、JNDI
1、JNDI概述和原理
  • JNDI(Java Naming and Directory Interface,Java命名和目录接口)是SUN公司提供的一种标准的Java命名系统接口.
  • 是SUN公司推出的一套规范,属于JavaEE技术之一。目的是模仿windows系统中的注册表(搜索-regedit)。
    • win的 key存放的为:路径+名称
2、JNDI搭建maven的war工程
3、测试JNDI数据源的使用以及使用细节
  • 使用了tomcat的数据源,必须要经过服务器,原先的test方法无法使用
JNDI数据源

JNDI:Java Naming and Directory Interface。是SUN公司推出的一套规范,属于JavaEE技术之一。目的是模仿windows系统中的注册表。

在服务器中注册数据源:

1.1 创建Maven的war工程并导入坐标

<dependencies>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.5</version>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.6</version>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.12</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
    </dependency>

  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
  </dependency>

  <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
  </dependency>
</dependencies>

1.2 在webapp文件下创建META-INF目录

1.3 在META-INF目录中建立一个名为context.xml的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!--
<Resource
name="jdbc/eesy_mybatis"                  数据源的名称
type="javax.sql.DataSource"                   数据源类型
auth="Container"                        数据源提供者
maxActive="20"                         最大活动数
maxWait="10000"                            最大等待时间
maxIdle="5"                               最大空闲数
username="root"                            用户名
password="1234"                            密码
driverClassName="com.mysql.jdbc.Driver"          驱动类
url="jdbc:mysql://localhost:3306/eesy_mybatis" 连接url字符串
/>
 -->
<Resource
name="jdbc/eesy_mybatis"
type="javax.sql.DataSource"
auth="Container"
maxActive="20"
maxWait="10000"
maxIdle="5"
username="root"
password="1234"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/eesy_mybatis"
/>
</Context>

1.4 修改SqlMapConfig.xml中的配置

@font-face { font-family: "Times New Roman" }
@font-face { font-family: "宋体" }
@font-face { font-family: "华文楷体" }
p.MsoNormal { mso-style-name: 正文; mso-style-parent: ""; margin: 0 0 0.0001pt; mso-pagination: none; text-align: justify; text-justify: inter-ideograph; font-family: "Times New Roman"; font-size: 10.5pt; mso-font-kerning: 1.0000pt }
h2 { mso-style-name: "标题 2"; mso-style-next: 正文; margin-top: 13pt; margin-bottom: 13pt; page-break-after: avoid; mso-pagination: lines-together; text-align: center; mso-outline-level: 2; line-height: 173%; font-family: "Times New Roman"; mso-fareast-font-family: 华文楷体; font-weight: bold; font-size: 16pt }
p.MsoFooter { mso-style-name: 页脚; mso-style-noshow: yes; margin: 0 0 0.0001pt; layout-grid-mode: char; mso-pagination: none; text-align: left; font-family: "Times New Roman"; font-size: 9pt; mso-font-kerning: 1.0000pt }
p.16 { mso-style-name: 奇偶数页眉; margin: 0 0 0.0001pt; border-bottom: 1pt solid rgba(0, 0, 0, 1); mso-border-bottom-alt: 0.7500pt solid windowtext; padding: 0 0 1pt; layout-grid-mode: char; mso-pagination: none; text-align: center; font-family: "Times New Roman"; mso-fareast-font-family: 宋体; font-size: 10.5pt; mso-font-kerning: 1.0000pt }
span.msoIns { mso-style-type: export-only; mso-style-name: ""; text-decoration: underline; text-underline: single; color: rgba(0, 0, 255, 1) }
span.msoDel { mso-style-type: export-only; mso-style-name: ""; text-decoration: line-through; color: rgba(255, 0, 0, 1) }
@page { mso-page-border-surround-header: no mso-page-border-surround-footer: no }
@page Section0 { }
div.Section0 { page: Section0 }

<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.ibatis.io.Resources" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="com.itcast.dao.IUserDao" %>
<%@ page import="com.itcast.domain.User" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; utf-8" pageEncoding="utf-8" %>
<html>
<body>
<h2>Hello World!</h2>
<%
//1.读取配置文件
InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
//2.创建SqlSessionFactory工厂
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(in);
//3.使用工厂生产SqlSession对象
SqlSession sqlSession = factory.openSession();//与jsp的隐式对象session冲突
//4.使用SqlSession创建Dao接口的代理对象
IUserDao userDao = sqlSession.getMapper(IUserDao.class);
//5.使用代理对象执行方法
System.out.println("你好");
List<User> users = userDao.findAll();
for (User user : users) {
System.out.println(user);
}
//6.释放资源
sqlSession.close();
in.close();
%>
</body>
</html>



@font-face { font-family: "Times New Roman" }
@font-face { font-family: "宋体" }
@font-face { font-family: "华文楷体" }
@font-face { font-family: "Courier New" }
@font-face { font-family: "微软雅黑" }
@font-face { font-family: "Consolas" }
@list l0:level1{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"第%1章";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:21.0000pt;text-indent:-21.0000pt;font-family:宋体;}
@list l0:level2{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:255.6500pt;text-indent:-28.8000pt;font-family:宋体;}
@list l0:level3{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:36.0000pt;text-indent:-36.0000pt;font-family:宋体;}
@list l0:level4{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:43.2000pt;text-indent:-43.2000pt;font-family:宋体;mso-ascii-font-family:'Times New Roman';mso-hansi-font-family:'Times New Roman';mso-bidi-font-family:'Times New Roman';letter-spacing:0.0000pt;text-transform:none;font-style:normal;font-variant:normal;}
@list l0:level5{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4.%5";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:50.4000pt;text-indent:-50.4000pt;font-family:宋体;}
@list l0:level6{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4.%5.%6";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:57.6000pt;text-indent:-57.6000pt;font-family:宋体;}
@list l0:level7{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4.%5.%6.%7";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:64.8000pt;text-indent:-64.8000pt;font-family:宋体;}
@list l0:level8{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4.%5.%6.%7.%8";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:72.0000pt;text-indent:-72.0000pt;font-family:宋体;}
@list l0:level9{
mso-level-number-format:decimal;
mso-level-suffix:tab;
mso-level-text:"%1.%2.%3.%4.%5.%6.%7.%8.%9";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:79.2000pt;text-indent:-79.2000pt;font-family:宋体;}
p.MsoNormal { mso-style-name: 正文; mso-style-parent: ""; margin: 0 0 0.0001pt; mso-pagination: none; text-align: justify; text-justify: inter-ideograph; font-family: "Times New Roman"; font-size: 10.5pt; mso-font-kerning: 1.0000pt }
h1 { mso-style-name: "标题 1"; mso-style-next: 正文; margin-top: 17pt; margin-bottom: 16.5pt; margin-left: 21pt; text-indent: -21pt; page-break-after: avoid; mso-pagination: lines-together; text-align: center; mso-outline-level: 1; line-height: 240%; font-family: "Times New Roman"; font-weight: bold; font-size: 22pt; mso-font-kerning: 22.0000pt }
h2 { mso-style-name: "标题 2"; mso-style-next: 正文; margin-top: 13pt; margin-bottom: 13pt; margin-left: 255.65pt; text-indent: -28.8pt; page-break-after: avoid; mso-pagination: lines-together; text-align: center; mso-outline-level: 2; line-height: 173%; font-family: "Times New Roman"; mso-fareast-font-family: 华文楷体; font-weight: bold; font-size: 16pt }
p.MsoFooter { mso-style-name: 页脚; mso-style-noshow: yes; margin: 0 0 0.0001pt; layout-grid-mode: char; mso-pagination: none; text-align: left; font-family: "Times New Roman"; font-size: 9pt; mso-font-kerning: 1.0000pt }
p.16 { mso-style-name: 奇偶数页眉; margin: 0 0 0.0001pt; border-bottom: 1pt solid rgba(0, 0, 0, 1); mso-border-bottom-alt: 0.7500pt solid windowtext; padding: 0 0 1pt; layout-grid-mode: char; mso-pagination: none; text-align: center; font-family: "Times New Roman"; mso-fareast-font-family: 宋体; font-size: 10.5pt; mso-font-kerning: 1.0000pt }
p.17 { mso-style-name: 例程代码(无行号); margin: 0 0 0.0001pt; text-indent: 21pt; mso-pagination: none; text-align: justify; text-justify: inter-ideograph; background: rgba(224, 224, 224, 1); font-family: "Courier New"; font-size: 9pt; mso-font-kerning: 1.0000pt; mso-shading: rgb(224,224,224) }
span.msoIns { mso-style-type: export-only; mso-style-name: ""; text-decoration: underline; text-underline: single; color: rgba(0, 0, 255, 1) }
span.msoDel { mso-style-type: export-only; mso-style-name: ""; text-decoration: line-through; color: rgba(255, 0, 0, 1) }
@page { mso-page-border-surround-header: no mso-page-border-surround-footer: no }
@page Section0 { margin-top: 72pt margin-bottom: 72pt margin-left: 70.9pt margin-right: 70.9pt size: 595.3000pt 841.9000pt layout-grid: 15.6000pt }
div.Section0 { page: Section0 }

MyBatis03:连接池及事务控制、xml动态SQL语句、多表操作的更多相关文章

  1. 【MyBatis】MyBatis 连接池和事务控制

    MyBatis 连接池和事务控制 文章源码 MyBaits 连接池 实际开发中都会使用连接池,因为它可以减少获取连接所消耗的时间.具体可查看 MyBatis 数据源配置在 SqlMapConfig.x ...

  2. Junit 注解 类加载器 .动态代理 jdbc 连接池 DButils 事务 Arraylist Linklist hashset 异常 哈希表的数据结构,存储过程 Map Object String Stringbufere File类 文件过滤器_原理分析 flush方法和close方法 序列号冲突问题

    Junit 注解 3).其它注意事项: 1).@Test运行的方法,不能有形参: 2).@Test运行的方法,不能有返回值: 3).@Test运行的方法,不能是静态方法: 4).在一个类中,可以同时定 ...

  3. JNDI和在tomcat中配置DBCP连接池 元数据的使用 DBUtils框架的使用 多表操作

    1 JNDI和在tomcat中配置DBCP连接池 JNDI(Java Naming and Directory Interface),Java命名和目录接口,它对应于J2SE中的javax.namin ...

  4. MyBatis基础_连接池与事务、动态SQL、注解开发

    一.MyBatis连接池及事务控制 1.连接池 在实际开发中,都会使用连接池,因为它可以减少获取连接缩消耗的时间.所谓连接池,就是存储数据库连接的容器.连接池中存储一定数量的数据库连接,当线程需要使用 ...

  5. 存储过程中执行动态Sql语句

    MSSQL为我们提供了两种动态执行SQL语句的命令,分别是EXEC和sp_executesql;通常,sp_executesql则更具有优势,它提供了输入输出接口,而EXEC没有.还有一个最大的好处就 ...

  6. 怎样SQL存储过程中执行动态SQL语句

    MSSQL为我们提供了两种动态执行SQL语句的命令,分别是EXEC和sp_executesql;通常,sp_executesql则更具有优势,它提供了输入输出接口,而EXEC没有.还有一个最大的好处就 ...

  7. Spring Boot1.5.4 连接池 和 事务

    原文:https://github.com/x113773/testall/issues/10 默认连接池---spring Boot中默认支持的连接池有Tomcat.HikariCP .DBCP . ...

  8. (2.3)DDL增强功能-流程化控制与动态sql

    1.流程控制 在T-SQL中,与流程控制语句相关的关键字有8个: BEGIN...END BREAK GOTO CONTINUE IF...ELSE WHILE RETURN WAITFOR 其实还可 ...

  9. mybatis--MyBatis动态SQL语句

    mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类: 1. if 语句 (简单的条件判断) 2. ...

  10. MyBatis学习(三)、动态SQL语句

    三.动态SQL语句 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空,此时查询出的结果很可能是空的,也许我们需要参数为空时,是查出全部的信息.使用Orac ...

随机推荐

  1. Python实验报告——第2章 Python语言基础

    实验报告 [实验目的] 1.熟悉在线编程平台. 2.掌握基本的 python 程序编写.编译与运行程序的方法. [实验条件] 1.PC机或者远程编程环境 [实验内容] 1.完成第二章实例01-07,实 ...

  2. 第六章:Django 综合篇 - 17:CSRF与AJAX

    CSRF(Cross-site request forgery)跨站请求伪造,是一种常见的网络攻击手段,具体内容和含义请大家自行百度. Django为我们提供了防范CSRF攻击的机制. 一.基本使用 ...

  3. service服务使用CoreDNS提供的域名地址访问

    普通的 Service:会生成 servicename.namespace.svc.cluster.local 的域名,会解析到 Service 对应的 ClusterIP 上,在 Pod 之间的调用 ...

  4. 第三章:模版层 - 2:Django内置模板标签

    Django内置标签总览 可以查询下表来总览Django的内置标签: 标签 说明 autoescape 自动转义开关 block 块引用 comment 注释 csrf_token CSRF令牌 cy ...

  5. activeMq不能被主机访问的问题

    环境说明 主机:mac 虚拟机:VirtualBox 虚拟系统:Centos6.5 问题:虚拟机启动了 activemq. 也关闭了防火墙,但是在主机访问web界面,http://192.168.1. ...

  6. for循环及range内置方法

    目录 while循环补充说明 流程控制之for循环 range方法 rang实战案例 作业 """ 1.先写注释(思维逻辑和想法) 2.先考虑主体功能 在考虑附加功能 & ...

  7. 4.ElasticSearch系列之基本概念

    1. 文档 ElasticSearch是面向文档的,文档是所有可搜索数据的最小单位 文档会被序列化成JSON格式,保存在ES中 每个文档都有一个unique ID #查看前10条文档,了解文档格式 P ...

  8. Codeforces Round #829 (Div. 2)/CodeForces1754

    CodeForces1754 注:所有代码均为场上所书 Technical Support 解析: 题目大意 给定一个只包含大写字母 \(\texttt{Q}\) 和 \(\texttt{A}\) 的 ...

  9. 4.可视化API

    模式视图(可浏览api界面) #导包 依赖coreapi from rest_framework.schemas import get_schema_view # 将get_schema_view视图 ...

  10. JUC中的AQS底层详细超详解

    摘要:当你使用java实现一个线程同步的对象时,一定会包含一个问题:你该如何保证多个线程访问该对象时,正确地进行阻塞等待,正确地被唤醒? 本文分享自华为云社区<JUC中的AQS底层详细超详解,剖 ...