<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>薛磊</title>
    <description>DaLian369个人博客</description>
    <link>https://DaLian369.github.io/</link>
    <atom:link href="https://DaLian369.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 24 Sep 2019 03:48:05 +0000</pubDate>
    <lastBuildDate>Tue, 24 Sep 2019 03:48:05 +0000</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>etcd集群搭建</title>
        <description>&lt;h2 id=&quot;etcd集群搭建&quot;&gt;etcd集群搭建&lt;/h2&gt;

etcd的项目：https://github.com/coreos/etcd/releases/tag/v3.2.10 ，下载最新版本etcd。

系统：

&lt;blockquote&gt;
  etcd-1：192.168.159.129

  etcd-2：192.168. 159.130

  etcd-3：192.168. 159.131
&lt;/blockquote&gt;

&lt;strong&gt;1.在windows环境下下载etcd-v3.2.10-linux-amd64.tar.gz，并提供etcd命令。&lt;/strong&gt;

&lt;blockquote&gt;
  通过putty或MobaXterm将压缩包上传到三个linux系统中，再进行解压。

  tar –xzvf ext etcd-v3.2.10-linux-amd64.tar.gz

  cd etcd-v3.2.10-linux-amd64

  cp etcd etcdctl /user/local/bin/
&lt;/blockquote&gt;

&lt;strong&gt;2.在三个节点上创建etcd数据目录。&lt;/strong&gt;

&lt;blockquote&gt;
  mkdir –p /var/lib/etcd
&lt;/blockquote&gt;

&lt;strong&gt;3.在每个节点上创建etcd的配置文件&lt;/strong&gt;

&lt;blockquote&gt;
  首先在每个节点上创建目录和文件，sudo vi /etc/etcd/etcd.yml，打开文件进行配置。
&lt;/blockquote&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;name : etcd-1
data-dir : /var/lib/etcd
initial-advertise-peer-urls : http://192.168.159.129:2380
listen-peer-urls : http://192.168.159.129:2380
listen-client-urls : http://192.168.159.129:2379,http://127.0.0.1:2379
advertise-client-urls : http://192.168.159.129:2379,http://127.0.0.1:2379
initial-cluster-token : etcd-cluster-token
initial-cluster : etcd-2=http://192.168.159.130:2380,etcd-1=http://192.168.159.129:2380,etcd-3=http://192.168.159.131:2380
initial-cluster-state : new
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;name : etcd-2
data-dir : /var/lib/etcd
listen-client-urls : http://192.168.159.130:2379,http://127.0.0.1:2379
advertise-client-urls : http://192.168.159.130:2379,http://127.0.0.1:2379
listen-peer-urls : http://192.168.159.130:2380
initial-advertise-peer-urls : http://192.168.159.130:2380
initial-cluster : etcd-1=http://192.168.159.129:2380,etcd-2=http://192.168.159.130:2380,etcd-3=http://192.168.159.131:2380
initial-cluster-token : etcd-cluster-token
initial-cluster-state : new
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;name : etcd-3
initial-advertise-peer-urls : http://192.168.159.131:2380
listen-peer-urls : http://192.168.159.131:2380
listen-client-urls : http://192.168.159.131:2379,http://127.0.0.1:2379
advertise-client0urls : http://192.168.159.131:2379,http://127.0.0.1:2379
initial-cluster-token : etcd-cluster-token
initial-cluster : etcd-2=http://192.168.159.130:2380,etcd-1=http://192.168.159.129:2380,etcd-3=http://192.168.159.131:2380
initial-cluster-state : new
data-dir : /var/lib/etcd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

系统默认的etcd版本是2.x，需要在/etc/profile 这个全局变量文件里加入&lt;code class=&quot;highlighter-rouge&quot;&gt;export ETCDCTL_API=3&lt;/code&gt;保存。

输入命令 &lt;code class=&quot;highlighter-rouge&quot;&gt;source profile&lt;/code&gt;系统重读配置文件

&lt;strong&gt;4.启动服务，进行测试&lt;/strong&gt;

执行&lt;code class=&quot;highlighter-rouge&quot;&gt;sudo etcd --config-file=/etc/etcd/etcd.yml &amp;amp;&lt;/code&gt; 命令，启动三个节点上的etcd服务。

启动成功后，进行测试。

在etcd-1上输入指令&lt;code class=&quot;highlighter-rouge&quot;&gt; etcdctl put xuelei 123&lt;/code&gt;，在etcd-2上输入指令&lt;code class=&quot;highlighter-rouge&quot;&gt;etcdctl get xuelei&lt;/code&gt; ，看etcd-2上能否获取到键值对。

&lt;strong&gt;5.注意&lt;/strong&gt;

①   可以下载MobaXterm来链接Linux系统，这样可以方便执行粘贴复制。

②   可以通过MobaXterm或putty将压缩包上传到Linux系统。

③   sudo apt-get install xx 可以安装缺少的指令。

④   在编写配置文件时注意，数据均为JSON格式，是键值对，在 : 前后需加上空格，否则会报错误。

&lt;strong&gt;6.etcd集群搭建必需配置参数&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;参数&lt;/th&gt;
      &lt;th&gt;描述&lt;/th&gt;
      &lt;th&gt;默认/推荐设置&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;name&lt;/td&gt;
      &lt;td&gt;etcd实例的名称&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;data-dir&lt;/td&gt;
      &lt;td&gt;数据保存的路径&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;listen-client-urls&lt;/td&gt;
      &lt;td&gt;对外提供服务的地址&lt;/td&gt;
      &lt;td&gt;http://ip:2379,   http://127.0.0.1:2379&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;listen-peer-urls&lt;/td&gt;
      &lt;td&gt;和同伴通讯的地址&lt;/td&gt;
      &lt;td&gt;http://ip:2380&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;advertise-client-urls&lt;/td&gt;
      &lt;td&gt;对外公布的该节点客户端监听地址&lt;/td&gt;
      &lt;td&gt;http://ip:2379,   http://127.0.0.1:2379&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;initial-advertise-peer-urls&lt;/td&gt;
      &lt;td&gt;该节点同伴监听地址&lt;/td&gt;
      &lt;td&gt;http://ip:2380&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;initial-cluster&lt;/td&gt;
      &lt;td&gt;集群中所有节点的信息&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;initial-cluster-token&lt;/td&gt;
      &lt;td&gt;创建集群的token&lt;/td&gt;
      &lt;td&gt;这个token需要在集群中保持唯一&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;initial-cluster-state&lt;/td&gt;
      &lt;td&gt;集群状态&lt;/td&gt;
      &lt;td&gt;新创建集群的时候，这个值为new，已存在的集群，这个值为existing&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</description>
        <pubDate>Tue, 16 Jul 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/07/16/etcd%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/07/16/etcd%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA/</guid>
        
        <category>etcd集群搭建</category>
        
        
        <category>etcd集群搭建</category>
        
      </item>
    
      <item>
        <title>MySql</title>
        <description>&lt;a id=&quot;top&quot;&gt;&lt;/a&gt;
&lt;a href=&quot;#dql&quot;&gt;一、DQL语言&lt;/a&gt;

&lt;a href=&quot;#dml&quot;&gt;二、DML语言&lt;/a&gt;

&lt;a href=&quot;#ddl&quot;&gt;三、DDL语言&lt;/a&gt;

&lt;a href=&quot;#tcl&quot;&gt;四、TCL语言-事务&lt;/a&gt;

&lt;a href=&quot;#other&quot;&gt;五、其他&lt;/a&gt;

&lt;ul&gt;
  &lt;li&gt; &lt;a href=&quot;#other-view&quot;&gt;视图&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt; &lt;a href=&quot;#other-var&quot;&gt;变量&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt; &lt;a href=&quot;#other-fun&quot;&gt;函数&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt; &lt;a href=&quot;#other-proc&quot;&gt;存储过程&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;strong&gt;SQL的语言分类&lt;/strong&gt;

​	DQL（Data Query Language）：数据查询语言
​		select

​	DML(Data Manipulate Language):数据操作语言
​		insert 、update、delete

​	DDL（Data Define Languge）：数据定义语言
​		create、drop、alter

​	TCL（Transaction Control Language）：事务控制语言
​		commit、rollback

&lt;strong&gt;1.数据库的好处&lt;/strong&gt;

&lt;blockquote&gt;
  (1)可以持久化数据到本地

  (2)结构化查询
&lt;/blockquote&gt;

&lt;strong&gt;2.数据库的常见概念&lt;/strong&gt;

&lt;blockquote&gt;
  DB：数据库，存储数据的容器

  DBMS：数据库管理系统，又称为数据库软件或数据库产品，用于创建或管理DB

  SQL：结构化查询语言，用于和数据通信的语言。
&lt;/blockquote&gt;

&lt;strong&gt;3.数据库存储的特点&lt;/strong&gt;

&lt;blockquote&gt;
  (1)数据库存放到表中，然后表再放到库中

  (2)一个库可以有多张表，每张表具有唯一的表名用来标识自己

  (3)表中有一个或多个列，即“字段，相当于java中的属性

  (4)表中的每一行数据，相当于java中“对象”
&lt;/blockquote&gt;

&lt;strong&gt;4.MySQL的优点&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 开源、免费、成本低

  (2) 性能高、移植性也好

  (3) 体积小，便于安装
&lt;/blockquote&gt;

&lt;strong&gt;5.MySQL服务的启动和停止&lt;/strong&gt;

&lt;blockquote&gt;
  方式一：计算机—右键管理—服务

  方式二：通过管理员身份运行

  net start 服务名 (启动服务)

  net stop 服务名 (停止服务)
&lt;/blockquote&gt;

&lt;strong&gt;6.MySQL服务的登陆和退出&lt;/strong&gt;

&lt;blockquote&gt;
  方式一：通过mysql自带的客户端，只限于root用户

  方式二：通过windows自带的

  登陆：mysql [-h 主机名 -P端口号] -u用户名 -p密码

  退出：exit 或 ctrl+c
&lt;/blockquote&gt;

&lt;strong&gt;7.MySQL的常见命令&lt;/strong&gt;

(1)查看当前所有的数据库

&lt;blockquote&gt;
  show database;
&lt;/blockquote&gt;

(2)打开指定的库

&lt;blockquote&gt;
  use 库名
&lt;/blockquote&gt;

(3)查看当前库的所有表

&lt;blockquote&gt;
  show tables;
&lt;/blockquote&gt;

(4)查看其他库的所有表

&lt;blockquote&gt;
  show tables from 库名;
&lt;/blockquote&gt;

(5)创建表

&lt;blockquote&gt;
  create table 表名(

  ​	列名	列类型,

  ​	…

  );
&lt;/blockquote&gt;

(6)查看表结构

&lt;blockquote&gt;
  desc 表名;
&lt;/blockquote&gt;

(7)查看服务器的版本

&lt;blockquote&gt;
  方式一：登陆到Mysql服务端

  ​	select version();

  方式二：没有登录到Mysql服务端

  ​	mysql –version 	或	mysql -V
&lt;/blockquote&gt;

&lt;strong&gt;8.MySQL的语法规范&lt;/strong&gt;

&lt;blockquote&gt;
  1.不区分大小写，但建议关键字大写，表名、列名小写

  2.每条命令最好用分号结尾

  3.每条命令根据需要，可以进行所街或换行

  4.注释

  &lt;blockquote&gt;
    单行注释：#注释文字

    单行注释：– 注释文字

    多行注释：/* 注释文字 */
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;a id=&quot;dql&quot;&gt;&lt;/a&gt;

&lt;h3 id=&quot;dql语言学习&quot;&gt;DQL语言学习&lt;/h3&gt;

&lt;strong&gt;语法&lt;/strong&gt;

&lt;blockquote&gt;
  select 查询列表

  from 表名

  【where 筛选条件】

  group by 分组的字段

  【having 分组胡的筛选】

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;【order by 排序列表】 【asc&lt;/td&gt;
        &lt;td&gt;desc】&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/blockquote&gt;

&lt;strong&gt;筛选条件的分类&lt;/strong&gt;

(1).简单条件运算符

&lt;blockquote&gt;
  &amp;gt; &amp;lt; = &amp;lt;&amp;gt; != &amp;gt;= &amp;lt;= &amp;lt;=&amp;gt;安全等于
&lt;/blockquote&gt;

(2).逻辑运算符

&lt;blockquote&gt;
  &amp;amp;&amp;amp;  and

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt; &lt;/td&gt;
        &lt;td&gt;or&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  !      not
&lt;/blockquote&gt;

(3).模糊查询

&lt;blockquote&gt;
  like：一般搭配通配符使用，用于判断字符型数值或数值型

  通配符：%任意多个字符，_任意单个字符

  between and

  in

  is null  /  is not null
&lt;/blockquote&gt;

&lt;strong&gt;is null  pk  &amp;lt;=&amp;gt;&lt;/strong&gt;

&lt;blockquote&gt;
  is null ：仅仅可以判断null值，可读性较高。

  &amp;lt;=&amp;gt;：既可以判断null值，又可以判断普通的数值，可读性较低。
&lt;/blockquote&gt;

&lt;strong&gt;去重&lt;/strong&gt;

&lt;blockquote&gt;
  select distinct id from user;
&lt;/blockquote&gt;

&lt;strong&gt;+的作用&lt;/strong&gt;

&lt;blockquote&gt;
  mysql里仅仅只有一个功能：运算符

  select 100+90;

  select ‘123’+90;其中一方为字符型，若转换成功则继续做加法运算

  select ‘john’+90;若转换失败，则将字符型转换为0

  select null+0; 若其中一方为null，则结果肯定为null

  查询员工名和姓连接成一个字段，并显示为 姓名

  select concat(‘a’,’b’,’c’);
&lt;/blockquote&gt;

ifnull(money,0)

&lt;blockquote&gt;
  如果为null，则为0
&lt;/blockquote&gt;

isnull函数

&lt;blockquote&gt;
  如果为null，返回1,否则返回0
&lt;/blockquote&gt;

&lt;strong&gt;10.单行函数&lt;/strong&gt;

&lt;strong&gt;字符函数：&lt;/strong&gt;

&lt;blockquote&gt;
  length	字符串长度

  concat	连接字符串

  substr	截取字符串

  instr	查看字符串中某子字符串位置

  trim	去前后相同字符

  upper

  lower

  lpad	左填充

  rpad	右填充
&lt;/blockquote&gt;

&lt;strong&gt;数学函数：&lt;/strong&gt;

&lt;blockquote&gt;
  round	四舍五入

  ceil	向上取整

  floor	向下取整

  truncate	截断

  rand	获取随机数，返回0-1之间的小数

  mod	求模
&lt;/blockquote&gt;

&lt;strong&gt;日期函数：&lt;/strong&gt;

&lt;blockquote&gt;
  now

  curdate	curtime

  year	month

  monthname	以英文形式返回月

  day	hour	minute	second

  str_to_date

  date_format

  datediff	求相差天数
&lt;/blockquote&gt;

&lt;strong&gt;其他函数:&lt;/strong&gt;

&lt;blockquote&gt;
  version

  database

  user

  password(‘字符’)	返回该字符的密码形式

  md5(‘字符’)	返回该字符的md5加密形式
&lt;/blockquote&gt;

&lt;strong&gt;控制函数：&lt;/strong&gt;

&lt;blockquote&gt;
  if(条件表达式，表达式1,表达式2)

  case

  &lt;blockquote&gt;
    case 变量或表达式或字段

    when 常量1 then 值1

    …

    else 值n

    end
  &lt;/blockquote&gt;

  &lt;blockquote&gt;

    case 变量或表达式或字段

    when 条件1 then 值1

    …

    else 值n

    end
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;strong&gt;11.分组函数&lt;/strong&gt;

&lt;blockquote&gt;
  sum	求和

  avg	平均值

  max	最大值

  min	最小值

  count	计算个数

  (1)

  &lt;blockquote&gt;
    sum、avg处理数值类型

    max、min、count可以处理任何类型
  &lt;/blockquote&gt;

  (2)都忽略null值

  (3)可以和distinct搭配实现去重的运算

  (4)统计行数，效率

  &lt;blockquote&gt;
    count(字段)：统计该字段非空值的个数

    count(*)：统计结果集的行数

    MYISAM存储引擎下，count(*)的效率最高

    INNODB存储引擎下，count(*)和count(1)的效率差不多，比count(字段)要高一些
  &lt;/blockquote&gt;

  (5)和分组函数一同查询的字段要求是group by后的字段

  可以先写select，from，gourp by，再写where，having
&lt;/blockquote&gt;

1.分组查询中的筛选条件分为两类

&lt;blockquote&gt;
  ①分组函数做条件肯定是放在having子句中。

  ②能用分组前筛选的，就优先考虑使用分组前筛选。
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th&gt;数据源&lt;/th&gt;
      &lt;th&gt;位置&lt;/th&gt;
      &lt;th&gt;关键字&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;分组前筛选&lt;/td&gt;
      &lt;td&gt;原始表&lt;/td&gt;
      &lt;td&gt;group by子句的前面&lt;/td&gt;
      &lt;td&gt;where&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;分组后筛选&lt;/td&gt;
      &lt;td&gt;分组后的结果集&lt;/td&gt;
      &lt;td&gt;group by子句的后面&lt;/td&gt;
      &lt;td&gt;having&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

2.group by子句支持单个字段分组，多个字段分组(多个字段之间用逗号隔开没有顺序要求)

3.也可以添加排序（排序放在整个分组查询的最后

&lt;strong&gt;12.分组查询&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组函数&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;列&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;要求出现在&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;的后面&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组的列表&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;子句】&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;avg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;gourp&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;avg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;avg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;13.进阶6：连接查询&lt;/strong&gt;

含义：又称多表查询，当查询的字段来自多个表时，就会用到多表查询

笛卡尔乘积现象：当查询多个表时，没有添加有效的链接条件，导致多个表所有行实现完全连接。

发生原因：没有有效的连接条件

如何避免：添加有效的连接条件

按功能分类：

&lt;blockquote&gt;
  内连接：

  &lt;blockquote&gt;
    等值连接、非等值连接、自连接
  &lt;/blockquote&gt;

  外链接：

  &lt;blockquote&gt;
    左外连接、右外连接、全外连接(mysql不支持)
  &lt;/blockquote&gt;

  交叉连接
&lt;/blockquote&gt;

&lt;strong&gt;(1) SQL92语法&lt;/strong&gt;

&lt;strong&gt;①等值连接&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组字段】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组后的筛选】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;排序字段】&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

特点：

&lt;blockquote&gt;
  a.一般为表其别名

  b.多表的顺序可以调换

  c.n表连接至少需要n-1个连接条件

  d.等值连接的结果是多表的交集部分
&lt;/blockquote&gt;

&lt;strong&gt;②非等值连接&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;非等值的连接条件&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组字段】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组后的筛选】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;排序字段】&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;③自连接&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;等值的连接条件&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组字段】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组后的筛选】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;排序字段】&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(2) SQL99语法&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【连接类型】&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;别名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;连接条件&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;排序列表】&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;limit&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;子句&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;分类：&lt;/strong&gt;

&lt;blockquote&gt;
  内连接：inner

  外连接：

  &lt;blockquote&gt;
    左外：left 【outer】

    右外：right 【outer】

    全外：full 【outer】
  &lt;/blockquote&gt;

  交叉连接：cross
&lt;/blockquote&gt;

&lt;strong&gt;①内连接&lt;/strong&gt;

&lt;blockquote&gt;
  分类：

  等值、非等值、自连接
&lt;/blockquote&gt;

特点：

&lt;blockquote&gt;
  ①表的顺序可以调换

  ②内连接的结果 = 多表的交集

  n表连接至少需要n-1个连接文件
&lt;/blockquote&gt;

&lt;strong&gt;②外连接&lt;/strong&gt;

&lt;strong&gt;应用场景:&lt;/strong&gt;用于查询一个表中有，另一个表没有的记录

特点：

&lt;blockquote&gt;
  a.外连接的查询结果为主表中的所有行

  ​	如果从表中有和它匹配的，则显示匹配的值

  ​	如果从表中没有和它匹配的，则显示null

  ​	外连接查询结果 = 内连接结果 + 主表中有而从表没有的记录

  b.左外连接，left join 左边的是主表

  右外连接，right join 右边的是主表

  全外连接，full join 两边都是主表

  c.左外和右外交换两个表的顺序，可以实现同样的效果。

  d.全外连接 = 内连接的结果 + 表1中有但表2没有的 + 表2中有但表1没有的。

  e.一般用于查询除了交集部分的剩余的不匹配的行。
&lt;/blockquote&gt;

&lt;strong&gt;③交叉连接&lt;/strong&gt;

特点：

&lt;blockquote&gt;
  类似于笛卡尔积
&lt;/blockquote&gt;

&lt;strong&gt;(3) sql92和sql99 PK&lt;/strong&gt;

&lt;blockquote&gt;
  功能：sql99支持的较多。

  可读性：sql99实现连接条件和筛选条件的分离，可读性较高。
&lt;/blockquote&gt;

&lt;strong&gt;14.进阶7：子查询&lt;/strong&gt;

&lt;strong&gt;含义：&lt;/strong&gt;

&lt;blockquote&gt;
  嵌套在其他语句中的select语句，成为子查询或内查询；

  外面的语句可以使insert、update、delete、select等，一般select作为外面语句较多。
&lt;/blockquote&gt;

&lt;strong&gt;分类：&lt;/strong&gt;

按子查询出现的位置：

&lt;blockquote&gt;
  select后面：

  ​	仅仅支持标量子查询

  from后面：

  ​	支持表子查询

  where或having后面：

  ​		标量子查询	(单行)	√

  ​		列子查询    	(多行)	√

  ​		行子查询

  exists后面 （相关子查询）：

  ​		标量子查询

  ​		列子查询

  ​		行子查询

  ​		表子查询
&lt;/blockquote&gt;

&lt;strong&gt;按结果集的行列数不同：&lt;/strong&gt;

&lt;blockquote&gt;
  标量子查询	(结果集只有一行一列)

  列子查询    	(结果集只有多行一列)

  行子查询    	(结果集有多行多列)

  表子查询    	(结果集一般为多行多列)
&lt;/blockquote&gt;

&lt;strong&gt;where或having后面&lt;/strong&gt;

&lt;strong&gt;特点：&lt;/strong&gt;

&lt;blockquote&gt;
  a.子查询放在小括号内

  b.子查询一般放在条件的右侧

  c.标量子查询，一般搭配着单行操作符使用

  ​	&amp;gt;	&amp;lt;	&amp;gt;=	&amp;lt;=	=	&amp;lt;&amp;gt;

  ​	列子查询，一般搭配着多行操作符使用

  ​	in、any/some、all

  d.子查询的执行优先于主查询执行，主查询的条件用到了子查询的结果
&lt;/blockquote&gt;

&lt;strong&gt;(1)标量子查询&lt;/strong&gt;

案例：返回job_id与141号员工相同，salary比143号员工多的员工   姓名、job_id和工资

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;①查询&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;141&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;号员工的&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;141&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;②查询&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;143&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;号员工的&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;143&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;③查询员工的姓名，&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;和工资，要求&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;①并且&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;②&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;job_id&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;141&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;143&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

案例：查询最低工资的员工姓名和工资

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;①最低工资&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;②查询员工的姓名和工资，要求工资&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;①&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(2)列子查询(多行子查询)&lt;/strong&gt;

案例：返回location_id是1400或1700的部门中的所有员工姓名

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;①查询&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;location_id&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;是&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1400&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;或&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1700&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;的部门编号&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;distinct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;departments&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;locaion_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1700&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;②查询员工姓名，要求部门号是①列表中的某一个&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;--也可替换为 = any&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;distinct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department_id&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;departments&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;locaion_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1400&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1700&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

案例：查询所有的是领导的员工姓名

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;①查询所有员工的&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;manager_id&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;distinct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;manager_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;②查询姓名，&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;属于①列表的一个&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;manager_id&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(3)行子查询（结果集一行多列或多行多列）&lt;/strong&gt;

案例：查询员工编号最小并且工资最高的员工信息

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;employee_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;employees&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;15.进阶8：分页查询&lt;/strong&gt;

&lt;strong&gt;应用场景：&lt;/strong&gt;当要显示的数据，一页显示不全，需要分页提交sql请求

&lt;strong&gt;语法：&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt;				  &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;						&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;			&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;连接条件&lt;/span&gt;					  &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选条件&lt;/span&gt;				  &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组字段&lt;/span&gt;			  &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;having&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;分组后的筛选&lt;/span&gt;	   		 &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;排序的字段&lt;/span&gt;			  &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;limit&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			 &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- offset要显示条目的起始索引（起始索引从0开始）&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;-- size 要显示的条目个数&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;特点：&lt;/strong&gt;

&lt;blockquote&gt;
  ①limit语句放在查询语句的最后

  ②公式

  要显示的页数page，每页的条目数size

  select 查询列表

  from 表

  limit  (page-1)*size,size;
&lt;/blockquote&gt;

&lt;strong&gt;16.进阶8：联合查询&lt;/strong&gt;

union  联合  合并：将多条查询语句的结果合并成一个结果

语法：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;查询语句&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;union&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;查询语句&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;union&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

应用场景：

&lt;blockquote&gt;
  要查询的结果来自于多个表，且多个表没有直接的连接关系，但查询的信息一致时
&lt;/blockquote&gt;

特点：

&lt;blockquote&gt;
  ①要求多条查询语句的查询列数是一致的

  ②要求多条查询语句的查询的每一列的类型和顺序最好一直

  ③union关键字默认去重，如果使用union all 可以包含重复项
&lt;/blockquote&gt;

&lt;a id=&quot;dml&quot;&gt;&lt;/a&gt;

&lt;h3 id=&quot;dml语言&quot;&gt;DML语言&lt;/h3&gt;

&lt;strong&gt;1.插入&lt;/strong&gt;

&lt;strong&gt;方式一&lt;/strong&gt;

语法：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;into&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

特点：

&lt;blockquote&gt;
  (1) 要求值的类型和字段的类型要一致或兼容

  (2) 字段的个数和顺序不一定与原始表中的字段个数和顺序一致

  ​	但必须保证值和字段一一对应

  (3) 假如表中有可以为null的字段，注意可以通过以下两种方式插入Null值

  ​	①字段和值都省略

  ​	②字段写上，值使用null

  (4) 字段和值的个数必须一致

  (5) 字段名可以省略，默认所有列
&lt;/blockquote&gt;

&lt;strong&gt;方式二&lt;/strong&gt;

语法：

&lt;blockquote&gt;
  insert into 表名 set 字段=值,字段=值,…;
&lt;/blockquote&gt;

&lt;strong&gt;两种方式的区别：&lt;/strong&gt;

&lt;blockquote&gt;
  1.方式一支持一次插入多行，语法如下

  ​	insert into 表名 values(值,…), (值,…),… ;

  2.方式一支持子查询，语法如下：

  ​	insert into 表名  查询语句：
&lt;/blockquote&gt;

&lt;strong&gt;2.修改&lt;/strong&gt;

&lt;strong&gt;修改单表的记录&lt;/strong&gt;

语法：

&lt;blockquote&gt;
  update 表名 set 字段=值,字段=值  【where 筛选条件】;
&lt;/blockquote&gt;

&lt;strong&gt;修改多表的记录&lt;/strong&gt;

语法：

&lt;blockquote&gt;
  update 表1 别名

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;left&lt;/td&gt;
        &lt;td&gt;right&lt;/td&gt;
        &lt;td&gt;inner join 表2 别名&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  on 连接条件

  set 字段=值,字段=值

  【where 筛选条件】;
&lt;/blockquote&gt;

&lt;strong&gt;3.删除&lt;/strong&gt;

&lt;strong&gt;方式一：使用delete&lt;/strong&gt;

&lt;strong&gt;(1)删除单表的记录&lt;/strong&gt;

&lt;blockquote&gt;
  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;语法：delete from 表名 【where 筛选条件】&lt;/td&gt;
        &lt;td&gt;【limit 条目数】&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/blockquote&gt;

&lt;strong&gt;(2)级联删除&lt;/strong&gt;

&lt;blockquote&gt;
  delete 别名1,别名2 from 表1 别名1

  &lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;inner&lt;/td&gt;
        &lt;td&gt;left&lt;/td&gt;
        &lt;td&gt;right join 表2  别名2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;

  on 连接条件

  【where 筛选条件】
&lt;/blockquote&gt;

&lt;strong&gt;方式二：使用truncate&lt;/strong&gt;

&lt;blockquote&gt;
  语法：truncate table 表名
&lt;/blockquote&gt;

&lt;strong&gt;两种方式的区别【面试题】&lt;/strong&gt;

&lt;blockquote&gt;
  1.truncate删除后，如果再插入，标识列从1开始

  delete删除后，如果再插入，标识列从断点开始

  2.delete可以添加筛选条件

  truncate不可以添加筛选条件

  3.truncate效率较高

  4.truncate没有返回值

  delete可以返回受影响的行数

  5.truncate不可以回滚

  delete可以回滚
&lt;/blockquote&gt;

&lt;a id=&quot;ddl&quot;&gt;&lt;/a&gt;

&lt;h3 id=&quot;ddl语言&quot;&gt;DDL语言&lt;/h3&gt;

&lt;strong&gt;1、库的管理&lt;/strong&gt;

&lt;strong&gt;1.创建库&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;database&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;库名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;character&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字符集名】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2.修改库&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;database&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;库名&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;character&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字符集名；&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3.删除库&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;database&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;库名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2、表的管理&lt;/strong&gt;

&lt;strong&gt;1.创建表&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】表名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;【约束】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2.修改表&lt;/strong&gt;

(1)添加列

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;列名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;类型&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段名】&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(2)修改列

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;modify&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;列名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;新类型&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【新约束】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(3)修改列名

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;change&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;旧列名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;新列名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;类型&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(4)删除列

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;列名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(5)修改表名

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rename&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;新表名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3.删除表&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】表名&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;4.复制表&lt;/strong&gt;

(1)复制表的结构

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;like&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;旧表&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(2)复制表的结构+数据

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;查询列表&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;旧表&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;筛选】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	 	
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3、数据类型&lt;/strong&gt;

&lt;strong&gt;1.数值型&lt;/strong&gt;

(1)整型

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;tinyint&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;smallint&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;mediumint&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;int/integer&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;bigint&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;字节&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;4&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;8&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

特点：

&lt;blockquote&gt;
  ①都可以设置无符号和有符号，默认有符号，通过unsigned设置无符号

  ②如果超出了范围，会报out or range 异常，插入临界值

  ③长度可以不指定，默认会有一个长度

  ​    长度代表显示的最大宽度，如果不够则左边用0填充，但需要搭配zerofill，并且默认变为无符号类型
&lt;/blockquote&gt;

&lt;strong&gt;(2)浮点型&lt;/strong&gt;

&lt;blockquote&gt;
  定点数：decimal(M,D)

  浮点数：

  ​	float(M,D)	4

  ​	double(M,D)	8
&lt;/blockquote&gt;

特点:

&lt;blockquote&gt;
  ①M代表整数部位+小数部位的个数，D代表小数部位

  ②如果超出范围，则保  out or range异常，并且插入临界值

  ③M和D都可以胜率，但对于定点数，M默认为10，D默认为0

  ④如果精度要求较高，则优先考虑使用定点数
&lt;/blockquote&gt;

&lt;strong&gt;(3)字符型&lt;/strong&gt;

char、varchar、binary、varbinary、enum、set、text、blob

&lt;blockquote&gt;
  char：固定长度的字符，写法为char(M)，最大长度不能超过M，其中M可以省略，默认为1

  varchar：可变长度的字符varchar(M)，最大长度不能超过M，其中M可以省略
&lt;/blockquote&gt;

&lt;strong&gt;4、常见的约束&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;not null&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;非空，该字段的值必填&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;unique&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;唯一，该字段的值不可重复&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;default&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;默认，该字段的值不用手动插入就有默认值&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;check&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;检查，mysql不支持&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;primary key&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;主键，该字段的值不可重复并且非空&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;froeign key&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;外键，该字段的值引用了另外的表的字段&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;主键和唯一的区别【面试题】&lt;/strong&gt;

区别：

&lt;blockquote&gt;
  1.一个表至多有一个主键，但可以有多个唯一

  2.主键不允许为空，唯一可以为空
&lt;/blockquote&gt;

相同点：

&lt;blockquote&gt;
  都具有唯一性

  都支持组合键，但不推荐
&lt;/blockquote&gt;

&lt;strong&gt;外键&lt;/strong&gt;

&lt;blockquote&gt;
  1.用于限制两个表的关系，从表的字段值引用了主表的某字段值

  2.外键列和主表的被引用列要求类型一致，意义一样，名称无要求

  3.主表的被引用列要求是一个key（一般就是主键）

  4.插入数据，先插入主表
&lt;/blockquote&gt;

&lt;strong&gt;删除数据&lt;/strong&gt;，先删除从表

&lt;strong&gt;方式一：级联删除&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stuinfo&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constraint&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fk_stu_major&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;foreign&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;majorid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;references&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;major&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;cascade&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;方式二：级联置空&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stuinfo&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;constraint&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fk_stu_major&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;foreign&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;majorid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;references&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;major&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2.创建表时添加约束&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;unique&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;constraint&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;约束名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;foreign&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reference&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;主表&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;被引用列&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;注意：&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;支持类型&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;可以起约束名&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;列级约束&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;除了外键&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;不可以&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;表级约束&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;除了非空和默认&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;可以，但对主键无效&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

列级约束可以在一个字段上追加多个，中间用空格隔开，没有顺序要求。

&lt;strong&gt;3.修改表时添加或删除约束&lt;/strong&gt;

&lt;strong&gt;(1)非空&lt;/strong&gt;

添加非空

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;modify&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

删除非空

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;modify&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(2)默认&lt;/strong&gt;

添加默认

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;modify&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

删除默认

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;modify&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;字段类型&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(3)主键&lt;/strong&gt;

添加主键

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;constraint&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;约束名】&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;primary&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

删除主键

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;primary&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(5)唯一&lt;/strong&gt;

添加唯一

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;unique&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

删除唯一

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;索引名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(5)外键&lt;/strong&gt;

添加外键

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;foreign&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;字段名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;references&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;主表&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;被引用列&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

删除外键

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;foreign&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;约束名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;a id=&quot;tcl&quot;&gt;&lt;/a&gt;

&lt;h3 id=&quot;tcl语言&quot;&gt;TCL语言&lt;/h3&gt;

&lt;strong&gt;1、事务:&lt;/strong&gt;一条或多条sql语句组成一个执行单位，一组sql语句要么都执行，要么都不执行。

&lt;strong&gt;2、特点(ACID)：&lt;/strong&gt;

&lt;blockquote&gt;
  A.原子性（Atomicity）：一个事务是不可再分割的整体，要么都执行要么都不执行；

  B.一致性（Consistency）：一个事务可以使数据从一个一致状态切换到另外一个一致的状态；

  C.隔离性（Isolation）：一个事务不受其他事务的干扰，多个事务互相隔离的；

  D.持久化（Durubility）：一个事务一旦提交了，则永久的持久化到本地。
&lt;/blockquote&gt;

&lt;strong&gt;3、事务的使用步骤：&lt;/strong&gt;

&lt;blockquote&gt;
  隐式(自动)事务：没有明显的开始和结束，本身就是一条事务可以自动提交，比如insert、update、delete

  显示事务：具有明显的开启和结束
&lt;/blockquote&gt;

&lt;strong&gt;使用显示事务：&lt;/strong&gt;

①开启事务

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;autocommit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transaction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;--可省略&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

②编写一组逻辑sql语句

注意：sql语句支持的是insert、update、delete

设置回滚点：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;savepoint&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;回滚点名；&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

③结束事务

提交：commit

回滚：rollback

回滚到指定的地方：roolback to 回滚点名；

&lt;strong&gt;4、并发事务&lt;/strong&gt;

&lt;strong&gt;1.事务的并发问题是如何发生的？&lt;/strong&gt;

&lt;blockquote&gt;
  多个事务同时操作同一个数据库的相同数据时
&lt;/blockquote&gt;

&lt;strong&gt;2.并发问题都有哪些？&lt;/strong&gt;

&lt;blockquote&gt;
  脏读：一个事务读取了其他事务还没有提交的数据，读到的是其他事务“更新”的数据。

  不可重复读：一个事务多次读取，结果不一样

  幻读：一个事务读取了其他事务还没有提交的数据，只是读到的是 其他事务“插入”的数据。
&lt;/blockquote&gt;

&lt;strong&gt;3.如何解决并发问题？&lt;/strong&gt;

&lt;blockquote&gt;
  通过设置隔离级别来解决并发问题。
&lt;/blockquote&gt;

&lt;strong&gt;4.隔离级别&lt;/strong&gt;

mysql默认的事务处理级别是’REPEATABLE-READ’,也就是可重复读。

默认系统事务隔离级别是READ COMMITTED,也就是读已提交。

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;脏读&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;不可重复读&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;幻读&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;read uncommitted：读未提交&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;read committed：读已提交&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;repeatable read：可重复读&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;×&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;serializable：串行化&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;√&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;a id=&quot;other&quot;&gt;&lt;/a&gt;
&lt;h3 id=&quot;其他&quot;&gt;其他&lt;/h3&gt;

&lt;a id=&quot;other-view&quot;&gt;&lt;/a&gt;
&lt;strong&gt;一、视图&lt;/strong&gt;

&lt;strong&gt;1、含义：&lt;/strong&gt;mysql5.1版本出现的新特性，本身是一个虚拟表，它的数据来自于表，通过执行时动态生成。

&lt;strong&gt;好处：&lt;/strong&gt;

&lt;blockquote&gt;
  1.简化了Sql语句

  2.提高了sql的重用性

  3.保护基表的数据，提高了安全性
&lt;/blockquote&gt;

&lt;strong&gt;2、创建&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;as&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;查询语句&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3、修改&lt;/strong&gt;

方式一：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;replace&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;as&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;查询语句&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

方式二：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;alter&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图名&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;as&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;查询语句&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;4、删除&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;视图&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,...&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;；&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;5、查看&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;desc&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图名；&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;show&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;view&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;视图名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;6、使用&lt;/strong&gt;

&lt;blockquote&gt;
  insert、update、delete、select
&lt;/blockquote&gt;

&lt;strong&gt;注意：&lt;/strong&gt;视图一般用于查询的，而不是更新的，所以具备以下特点的视图都不允许更新

&lt;blockquote&gt;
  ①包含分组函数、group by、distinct、having、union

  ②join

  ③常量视图

  ④where后的子查询用到了from中的表

  ⑤用到了不可更新的视图
&lt;/blockquote&gt;

&lt;strong&gt;7、视图和表的对比&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;关键字&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;是否占用物理空间&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;使用&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;视图&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;view&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;占用较小，只保存sql逻辑&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;一般用于 查询&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;表&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;table&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;保存实际的数据&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;正增删改查&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;a id=&quot;other-var&quot;&gt;&lt;/a&gt;
&lt;strong&gt;二、变量&lt;/strong&gt;

&lt;strong&gt;1、系统变量&lt;/strong&gt;

说明：变量由系统提供的，不用自定义

语法：

①查看系统变量

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;show&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;variables&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;like&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;--默认是session&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

②查看指定的系统变量的值

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;--默认是session&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

③为系统变量赋值

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值；&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@@&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2、自定义变量&lt;/strong&gt;

&lt;strong&gt;1.用户变量&lt;/strong&gt;

作用域：针对于当前连接（会话）生效

位置：begin end 里面，也可以放在外面

使用：

①声明并赋值：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

②更新值

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;--方式一：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;--方式二：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xx&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;into&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

③使用

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2.局部变量&lt;/strong&gt;

作用域：仅仅在定义它的begin end 中有效。

位置：只能放在begin end 中，而且只能放在第一句。

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pro1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;declare&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

①声明

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;declare&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;类型&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;值】&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

②赋值或更新

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;--方式一：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;值&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;--方式二：&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xx&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;into&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;表&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

③使用

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;变量名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3、存储过程和函数&lt;/strong&gt;

说明：都类似于java中的方法，将一组完成特定功能的逻辑语句包装起来，对外暴露名字。

好处：

&lt;blockquote&gt;
  ①提高了重用性

  ②sql语句简单

  ③减少了和数据库服务器连接的次数，提高了效率
&lt;/blockquote&gt;

&lt;a id=&quot;other-proc&quot;&gt;&lt;/a&gt;
&lt;strong&gt;1.存储过程&lt;/strong&gt;

(1)创建

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;存储过程名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;参数模式&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;参数名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;参数类型&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
		&lt;span class=&quot;err&quot;&gt;存储过程体&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

注意：

&lt;blockquote&gt;
  ①参数模式：in、out、inout，其中in可以省略。

  ②存储过程体的每一条sql语句都需要用分号结尾。
&lt;/blockquote&gt;

(2)调用

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;call 存储过程名(实参列表);
#举例
调用in模式的参数：call sp1('值');
调用out模式的参数：set @name; call sp1(@name);select @name;
调用inout模式的参数：set @name = 值; call sp1(@name);  select @name;
&lt;/code&gt;&lt;/pre&gt;

&lt;strong&gt;(3)查看&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;show&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;存储过程名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;(4)删除&lt;/strong&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;存储过程名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;a id=&quot;other-fun&quot;&gt;&lt;/a&gt;
&lt;strong&gt;2.函数&lt;/strong&gt;

(1)创建

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;函数名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;参数名&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;参数类型&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;returns&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;返回类型&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
	&lt;span class=&quot;err&quot;&gt;函数体&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

注意，函数体中必须要有return 语句。

(2)调用

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;函数名&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;实参列表&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

(3)查看

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;show create function 函数名;
&lt;/code&gt;&lt;/pre&gt;

(4)删除

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;drop function 函数名;
&lt;/code&gt;&lt;/pre&gt;

&lt;strong&gt;4、流程控制结构&lt;/strong&gt;

&lt;strong&gt;1.分支结构&lt;/strong&gt;

(1) if 函数

语法：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;if(条件,值1,值2)
&lt;/code&gt;&lt;/pre&gt;

位置：可以作为表达式放在任何位置

(2)case结构

语法1：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;case 表达式或字段
when 值1 then 语句1;
...
else 语句n;
end [case];
&lt;/code&gt;&lt;/pre&gt;

语法2：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;case 表达式或字段
when 条1 then 语句1;
...
else 语句n;
end [case];
&lt;/code&gt;&lt;/pre&gt;

位置：可以放在任何位置

如果放在begin end 外面，作为表达式结合着其他语句使用。

如果放在begin end 里面，一般作为独立的语句使用。

(3) if 结构

语法：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;if 条件1 then 语句1
elseif 条件2 then 语句2
...
else 语句n;
end if;
&lt;/code&gt;&lt;/pre&gt;

位置：只能放在begin end 中。

&lt;strong&gt;2.循环结构&lt;/strong&gt;

位置：只能放在begin end中

特点：都能实现循环结构

对比：

①这三种循环都可以省略名称，但如果循环中添加了循环控制语句(leave或iterate)则必须添加名称。

②loop 一般用于实现简单的死循环

while 先判断后执行

repeat 先执行后判断，无条件至少执行一次。

(1)while

语法：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;【名称:】while 循环条件 do
	循环体
end while 【名称】;
&lt;/code&gt;&lt;/pre&gt;

(2)loop

语法：

&lt;pre&gt;&lt;code class=&quot;language-mysql&quot;&gt;【名称：】loop
	循环体
end loop 【名称】;
&lt;/code&gt;&lt;/pre&gt;

(3)repeat

语法：

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;【名称&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;】&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;repeat&lt;/span&gt;
	&lt;span class=&quot;err&quot;&gt;循环体&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;until&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;结束条件&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;repeat&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;【名称】&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3.循环控制语句&lt;/strong&gt;

leave：类似于break，用于跳出所在的循环

iterate：类似于continue，用于结束本次循环，继续下一次

&lt;a href=&quot;#top&quot;&gt;回到顶部&lt;/a&gt;
</description>
        <pubDate>Mon, 01 Jul 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/07/01/MySql/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/07/01/MySql/</guid>
        
        <category>MySql</category>
        
        
        <category>MySql</category>
        
      </item>
    
      <item>
        <title>字节跳动游戏专场笔试</title>
        <description>&lt;strong&gt;题型：选择10道+多选5道+编程3道+问答3道&lt;/strong&gt;

&lt;strong&gt;选择题：&lt;/strong&gt;

1.下面哪些不是SpringMVC的注解？

&lt;blockquote&gt;
  A.@RestController	这个是SpringBoot的注解

  B.@PathVariable

  C.@Mapper

  D.Component
&lt;/blockquote&gt;

2.session和cookie的区别

&lt;blockquote&gt;
  ①cookie以文本文件格式存储在浏览器中，session存储在服务端。

  ②cookie的存储限制了数据量，而session是无限量的。

  ③设置cookie时间可以使cookie过期。但是使用session-destory（），我们将会销毁会话。

  ④我们可以轻松访问cookie值但是我们无法轻松访问会话值，因此session更安全
&lt;/blockquote&gt;

&lt;strong&gt;多选题：&lt;/strong&gt;

1.稳定排序有哪些

&lt;blockquote&gt;
  冒泡排序，插入排序，桶排序，计数排序，归并排序，二叉树排序，基数排序

  ps：不稳定排序：选择排序、希尔排序、堆排序、快速排序
&lt;/blockquote&gt;

2.HashTable和HashMap的区别

&lt;blockquote&gt;
  ①HashMap是继承自AbstractMap类，而HashTable是继承自Dictionary类。不过它们都实现了同时实现了map、Cloneable（可复制）、Serializable（可序列化）这三个接口。

  ②Hashtable比HashMap多提供了elments() 和contains() 两个方法。

  ③HashMap的key-value支持key-value，null-null，key-null，null-value四种。而Hashtable只支持key-value一种（即key和value都不为null这种形式）。既然HashMap支持带有null的形式，那么在HashMap中不能由get()方法来判断HashMap中是否存在某个键， 而应该用containsKey()方法来判断，因为使用get的时候，当返回null时，你无法判断到底是不存在这个key，还是这个key就是null，还是key存在但value是null。

  ④HashTable是线程安全的，HashMap是非线程安全的。

  ⑤初始容量大小和每次扩充容量大小的不同

  &lt;blockquote&gt;
    Hashtable默认的初始大小为11，之后每次扩充，容量变为原来的2n+1。HashMap默认的初始化大小为16。之后每次扩充，容量变为原来的2倍。
  &lt;/blockquote&gt;

  ⑥6、计算hash值的方法不同

  为了得到元素的位置，首先需要根据元素的 KEY计算出一个hash值，然后再用这个hash值来计算得到最终的位置。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  Hashtable直接使用对象的hashCode。hashCode是JDK根据对象的地址或者字符串或者数字算出来的int类型的数值。然后再使用除留余数发来获得最终的位置。
&lt;/blockquote&gt;

3.哪些方法可以使线程放弃锁资源

&lt;blockquote&gt;
  A.wait

  B.sleep	sleep不会放弃锁

  C.join

  D.yield    yield也不会释放锁
&lt;/blockquote&gt;

&lt;strong&gt;问答题：&lt;/strong&gt;

1.抽象类和接口的区别

2.final、finally、finalize的区别

&lt;blockquote&gt;
  final是一个修饰符，可以修饰变量、方法和类。如果final修饰变量，意味着该变量的值在初始化后不能被改变。

  java运行使用finalize()方法在垃圾收集器将对象从内存中清除出去之间作必要的清理工作。这个方法时由垃圾收集器在确定这个对象没有被引用时对这个对象调用的，但是什么时候调用finalize没有保证。

  finally是一个关键字，与try、catch一起用于异常的处理。finally块一定会被执行，无论try块中是否有发生异常。
&lt;/blockquote&gt;

3.实现三种线程安全的单例模式

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//1.通过JVM类的加载机制，Class被类加载后，且在线程使用之前，会执行类的初始化，而JVM会在初始化期间获取一个锁，该锁可以同步多个线程对同一个类的初始化&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Singleton&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*
    	内部类
    */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SingletonHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*
    	获取对象，返回单实例对象
    */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//获取静态变量将导致SingletonHandle 类初始化&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//类的初始化，JVM保证有且仅有一个线程执行该类的初始化&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SingletonHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;singleton&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//2.通过enum的本身特性，JVM保障每个枚举类型的单实例对象&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*
    	获取对象
    */&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton2&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SingletonEnum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;INSTANCE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SingletonEnum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//单实例对象&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;INSTANCE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//单例&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SingletonEnum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Singleton2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;singleton2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//获取单实例对象&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton2&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//3.这里是双重检查锁定的优化，在singleton3=new Singleton3();这段代码这里，可能出现多线程竞争，所以必须使用volatile关键字。&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton3&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//获取实例对象&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton3&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//优化双重检查锁定&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;kd&quot;&gt;synchronized&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
                    &lt;span class=&quot;c1&quot;&gt;// + volatile关键字&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;singleton3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singleton3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;编程题：&lt;/strong&gt;

1.求链表倒数第k个节点值

2.根据成绩给幼儿园同学数组发糖果，求所需糖果最小数，要求：当前孩子成绩比他周围孩子高，那么他的糖果数也要高于他们

3.马里奥跳板，求最小跳跃次数
</description>
        <pubDate>Sun, 30 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/30/%E5%AD%97%E8%8A%82%E8%B7%B3%E5%8A%A8%E6%B8%B8%E6%88%8F%E4%B8%93%E5%9C%BA%E7%AC%94%E8%AF%95/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/30/%E5%AD%97%E8%8A%82%E8%B7%B3%E5%8A%A8%E6%B8%B8%E6%88%8F%E4%B8%93%E5%9C%BA%E7%AC%94%E8%AF%95/</guid>
        
        
        <category>求职</category>
        
      </item>
    
      <item>
        <title>操作系统</title>
        <description>&lt;h2 id=&quot;一操作系统引论&quot;&gt;一、操作系统引论&lt;/h2&gt;

&lt;strong&gt;1.操作系统的目标&lt;/strong&gt;

&lt;blockquote&gt;
  (1)方便性	(2)有效性	(3)可扩充性	(3)开放性
&lt;/blockquote&gt;

&lt;strong&gt;2.各操作系统的特点&lt;/strong&gt;

&lt;blockquote&gt;
  单道批处理系统、多道批处理系统、分时系统、实时系统
&lt;/blockquote&gt;

&lt;blockquote&gt;
  批处理系统：多道性、无序性、调度性，系统利用率高、吞吐量大、平均周转时间长、但无交互能力。

  分时系统：有多路性、独立性、及时性和交互性。有较好的人机交互的特性，并且可以实现共享主机。

  实时系统：有多路线、独立性、及时性、交互性和可靠性。实际上是指操作系统工作时，其各种资源可以根据需要随时进行动态分配。由于各种资源可以进行动态分配，因此，其处理事务的能力较弱、速度较快。

  总结：从可靠性：实时系统更强，从交互性：分时系统更强。
&lt;/blockquote&gt;

&lt;strong&gt;3.操作系统的基本特性&lt;/strong&gt;

&lt;blockquote&gt;
  并发、共享、虚拟、异步
&lt;/blockquote&gt;

&lt;strong&gt;4.概念&lt;/strong&gt;

&lt;blockquote&gt;
  &lt;strong&gt;并发性&lt;/strong&gt;是指两个或多个事件在同一时刻发生。

  &lt;strong&gt;并行性&lt;/strong&gt;是指两个或多个事件在同一时间间隔内发生。

  在OS中，把通过某种技术将一个物理试实体变为若干个逻辑上的对应物的功能称为&lt;strong&gt;虚拟&lt;/strong&gt;。
&lt;/blockquote&gt;

&lt;h2 id=&quot;二进程的描述与控制&quot;&gt;二、进程的描述与控制&lt;/h2&gt;

&lt;strong&gt;1.程序并发执行的特征&lt;/strong&gt;

&lt;blockquote&gt;
  (1)间断性：程序在并发执行的时候，因为是共享资源，以及完成同一项任务而相互合作，致使在这些并发执行的程序之间形成了相互制约的关系，导致程序执行呈现：执行–暂停–执行。

  (2)失去封闭性：当系统中有多个并发执行的程序时，各个资源是他们所共享的，这些资源的状态也由这些程序所改变，所以一个程序的运行环境会受到其他程序的影响。

  (3)不可再现性：程序在并发执行时，由于失去了封闭性，也将导致其有失去可再现性。
&lt;/blockquote&gt;

&lt;strong&gt;3.进程的特征与三种基本状态&lt;/strong&gt;

&lt;strong&gt;特征：&lt;/strong&gt;

&lt;blockquote&gt;
  (1)动态性	(2)并发性	(3)独立性	(4)异步性
&lt;/blockquote&gt;

&lt;strong&gt;状态：&lt;/strong&gt;

&lt;blockquote&gt;
  (1)就绪状态	(2)执行状态	(3)阻塞状态
&lt;/blockquote&gt;

三种基本状态转换：

&lt;blockquote&gt;
  处于就绪状态的进程，在调度程序为之分配了处理机之后便开始执行，就绪 → 执行

  正在执行的进程如果因为分配它的时间片已经用完，而被剥夺处理机，执行 → 就绪

  如果因为某种原因致使当前的进程受阻，使之不能执行。			执行 → 阻塞
&lt;/blockquote&gt;

&lt;strong&gt;4.进程控制块PCB的作用&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 作为进程存在的唯一标志

  (2) 能实现间断性运行方式

  (3) 提供进程管理所需要的信息

  (4) 提供进程调度所需要的信息
&lt;/blockquote&gt;

&lt;strong&gt;5.线程与进程的区别联系&lt;/strong&gt;

&lt;strong&gt;定义：&lt;/strong&gt;

&lt;blockquote&gt;
  进程：进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动，是系统进行资源分配和调度的一个独立单位（包括程序段，相关数据段，进程控制块PCB）。

  线程：线程是进程的一个实体，是CPU调度和分派的基本单位，它是比进程更小的能独立运行的基本单位。线程自己基本上不拥有系统资源，只拥有一点在运行中必不可少的资源（如程序计数器，一组寄存器和栈)，但是它可与同属一个进程的其他的线程共享进程所拥有的全部资源。
&lt;/blockquote&gt;

&lt;strong&gt;关系：&lt;/strong&gt;

&lt;blockquote&gt;
  一个线程可以创建和撤销另一个线程。同一个进程中的多个线程之间可以并发执行。相对进程而言，线程是一个更加接近于执行体的概念，它可以与同进程中额度其他线程共享数据，但拥有自己的栈空间，拥有独立的执行序列。
&lt;/blockquote&gt;

&lt;strong&gt;区别：&lt;/strong&gt;

&lt;blockquote&gt;
  主要差别在于它们是不同的操作系统资源管理方式。进程有独立的地址空间，一个进程崩溃后，在保护模式下不会对其他进程产生影响，而线程只是一个进程中的不同执行路径。线程有自己的堆栈和局部变量，但线程之间没有单独的地址空间，一个线程死掉就等于整个进程死掉，所以多进程的程序要比多线程的程序健壮，但在进程切换时，耗费资源较大，效率要差一些。但对于一些要求同时进行并且又要共享某些变量的并发操作，只能用线程，不能用进程。
&lt;/blockquote&gt;

&lt;strong&gt;优缺点：&lt;/strong&gt;

&lt;blockquote&gt;
  线程和进程在使用上各有优缺点：线程执行开销小，但不利于资源的管理和保护；而进程相反。同时，&lt;em&gt;线程适合于在SMP机器上允许，而进程则可以跨机器迁移&lt;/em&gt;。
&lt;/blockquote&gt;

&lt;strong&gt;6.进程间的通信是如何实现的？&lt;/strong&gt;

  早期的的属于低级通信，原因：(1)效率低，生产者每次只能向缓冲池投放一个信息。(2)通信对用户不透明，隐藏了通信的具体细节。现在发展为高级通信：用户可以利用操作系统所提供的一组通信命令传送大量数据。操作系统隐藏了进程通信的实现细节，或者说，通信过程对用户是透明的。

&lt;strong&gt;高级通信机制：&lt;/strong&gt;

&lt;blockquote&gt;
  1.共享存储器系统

  &lt;blockquote&gt;
    实际操作中对应的是“剪贴板”（剪贴板实际上是系统维护管理的一块内存区域）的通信方式。
  &lt;/blockquote&gt;

  2.消息传递系统（进程间的数据交换以消息(message)为单位)

  &lt;blockquote&gt;
    当今最流行的微内核操作系统中，微内核与服务器之间的通信，都采用了消息传递机制
  &lt;/blockquote&gt;

  3.管道通信系统（连接读写进程实现他们之间通信的共享文件）

  (pipe文件，类似于先进先出的队列，由一个进程写，一个进程读)

  &lt;blockquote&gt;
    管道分为匿名管道、命名管道。匿名管道是未命名的、单向管道，通过父进程和一个子进程之间传输数据。匿名管道只能实现本地机器上两个进程之间的通信，不能实现跨网络的通信。命名管道不仅可以在本机上实现两个进程间的通信，还可以跨网络实现进程间的通信。
  &lt;/blockquote&gt;

  4.客户机-服务器系统

  &lt;blockquote&gt;
    包括：套接字（socket），远程过程调用和远程方法调用。
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;strong&gt;7.什么是临界区？如何解决冲突？&lt;/strong&gt;

每个进程中访问临界资源的那段程序成为临界区，每次只准许一个进程进入临界区，进入后不允许其他进程进入。

&lt;blockquote&gt;
  (1)如果有若干进程要求进入空闲的临界区，一次仅允许一个进程进入；

  (2)任何时候，处于临界区内的进程不可多于一个。如已有进程进入自己的临界区，则其他所有试图进入临界区的进程必须等待；

  (3)进入临界区的进程要在有限的时间内推出，以便其他进程能及时进入自己的临界区。

  (4)如果进程不能进入自己的临界区，则应让出CPU，避免进程出现“忙等”现象。
&lt;/blockquote&gt;

&lt;strong&gt;8.进程同步原则&lt;/strong&gt;

  进程同步的主要任务：是对多个相关进程在执行次序上进行协调，使并发执行的诸进程之间能有效地共享资源和相互合作，从而使程序的执行具有可再现性。同步机制遵循的原则：

&lt;blockquote&gt;
  (1) 空闲让进

  (2) 忙则等待（保证对临界区的互斥访问）

  (3) 有限等待（避免死等）

  (4) 让权等待（当进程不能进入自己的临界区时，应该释放处理机，以免陷入忙等状态）
&lt;/blockquote&gt;

&lt;strong&gt;9.进程同步&lt;/strong&gt;

  由于进程同步产生了一系列经典的同步问题“生产者-消费者”问题，“哲学家进餐”问题，“读者-写者”问题。

&lt;blockquote&gt;
  解决方法：

  (1)整型信号量

  (2)记录型信号量，针对多个并发进程仅共享一个临界资源的情况。

  (3)AND信号量，针对一个进程需要获得两个或更多的共享资源后才能执行其任务。

  (4)管程
&lt;/blockquote&gt;

&lt;strong&gt;P(S)：请求资源，V(S)：释放资源。&lt;/strong&gt;

&lt;strong&gt;10.程序和进程的区别&lt;/strong&gt;

&lt;blockquote&gt;
  &lt;strong&gt;程序：&lt;/strong&gt;计算机指令的集合，它以文件的形式存储在磁盘上。程序是静态实体，在多道程序系统中，它是不能独立运行的，更不能与其他程序并发执行。

  使用系统资源情况：不使用（程序不能申请系统资源，不能被系统调度，也不能作为独立运行的单位，它不占用系统的运行资源）。

  &lt;strong&gt;进程：&lt;/strong&gt;进程是进程实体（包括：&lt;strong&gt;程序段、相关的数据段、进制控制块PCB&lt;/strong&gt;）的运行过程，是一个程序在其自身的地址空间中的一次执行活动。是系统进行资源分配和调度的一个独立单位。

  使用系统资源情况：使用（进程是资源申请、调度和独立运行的单位，因此，它使用系统中的运行资源）。
&lt;/blockquote&gt;

&lt;h2 id=&quot;三处理机调度与死锁&quot;&gt;三、处理机调度与死锁&lt;/h2&gt;

&lt;strong&gt;1.处理机调度的层次&lt;/strong&gt;

(1) 高级调整

&lt;blockquote&gt;
  主要用于多道批处理系统中，又称长作业调度，调度对象是作业，根据某种算法决定将后备队列中的哪个作业调入内存。
&lt;/blockquote&gt;

(2) 低级调度

&lt;blockquote&gt;
  操作系统中最基本的一种调度方式（频率最高），其所调度的对象是进程(或内核级线程)。主要功能是，根据某种算法，决定就绪队列中的哪个进程应获得处理机，并由分派程序将处理机分配给选中的进程。在多道批处理、分时和实时三种类型的OS中都存在，又称为短作业调度。
&lt;/blockquote&gt;

(3) 中级调度

&lt;blockquote&gt;
  又称为内存调度，目的是为了提高内存利用率和系统吞吐率。
&lt;/blockquote&gt;

&lt;strong&gt;2.作业调度的算法&lt;/strong&gt;

(1) 先来先服务算法（FCFS）

&lt;blockquote&gt;
  最简单额度调度算法，既可以用于作业调度，也可用于进程调度，系统按照作业到达的先后顺序进行调度，或者是优先考虑在系统中等待时间最长的作业
&lt;/blockquote&gt;

(2) 短作业优先调度算法（SJF）

&lt;blockquote&gt;
  实际情况短作业占有比例很大，为了使他们比长作业优先执行，而产生了短作业优先的调度算法，作业越短优先级越高，缺点是必须知道作业的运行时间，对长作业不利，人机无法实现交互，未完全考虑作业的紧迫程度。
&lt;/blockquote&gt;

(3) 优先级调度算法（PSA）

&lt;blockquote&gt;
  优先级：

  对于先来先服务算法，作业的等待时间就是他的优先级，等待时间越长优先级越高。

  对于短作业优先算法，作业时间的长短就是它的优先级。

  在优先级算法中，基于作业的紧迫程度。
&lt;/blockquote&gt;

(4) 高响应比优先调度算法（HRRN）

&lt;blockquote&gt;
  在FSFS中只是考虑作业的等待时间而忽略作业的运行时间，SJF算法正好相反。高响应比算法既考虑作业的等待时间，又考虑作业的运行时间。

  优先权 = （等待时间 + 要求服务时间）/  要求服务时间

  由于等待时间与服务时间之和就是作业的响应时间，顾优先级相当于响应比：Rp

  Rp = （等待时间 + 要求服务时间）/  要求服务时间  =  响应时间 / 要求服务时间
&lt;/blockquote&gt;

&lt;strong&gt;3.什么是死锁，死锁产生的4个条件&lt;/strong&gt;

&lt;strong&gt;死锁定义：&lt;/strong&gt;

&lt;blockquote&gt;
  在两个或多个并发进程中，如果每个进程持有某种资源而又都等待别的进程释放它或它们现在保持着的资源，在未改变这种状态之前都不能向前推进，称这一组进程产生了死锁。通俗的讲，就是两个或多个进程被无限期地阻塞、相互等待的一种状态。
&lt;/blockquote&gt;

&lt;strong&gt;产生死锁的必要条件(缺一不可)：&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 互斥条件			一个资源一次只能被一个进程调用。

  (2) 请求保持条件		一个进程因请求资源而阻塞时，对已经获得资源保持不放。

  (3) 不可抢占条件		进程已获得的资源在未使用完之前不能被抢占。

  (4) 循环等待条件		若干进程之间形成一种头尾相接的循环等待资源的关系。
&lt;/blockquote&gt;

&lt;strong&gt;4.预防避免死锁的方法&lt;/strong&gt;

(1) 破坏”互斥”条件

&lt;blockquote&gt;
  所有进程可以同时访问共享资源。但由于互斥条件是非共享设备所必须的，不仅不能改变，还应加以保证。
&lt;/blockquote&gt;

(2) 破坏”请求和保持”条件

&lt;blockquote&gt;
  规定所有进程在开始运行之前，都必须一次性的申请其在整个运行过程所需要的全部资源。

  优点：简单，安全。	缺点：资源严重浪费，恶化了系统的利用率。
&lt;/blockquote&gt;

(3) 破坏“不剥夺“条件

&lt;blockquote&gt;
  进程逐个的提出资源请求，当一个已经保持了某些资源的进程，再提出新的资源请求而不能立即得到满足时，必须释放它已经保持了的所有资源，待以后需要时再重新申请。

  缺点：实现复杂，代价大，反复地申请和释放资源，而使进程的执行无限的推迟、延长了进程的周转时间，增加系统开销，降低系统吞吐量。
&lt;/blockquote&gt;

(4) 破坏”环路等待”条件

&lt;blockquote&gt;
  将所有的资源按类型进行线性排队，并赋予不同的序号。所有进程请求资源必须按照资源递增的次序提出，防止出现环路。

  缺点：1.序号必须相对稳定，限制了新设备类型的增加。2.作业（进程）使用资源顺序和系统规定的顺序不同而造成资源浪费。3.限制了用户编程。
&lt;/blockquote&gt;

&lt;strong&gt;算法：利用银行家算法避免死锁&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;进程\资源情况&lt;/th&gt;
      &lt;th&gt;Work&lt;/th&gt;
      &lt;th&gt;Need&lt;/th&gt;
      &lt;th&gt;Allocation&lt;/th&gt;
      &lt;th&gt;Work+Allocation&lt;/th&gt;
      &lt;th&gt;Finish&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
  Available，可利用资源 ，表示一类可利用的资源数目。

  Max，最大需求矩阵，表示进程i需要Rj类资源的最大数目。

  Allocation，分配矩阵，表示进程i当前已分的Rj类资源的数目。

  Need，需求矩阵，表示进程i还需要Rj类资源K个方能完成任务。

  Work，工作向量，表示系统可提供给进程继续运行所需的各类资源数目。
&lt;/blockquote&gt;

&lt;strong&gt;5.死锁的检测和解除&lt;/strong&gt;

(1)死锁的检测

&lt;blockquote&gt;
  ①资源分配图：

  &lt;blockquote&gt;
    圆圈代表一个进程，方框代表一类资源。

    资源请求边由进程P指向资源R；资源分配便由资源R指向进程P。
  &lt;/blockquote&gt;

  ②死锁原理

  S为死锁状态的充分条件是：当且仅当S状态的资源分配图是不可完全简化的。

  ③死锁中的数据结构
&lt;/blockquote&gt;

(2)死锁的解除

&lt;blockquote&gt;
  ①抢占资源：从一个或多个进程中抢占足够数量的资源，分配给死锁进程，以解除死锁状态。

  ②终止进程：终止系统中的一个或多个死锁进程，直至打破循环环路，使系统从死锁状态解脱出来。
&lt;/blockquote&gt;

&lt;h2 id=&quot;四存储器管理&quot;&gt;四、存储器管理&lt;/h2&gt;

&lt;strong&gt;1.存储器的多层结构&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;寄存器&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;高速缓存&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;主存储器&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;磁盘缓存&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;固态磁盘&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;可移动存储介质&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;最高层为CPU寄存器，紧接着三层为主存，最底两层是辅存。&lt;/strong&gt;

&lt;strong&gt;2.程序的装入和链接&lt;/strong&gt;

用户程序要在系统中运行，必须先将它装入内存，然后再将其转变为一个可以执行的程序，通常都要经过以下几个步骤：

&lt;blockquote&gt;
  (1)编译，由编译程序(Compiler)对用户源程序进行编译，形成若干个目标模块（Object Module）。

  (2)链接，由链接程序（Linker）将编译后形成的一组目标模块以及它们所需要的库函数链接在一起，形成一个完整的装入模块（Load Module）。

  (3)装入，由装入程序（Loader）将装入模块装入内存。
&lt;/blockquote&gt;

&lt;img src=&quot;F:\desk\md\Typora\images\加载用户程序.jpg&quot; alt=&quot;&quot; /&gt;

&lt;strong&gt;3.连续分配存储管理方式&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 单一连续分配

  (2) 固定分区分配

  (3) 动态分区分配

  (4)动态可重定位分区分配算法

  其中动态分区分配将涉及到分区分配中实际需要的数据结构，分区分配算法和分区的分配与回收操作。

  回收操作包括，三中合并以及一种插入。
&lt;/blockquote&gt;

&lt;strong&gt;内存分配流程：&lt;/strong&gt;

&lt;img src=&quot;F:\desk\md\Typora\images\内存分配流程.jpg&quot; alt=&quot;&quot; /&gt;

&lt;strong&gt;4.动态分区分配算法&lt;/strong&gt;

(1) 首次适应算法（FF）

&lt;blockquote&gt;
  要求地址空间递增的顺序链接，在分配内存时从链首开始查找，直到有一个满足的空间为止。该算法优先利用内存中低址空间，保留了高址空间，缺点是低址部分不断被划分，留下许多内存碎片。
&lt;/blockquote&gt;

(2) 循环首次适应算法（NF）

&lt;blockquote&gt;
  为了防止留下碎片，减少低址空间开销，NF算法每次从上一次分配的地方继续分配，该算法需要一个起始查询的指针用于指示下一次查询的空间地址。缺点是：缺乏大的空间分区。
&lt;/blockquote&gt;

(3) 最佳适应算法（BF）

&lt;blockquote&gt;
  每次作业分配时，总是把满足要求，又是最小的空间分配给作业，该算法把空间分区按其容量大小从小到大排列成空闲区链，缺点是：留下许多内存碎片。
&lt;/blockquote&gt;

(4) 最坏适应算法（WF）

&lt;blockquote&gt;
  总是挑选最大的空闲区域分配给作业使用，优点是不至于使空间区间太小，产生碎片的可能性小，缺点是：缺乏大的空间分区。
&lt;/blockquote&gt;

&lt;strong&gt;5.动态可重定位分区分配&lt;/strong&gt;

(1)紧凑

&lt;blockquote&gt;
  通过移动内存中作业的位置，把原来多个分散的小分区拼接成一个大分区的方法。

  缺点：需要对移动了的程序或数据进行重定位。
&lt;/blockquote&gt;

(2)动态重定位

&lt;blockquote&gt;
  当系统对内存进行了“紧凑”，而使若干程序从内存的某处移至另一处时，不需对程序做任何修改，只要用该程序在内存的新起始地址去置换原来的起始地址即可。这一过程需要硬件支持——&lt;strong&gt;重定位寄存器&lt;/strong&gt;。
&lt;/blockquote&gt;

&lt;strong&gt;6..对换&lt;/strong&gt;

&lt;blockquote&gt;
  是指把内存中暂时不能运行的进程或者暂时不用的程序和数据换出到外存上，以便腾出足够的内存空间，再把已具备运行条件的进程或进程所需要的程序和数据换入内存。

  对换是改善内存利用率的有效措施，它可以直接提高处理机的利用率和系统的吞吐量。
&lt;/blockquote&gt;

类型：

&lt;blockquote&gt;
  ①整体对换：进程对换，在中级调度中以整个进程为单位。

  需要系统实现三方面功能：对对换空间的管理、进程的换出和进程的换入

  ②页面(分段)对换。
&lt;/blockquote&gt;

&lt;strong&gt;7.分页存储管理方式&lt;/strong&gt;

分页存储的基本方法：

(1) 页面和物理块

&lt;blockquote&gt;
  页面：分页存储管理将进程的逻辑地址空间分成若干页，并从0开始编号，把内存的物理地址分成若干块（物理块）
&lt;/blockquote&gt;

(2) 地址结构

&lt;blockquote&gt;
  前一部分为也好P，后一部分为位(偏)移量W，对于特定的机器，其地址结构一定。给定逻辑地址A，页面的大小为L，则页面P和页内地址D有以下关系： P=INT[A/L]; d=[A] MOD L ，INT是整除函数。

  &lt;strong&gt;例如：页面大小1kb ，设A=2170B，得P=2,d=122。&lt;/strong&gt;

  &lt;strong&gt;物理地址=（P=2对应的物理块地址)*1024B+122B&lt;/strong&gt;
&lt;/blockquote&gt;

(3) 页表

&lt;blockquote&gt;
  记录相应页在内存中对应的物理块号
&lt;/blockquote&gt;

(4) 地址转换机构

&lt;blockquote&gt;
  将用户逻辑空间的地址，转变为空间中的物理地址。
&lt;/blockquote&gt;

&lt;strong&gt;8.分段存储管理方式&lt;/strong&gt;

分段管理方式的引入原因：

&lt;blockquote&gt;
  (1) 一般程序分为若干段，如：主程序段、数据段、栈段等，每个段大多试一个相对独立的单位。

  (2) 实现满足信息共享、信息保护、动态链接、以及信息动态增长等需要。
&lt;/blockquote&gt;

&lt;strong&gt;9.分页和分段的区别&lt;/strong&gt;

共同点：二者都采用离散分配方式，且都地址映射机构来实现地址的转换

不同点：

(1) 页是信息的物理单位。采用分页存储管理方式是为了实现离散分配方法。提高内存的利用率，采用分段目的主要在于能更好的满足用户的需求。

(2) 页的大小固定且有由系统决定，在采用分页存储管理方式中直接由硬件实现。而段的大小不固定，决定于用户所填写的程序

(3) 分页的用户程序地址空间是一维的。分页完全是系统的行为，分段系统中是二维的。

&lt;strong&gt;10.段页式存储管理方式&lt;/strong&gt;

&lt;blockquote&gt;
  基本原理是分段和分页相结合，其地址结构由：段号、段内页号、页内地址三部分组成。在段页式系统中获得一条指令需要三次访问内存，第一次访问内存中的短标，第二次访问内存中的页表，第三次访问内存中的数据。
&lt;/blockquote&gt;

&lt;strong&gt;11.Windows下的内存是如何管理的？&lt;/strong&gt;

Windows提供了3中方法来进行内存管理：

&lt;blockquote&gt;
  (1) 虚拟内存，最适合用来管理大型对象或者结构数组；

  (2) 内存映射文件，最适合用来管理大型数据流（通常来自文件）以及单个计算机上运行多个进程之间共享数据；

  (3) 内存堆栈，最适合用来管理大量的小对象

  Windows操作内存可以分两个层面：物理内存和虚拟内存。

  其中物理内存由系统管理，不允许应用程序直接访问。
&lt;/blockquote&gt;

&lt;h2 id=&quot;五虚拟存储器&quot;&gt;五、虚拟存储器&lt;/h2&gt;

&lt;strong&gt;1.操作系统的内容分为几块？为什么叫做虚拟内存？他和主机的关系如何？内存管理属于操作系统的内容吗？&lt;/strong&gt;

&lt;blockquote&gt;
  操作系统的主要组成部分：进程和线程的管理，存储管理，设备管理，文件管理。虚拟内存是一些系统页文件，存放在磁盘上，每个系统页文件大小为4K，物理内存也被分页每个页大小也为4k，这样虚拟页文件和物理内存也就可以对应，实际上虚拟内存就是用于物理内存的临时存放的磁盘空间。页文件就是内存页，物理内存中每页叫物理页，磁盘上的页文件叫虚拟页，物理页+虚拟页就是系统所有使用的页文件的总和。
&lt;/blockquote&gt;

&lt;strong&gt;2.请求分页存储管理方式&lt;/strong&gt;

&lt;strong&gt;请求页面机制：&lt;/strong&gt;作用是把用户的逻辑地址映射为内存空间中的物理地址。

结构：

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;页面&lt;/th&gt;
      &lt;th&gt;物理块号&lt;/th&gt;
      &lt;th&gt;状态P&lt;/th&gt;
      &lt;th&gt;访问字段A&lt;/th&gt;
      &lt;th&gt;修改位M&lt;/th&gt;
      &lt;th&gt;外存地址&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
  状态P：指示页面是否调入内存，供程序访问时参考。

  访问字段A：用于记录本页在一段时间内被访问的次数，供换出页面时参考。

  修改位M：标识页面调入内存是否被修改过，供置换页面时参考。

  外存地址：用于指示该页在外存上指示地址。
&lt;/blockquote&gt;

&lt;strong&gt;内存分配：&lt;/strong&gt;

&lt;blockquote&gt;
  最小物理块数：

  若采用单地址指令,且采用直接寻址，需要物理块数是2，一块用于存放指令页面，另一块用于存放数据页面。

  若采用间接寻址至少需要3块。
&lt;/blockquote&gt;

&lt;strong&gt;3.虚拟存储器页面置换算法&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 最佳置换算法（Optimal）

  &lt;blockquote&gt;
    一种理论的算法，选择淘汰的页面是以后一定不再使用的页面（理想化的），该算法无法实现，只能作为其他算法好坏的一个评价对比。
  &lt;/blockquote&gt;

  (2) 先进先出算法（FIFO）

  &lt;blockquote&gt;
    总是最先淘汰最先进去的页面，该算法容易实现。缺点：通常程序调入内存的先后顺序和程序执行的先后顺序不一致，导致缺页率高。
  &lt;/blockquote&gt;

  (3) 最近最久未使用（LEU）

  &lt;blockquote&gt;
    FIFO算法性能差，LRU算法根据页面调入内存的先后顺序决定，因为违反预测未来的使用情况，就是用过去的使用情况作为将来的使用情况的近似。
  &lt;/blockquote&gt;

  (4) 最少使用算法（LFU）

  &lt;blockquote&gt;
    在每个页面设置一个移位寄存器记录该页面的访问频率，最近时期最少使用的页面被淘汰。
  &lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;六输入输出系统&quot;&gt;六、输入输出系统&lt;/h2&gt;

&lt;strong&gt;1.IO软件的层次结构&lt;/strong&gt;

&lt;blockquote&gt;
  (1)用户层IO软件	(2)设备独立性软件	(3)设备驱动程序	(4)中断处理程序	(5)硬件
&lt;/blockquote&gt;

I/O设备一般是由执行I/O操作的机械部分和执行控制I/O的电子部件组成。通常将这两部分分开，执行I/O操作的机械部分就是一般的&lt;strong&gt;I/O设备&lt;/strong&gt;，而执行控制I/O的电子部件则称为&lt;strong&gt;设备控制器或适配器&lt;/strong&gt;。

设备控制器的&lt;strong&gt;主要功能&lt;/strong&gt;是：控制一个或多个I/O设备，以实现I/O设备和计算机之间的数据交换。

&lt;strong&gt;2.对IO设备的控制方式&lt;/strong&gt;

(1) 使用轮询的可编程方式

&lt;blockquote&gt;
  CPU不停地检查设备的状态，以字节为单位，非中断方式，利用率低
&lt;/blockquote&gt;

(2) 使用中断可编程的IO方式

&lt;blockquote&gt;
  添加CPU中断，提高了CPU的利用率
&lt;/blockquote&gt;

(3) 直接存储方式

&lt;blockquote&gt;
  以数据块为单位，放宽响应时间
&lt;/blockquote&gt;

(4) IO通道的方式

&lt;blockquote&gt;
  以数据块组成的一组数据块为单位，大幅度提高CPU的利用率
&lt;/blockquote&gt;

&lt;strong&gt;3.设备分配&lt;/strong&gt;

(1) 设备分配中的数据结构

&lt;blockquote&gt;
  ①设备分配表DCT	②控制器控制表，通道控制表，系统设备控制表
&lt;/blockquote&gt;

(2) 设备分配需要考虑的因素

&lt;blockquote&gt;
  ①设备的固有属性	②独占设备的分配策略	③设备的分配算法	④设备分配中的安全性
&lt;/blockquote&gt;

(3) 独占设备的分配程序

&lt;strong&gt;4.设备驱驱动程序&lt;/strong&gt;

设备处理程序又称为设备驱动程序，它是I/O系统的高层与设备控制器之间的通信程序。

&lt;strong&gt;设备驱动程序的处理过程：&lt;/strong&gt;

(1)将抽象要求转换为具体要求。

(2)对服务请求进行校验。

(3)检查设备的状态。

(4)传送必要的参数。

(5)启动I/O设备

&lt;strong&gt;5.SpooLing系统的构成&lt;/strong&gt;

&lt;img src=&quot;F:\desk\md\Typora\images\SPOOLing.jpg&quot; alt=&quot;&quot; /&gt;

&lt;blockquote&gt;
  (1) 输入井和输出井

  (2) 输入缓冲区和输出缓冲区

  (3) 输入进程和输出进程

  (4) 井管理程序
&lt;/blockquote&gt;

&lt;strong&gt;6.与设备无关的I/O软件&lt;/strong&gt;

为了实现与设备的无关性而引入了&lt;strong&gt;逻辑设备&lt;/strong&gt;与&lt;strong&gt;物理设备&lt;/strong&gt;两个概念。&lt;strong&gt;逻辑设备表LUT&lt;/strong&gt;*。

&lt;strong&gt;7.缓存区&lt;/strong&gt;

&lt;strong&gt;引入缓冲区的原因：&lt;/strong&gt;

&lt;blockquote&gt;
  (1)缓和CPU与I/O设备间速度不匹配的矛盾。

  (2)减少对CPU的中断频率，放宽对CPU中断响应时间的限制。

  (3)解决数据粒度不匹配的问题。

  (4)t提高CPU和I/O设备之间的并行性。
&lt;/blockquote&gt;

&lt;strong&gt;分类：&lt;/strong&gt;

&lt;blockquote&gt;
  (1) 单缓冲区，处理时间是：max(c,T) + M

  (2) 双缓冲区，处理时间是：max(C+T)
&lt;/blockquote&gt;

&lt;strong&gt;缓冲池：&lt;/strong&gt;在池中设置了多个可供若干个进程共享的缓冲区。

&lt;strong&gt;缓冲池与缓冲区的区别：&lt;/strong&gt;缓冲区仅仅是一组内存块的链表，而缓冲池则是包含了一个管理的数据结构及一组操作函数的管理机制，用于管理多个缓冲区。

&lt;strong&gt;缓冲池组成：&lt;/strong&gt;空白缓冲队列emq，输入队列inq，输出队列outq。

&lt;strong&gt;8.磁盘系统的性能改善&lt;/strong&gt;

(1)选择好的磁盘调度算法，以减少磁盘的寻道时间。

(2)提高磁盘I/O速度，以提高对文件的访问速度。

(3)采取冗余技术，提高磁盘系统的可靠性。

&lt;h2 id=&quot;七文件管理&quot;&gt;七、文件管理&lt;/h2&gt;

&lt;strong&gt;1.文件逻辑结构管理&lt;/strong&gt;

(1) 按文件的有无结构分

&lt;blockquote&gt;
  ① 有结构文件（记录式文件）	② 无结构文件（流式文件）
&lt;/blockquote&gt;

(2) 按文件组织方式分

&lt;blockquote&gt;
  ① 顺序文件	② 索引文件	③ 索引顺序文件
&lt;/blockquote&gt;

&lt;h2 id=&quot;八磁盘存储器管理&quot;&gt;八、磁盘存储器管理&lt;/h2&gt;

&lt;strong&gt;1.外存的组织方式&lt;/strong&gt;

(1) 连续组织方式

&lt;blockquote&gt;
  又称为连续分配方式，要求每一个文件分配一个相邻的盘块

  优点：顺序访问容易，访问连续文件非常容易，访问速度非常快

  缺点：要求为文件分配连续的空间，必须事先知道文件的长度，不能灵活的删除插入记录动态增长的文件难分配空间
&lt;/blockquote&gt;

(2) 链接组织方式（分为隐式链接和显示链接）

&lt;blockquote&gt;
  采用链接组织的方式可以为文件分配多个不连续的盘块。

  优点：①消除磁盘的外部碎片，提高内存的利用率。

  ②对插入删除修改非常容易。

  ③可以适应文件的动态增长。
&lt;/blockquote&gt;

(3)索引组织方式

&lt;blockquote&gt;
  分为单索引和多索引组织方式。
&lt;/blockquote&gt;
</description>
        <pubDate>Sun, 23 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/23/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/23/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/</guid>
        
        
        <category>操作系统</category>
        
      </item>
    
      <item>
        <title>SpringMVC</title>
        <description>&lt;h2 id=&quot;六springmvc&quot;&gt;六、SpringMVC&lt;/h2&gt;

&lt;strong&gt;1.WEB.xml&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 1.注册监听器，监听服务器的启动，在启动时，自动加载spring相关的xml文件 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;listener&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;listener-class&amp;gt;&lt;/span&gt;org.springframework.web.context.ContextLoaderListener&lt;span class=&quot;nt&quot;&gt;&amp;lt;/listener-class&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/listener&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;context-param&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;param-name&amp;gt;&lt;/span&gt;contextConfigLocation&lt;span class=&quot;nt&quot;&gt;&amp;lt;/param-name&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;param-value&amp;gt;&lt;/span&gt;classpath:applicationContext.xml&lt;span class=&quot;nt&quot;&gt;&amp;lt;/param-value&amp;gt;&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;!--配置service及以下 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/context-param&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 2.配置SpringMVC入口servlet，所有*.form请求，都会进入spring中 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 并在服务器启动时，默认加载位于web.inf文件夹中的viewSpace.xml，以配置springMVC --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 配置service以上 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;servlet&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;viewSpace&lt;span class=&quot;nt&quot;&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;servlet-class&amp;gt;&lt;/span&gt;org.springframework.web.servlet.DispatcherServlet&lt;span class=&quot;nt&quot;&gt;&amp;lt;/servlet-class&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;load-on-startup&amp;gt;&lt;/span&gt;1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/load-on-startup&amp;gt;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 设置此选项后，servlet会在服务器一启动就创建--&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/servlet&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;servlet-mapping&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;servlet-name&amp;gt;&lt;/span&gt;viewSpace&lt;span class=&quot;nt&quot;&gt;&amp;lt;/servlet-name&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;*.form&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
  	&lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;*.css&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
  	&lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;*.jpg&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
  	&lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;*.js&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
  	&lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;*.png&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 3.配置字符集过滤器，解决中文乱码问题 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;filter&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;filter-name&amp;gt;&lt;/span&gt;CharacterEncodingFilter&lt;span class=&quot;nt&quot;&gt;&amp;lt;/filter-name&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;filter-class&amp;gt;&lt;/span&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;span class=&quot;nt&quot;&gt;&amp;lt;/filter-class&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;filter-mapping&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;filter-name&amp;gt;&lt;/span&gt;CharacterEncodingFilter&lt;span class=&quot;nt&quot;&gt;&amp;lt;/filter-name&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;url-pattern&amp;gt;&lt;/span&gt;/*&lt;span class=&quot;nt&quot;&gt;&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/filter-mapping&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;2.viewSpace-servlet.xml&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- controller及以上，在此处配置 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 开启扫描注解，指定要扫描的包，多个包的话，名字之间可以用逗号隔开,防止多次扫描，因为application也里也有扫描，该配置文件只扫描controller及以上--&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;context:component-scan&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;base-package=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;context:exclude-filter&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;annotation&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframwork.stereotype.Service&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;context:exclude-filter&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;annotation&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframwork.stereotype.Repository&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;	
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/context:component-scan&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 开启此选项，才能在重定向时使用RedirectAttributes --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:annotation-driven&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 开启validator校验器进行字段校验 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;validator&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.validation.beanvalidation.LocalValidatorFactoryBean&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 给Controller注入Service --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userInfoController&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.controllers.UserInfoController&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;p:userInfoService-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userInfoService&quot;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 屏蔽Repository和Service扫描 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;context:component-scan&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;base-package=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		&lt;span class=&quot;nt&quot;&gt;&amp;lt;context:exclude-filter&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;annotation&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.stereotype.Service&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;context:exclude-filter&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;annotation&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.stereotype.Repository&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;	
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/context:component-scan&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&amp;lt;!--配置拦截器 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:interceptors&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:interceptor&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:mapping&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;../**/*.form&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;lt;!--拦截器映射--&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:exclude-mapping&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/**/login.form&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;lt;!--不包含的请求映射(不拦截) --&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:exclude-mapping&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/**/index.form&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.interceptors.LoginInterceptor&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;&amp;lt;!--处理拦截事务的拦截器类--&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/mvc:interceptor&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/mvc:interceptors&amp;gt;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 外部访问资源文件，需要对路径进行映射 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/css/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/css/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/js/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/js/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/img/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/img/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/fonts/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/fonts/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/plugins/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/plugins/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mvc:resources&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;location=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;WEB-INF/ajax/&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;mapping=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/ajax/**&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;

&lt;/blockquote&gt;

&lt;strong&gt;3.Controller&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//一、传递普通参数&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Controller&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;parController&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//给该注解别名，其他地方调用的对象名就为parController&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ParamController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;otherPage&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;jumpOtherPage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;第一个请求!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;otherPage.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//return &quot;redirect:otherPage.jsp&quot;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sendParam&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendParam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@RequestParam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;required&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Reqeust&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;userPass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;账号&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;密码&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userPass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;showParam.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sendParamWithRequest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendParamWithRequest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@RequestParam&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Reqeust&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;userPass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;账号&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;密码&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userPass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        
        &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;showParam.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sendSameNameWithRequest&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendSameNameWithRequest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@RequestParam&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Reqeust&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;账号&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;密码&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        
        &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;showParam.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sendSameNameWithRequestRedirect&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendSameNameWithRequest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@RequestParam&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Reqeust&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnsupportedEncodingException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;redirect:showParam.jsp?username=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;URLEncoder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;password=&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sendSameNameWithRequestRedirectSpring&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sendSameNameWithRequestRedirectSpring&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@RequestParam&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Reqeust&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Redirect&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;attrs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnsupportedEncodingException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;attrs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;attrs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;passwrod&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;redirect:showParam.jsp&quot;&lt;/span&gt;	&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//路径参数&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Controller&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PathVariableController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//getPage3By100Items&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Request&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;multiPageQuery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@PathVariable&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pageNo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@PageVariable&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;countPage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pageNo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;countPage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;otherPage.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//三、传递表单数据到实体对象中(模型属性)&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@Controller&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;UserController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@ReqeustMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;login&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;={&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RequestMethod&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;POST&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@ModelAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//模型属性会自动放入reqeust中&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//四、控制器跳转至另一个控制器&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//转发&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;sendSameNameParamWithRequest.form&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//重定向利用RedirectAttributes attrs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;4.字段校验&lt;/strong&gt;

&lt;blockquote&gt;
  hibernate-validator-x.jar

  jboss-logging-x.jar

  validation-api-x.jar
&lt;/blockquote&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Pattern&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;regexp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;^\\S{3,16}$&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;账号名必须是3-16位的非空白字符!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@NotNull&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;此字段不能为null!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@NotEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;此字段不能为空!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;密码必须是3-16位!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;priavte&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nd&quot;&gt;@Controller&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@ReqeustMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;UserControlelr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;login&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@Valid&lt;/span&gt; &lt;span class=&quot;nd&quot;&gt;@ModelAttribute&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BindingResult&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bindingResult&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//BindingResult存放出错信息&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//首先判断字段校验是否通过，若未通过，则不需要进行登陆验证!&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bindingResult&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;hasErrors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;index.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//登陆验证&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;zhangsan&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getUserName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123456&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;equals&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getUserpass&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;())){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;loginSuccess.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;loginFailed.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;5.ModelAndView&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Controller&lt;/span&gt;
&lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;UserController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@RequestMapping&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;login&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ModelAndView&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;@ModelAttribute&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ModelAndView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mav&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ModelAndView&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;index.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;mav&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;otherInfo&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;呵呵&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mav&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;6.注解&lt;/strong&gt;

&lt;blockquote&gt;
  @Repository  Dao层

  @Service  Service层

  @Controller

  @Autowired   变量

  @Qualifier(“userInfoDao”) 跟在auto下面，只有匹配名字的bean才能注入进来

  @ResponseBody 添加此注解，表示返回的字符串不是页面地址，而是响应体正文
&lt;/blockquote&gt;

&lt;strong&gt;7.application.xml&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;去掉bean
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 在application.xml里屏蔽controller扫描
	 在viewSpace-servlet.xml里屏蔽Repository和Service扫描
&amp;lt;!-- application和viewSpace都需要打开扫描注解 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;context:component-scan&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;base-package=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;context:exclude-filter&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;annotation&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;expression=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframwork.stereotype.Controller&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/context:component-scan&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;8.自动生成实体类使用&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 下面添加一个bean的设置，使其能够扫描myBatis的Dao层接口，自动生成实体类使用 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- applicationContext.xml --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.mybatis.spring.mapper.MapperScannerConfiger&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;p:basePackage=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.dao&quot;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;9.HandlerInterceptor接口&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;LoginInterceptor&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HandlerInterceptor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//请求执行之后，再执行的方法，一般在此处清理释放资源&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;afterCompletion&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;//正在执行请求，准备跳转页面之前执行的方法，一般在此处我们可以处理一部分请求或添加一部分响应头等&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;postHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ModelAndView&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mav&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;//正在执行请求，准备跳转页面之前执行的方法，一般在此处我们可以处理一部分请求或添加一部分响应头等&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;preHandle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletRequest&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HttpServletResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getAttribute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;loginUser&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;sendRedirect&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;index.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;	&lt;span class=&quot;c1&quot;&gt;//阻止继续向下传递请求&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//放行&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;HTTP请求处理流程-SpringMvc&lt;/strong&gt;

&lt;blockquote&gt;
  在SpringMVC的http请求处理过程中，包括了前端控制器（DispatcherServlet）、处理映射器(HandlerMapping)、处理适配器(HandlerAdapter)、处理器((Handler)Controller)、视图解析器(ViewReslover)、视图(View)这六大主要对象。他们负责对http请求做处理。
&lt;/blockquote&gt;

第一步：前端控制器dispatcher接受请求

&lt;blockquote&gt;
  Client—url—&amp;gt;Dispatcher
&lt;/blockquote&gt;

第二步：前端控制器去发起handler映射查找请求

&lt;blockquote&gt;
  Dispatcher—HttpServletRequest—&amp;gt; HandlerMapping
&lt;/blockquote&gt;

第三步：处理器映射器查找hanlder并返回HandlerExetuionChain

&lt;blockquote&gt;
  Dispatcher &amp;lt;—HandlerExeutionChain—HandlerMapping
&lt;/blockquote&gt;

第四步：前端控制器发起请求处理器适配器请求执行

&lt;blockquote&gt;
  Dispatcher—Handler—&amp;gt; HandlerAdapter
&lt;/blockquote&gt;

第五步：处理器适配器去调用handler执行

&lt;blockquote&gt;
  HandlerAdapter—HttpServletRequest&amp;gt; Handler(Controller)
&lt;/blockquote&gt;

第六步：处理器处理后返回ModelAndView给HandlerAdapter

&lt;blockquote&gt;
  HandlerAdapter &amp;lt;—ModelAndView—Handler(Controller)
&lt;/blockquote&gt;

第七步：处理器适配器将ModelAndView返回给前端控制器

&lt;blockquote&gt;
  Dispatcher &amp;lt;—ModelAndView—HandlerAdapter
&lt;/blockquote&gt;

第八步：前端控制器请求视图解析器解析ModelAndView

&lt;blockquote&gt;
  Dispatcher—ModelAndView—&amp;gt; ViewReslover
&lt;/blockquote&gt;

第九步：视图解析器解析视图后返回视图View给前端控制器

&lt;blockquote&gt;
  Dispatcher &amp;lt;—View—ViewReslover
&lt;/blockquote&gt;

第十步：前端控制器请求视图要求渲染视图

&lt;blockquote&gt;
  Dispatcher—&amp;gt;View—&amp;gt;render
&lt;/blockquote&gt;

第十一步：前端控制器返回响应

&lt;blockquote&gt;
  Response &amp;lt;—Dispatcher
&lt;/blockquote&gt;
</description>
        <pubDate>Mon, 17 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/17/SpringMVC/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/17/SpringMVC/</guid>
        
        <category>SpringMVC</category>
        
        
        <category>JavaWeb</category>
        
      </item>
    
      <item>
        <title>西安研华笔试+面试</title>
        <description>&lt;h2 id=&quot;2019614-西安研华笔试面试&quot;&gt;2019.6.14 西安研华笔试+面试&lt;/h2&gt;

&lt;h3 id=&quot;一笔试题&quot;&gt;一、笔试题&lt;/h3&gt;

&lt;strong&gt;1.接口与抽象类的区别？&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;参数&lt;/th&gt;
      &lt;th&gt;抽象类&lt;/th&gt;
      &lt;th&gt;接口&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;默认的方法实现&lt;/td&gt;
      &lt;td&gt;它可以有默认的方法实现&lt;/td&gt;
      &lt;td&gt;接口完全是抽象的。它根本不存在方法的实现&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;实现&lt;/td&gt;
      &lt;td&gt;子类使用&lt;strong&gt;extends&lt;/strong&gt;关键字来继承抽象类。如果之类不是抽象类的话，它需要提供抽象类中所有声明的方法的实现。&lt;/td&gt;
      &lt;td&gt;子类使用关键字implements来实现接口。它需要提供接口中所有声明的方法的实现。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;构造器&lt;/td&gt;
      &lt;td&gt;抽象类可以有构造器&lt;/td&gt;
      &lt;td&gt;接口不能有构造器&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;访问修饰符&lt;/td&gt;
      &lt;td&gt;抽象方法可以有&lt;strong&gt;public&lt;/strong&gt;、&lt;strong&gt;protected&lt;/strong&gt;和&lt;strong&gt;default&lt;/strong&gt;这些修饰符&lt;/td&gt;
      &lt;td&gt;接口方法默认修饰符是&lt;strong&gt;public&lt;/strong&gt;。不可以使用其它修饰符&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;main方法&lt;/td&gt;
      &lt;td&gt;抽象方法可以有main方法并且我们可以运行它&lt;/td&gt;
      &lt;td&gt;接口没有main方法，因此我们不能运行它。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;多继承&lt;/td&gt;
      &lt;td&gt;抽象类可以继承一个类或实现多个接口&lt;/td&gt;
      &lt;td&gt;接口只可以继承一个或多个其他接口&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;速度&lt;/td&gt;
      &lt;td&gt;它比接口的速度要快&lt;/td&gt;
      &lt;td&gt;接口是稍微有点慢的，因为它需要时间去寻找在类中实现的方法。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;添加新方法&lt;/td&gt;
      &lt;td&gt;如果要往抽象类中添加新的方法，可以给他提供默认的实现。因此不需要改变现在的代码。&lt;/td&gt;
      &lt;td&gt;如果要往接口中添加方法，那么必须改变实现该接口的类。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;2.什么是JDBC？&lt;/strong&gt;

&lt;blockquote&gt;
  JDBC代表Java数据库连接(&lt;strong&gt;J&lt;/strong&gt;ava &lt;strong&gt;D&lt;/strong&gt;ata&lt;strong&gt;b&lt;/strong&gt;ase &lt;strong&gt;C&lt;/strong&gt;onnectivity)，它是用于Java编程语言和数据库之间的数据库无关连接的标准Java API，换句话说：JDBC是用于在Java语言编程中与数据库连接的API。
&lt;/blockquote&gt;

&lt;strong&gt;3.给一个try{}catch{}finally{}的程序题，写出其输出结果&lt;/strong&gt;

&lt;strong&gt;4.HTTP请求在SpringMVC里的处理过程&lt;/strong&gt;

这个好可惜，自己有学过这块内容，但是脑子里只能模糊的记忆着。

&lt;blockquote&gt;
  在SpringMVC的http请求处理过程中，包括了前端控制器（DispatcherServlet）、处理映射器(HandlerMapping)、处理适配器(HandlerAdapter)、处理器((Handler)Controller)、视图解析器(ViewReslover)、视图(View)这六大主要对象。
&lt;/blockquote&gt;

&lt;img src=&quot;F:\desk\md\Typora\images\处理过程.jpg&quot; alt=&quot;&quot; /&gt;

&lt;h3 id=&quot;二面试题&quot;&gt;二、面试题&lt;/h3&gt;

（顺序可能不太对）

&lt;strong&gt;1.数据库多表的连接有哪些？&lt;/strong&gt;

&lt;blockquote&gt;
  我首先说了可以让两张表里相同的字段直接用 = 连接，然后又说了左连接left join on，右连接right join on，等值连接join on。
&lt;/blockquote&gt;

&lt;strong&gt;2.Java高并发有哪些解决高并发的方法？volatile类型变量有什么作用？&lt;/strong&gt;

我先说了volatile和synchronized，面试官继续问volatile变量有什么作用？

心里大概清楚volatile的作用，但是因为时间长了忘了原子性和可见性这两个名词，然后就没答出来。。。

&lt;blockquote&gt;
  volatile变量提供顺序和可见性保证，例如JVM或JIT为了获得更好的性能会对语句进行重排序，但是volatile类型变量即使在没有同步快的情况下赋值，也不会与其他语句进行重排序。volatile提供happens-before的保证，确保一个线程的修改能对其他线程是可见的。某些情况下，volatile还能提供原子性，如读64位数据类型，像long和double都不是原子的，但volatile类型的double和long就是原子的。
&lt;/blockquote&gt;

&lt;strong&gt;3.Java是怎样释放一个对象的？&lt;/strong&gt;

&lt;blockquote&gt;
  我说的是，可以让这个对象的引用直接等null，当该对象不存在引用后，依靠JVM的垃圾自动回收机制，进行回收。

  可能是我第一问的回答不是他想要的答案。
&lt;/blockquote&gt;

&lt;strong&gt;又问Java怎样立即释放一个对象？&lt;/strong&gt;

&lt;blockquote&gt;
  我emmm….，这个还真没有了解过。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  Java定义了一个特殊的方法叫做finalize()，它提供了C++析构函数的一些功能。但是，finalize()并不完全与C++的析构函数一样，并可以假设它会导致一系列的问题。finalize()方法作用的一个关键元素是Java的垃圾回收器。

  在Java中，当你创建 一个对象时，Java虚拟机（JVM）为该对象分配内存、调用析构函数并开始跟踪你使用的对象。当你停止使用一个对象（也就是说，当没有对该对象的有效引用时），JVM通过垃圾回收器将该对象标记为释放这状态。

  finalize方法是在Object类中定义的，因此所有的类都继承了它。子类覆盖finalize()方法以整理系统资源或者执行其他清理工作，finalize()方法是在垃圾收集器删除对象之前对这个对象调用的。
&lt;/blockquote&gt;

&lt;strong&gt;4.各学科成绩（数据结构、算法、计算机网络）&lt;/strong&gt;

略~

&lt;strong&gt;5.计算机网络的体系结构？各层有什么作用？&lt;/strong&gt;

&lt;blockquote&gt;
  因为长时间没有看计算机网络方面的知识，所以只说了五层协议每一层的名字。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  1.应用层的任务是通过应用进程间的交互来完成特定网络应用。

  2.运输层的主要任务就是负责向两台主机进程之间的通信提供通用的数据传输服务。

  &lt;blockquote&gt;
    运输层主要使用以下两种协议：

    (1)传输控制协议TCP，提供面向连接的，可靠的数据传输服务。

    (2)用户数据协议UDP，提供无连接的，尽最大努力的数据传输服务(不保证数据传输的可靠性)。
  &lt;/blockquote&gt;

  3.网络层负责为分组交换网上的不同主机提供通信服务。

  4.数据链路层通常简称为链路层。两台主机之间的数据传输，总是在一段一段的链路上传送的，这就需要使用专门的链路层的协议。在两个相邻节点之间传送数据时，数据链路层将网络层交下来的IP数据报组装成帧。

  5.物理层的作用是实现相邻计算机节点之间比特流的透明传送，尽可能屏蔽掉具体传输介质和物理设备的差异。

&lt;/blockquote&gt;

&lt;strong&gt;6.问项目经验&lt;/strong&gt;

&lt;blockquote&gt;
  我讲了最近做的课设，前端使用了JQuery+AJAX，后端使用了SSM框架集。
&lt;/blockquote&gt;

&lt;strong&gt;MyBatis与Spring Data、Hibernate的区别。&lt;/strong&gt;

(当时问了与Spring的区别，不知道啥意思，我讲了与Hibernate的区别，下面才了解了是SpringData = =)

&lt;blockquote&gt;
  我说，Hibernate是一个傻瓜式的框架，它的使用很方便，但是一个很简单的语句经过它处理，可能需要很复杂的处理过程。而MyBatis虽然写配置文件的时候可能有些麻烦，但是处理效率很高。(应该是讲错了。。。)

  它们的区别见另一位博文https://www.cnblogs.com/liaojie970/p/7743068.html

&lt;/blockquote&gt;

&lt;strong&gt;7.双端队列的插入手写代码，不行的话说清思路&lt;/strong&gt;

&lt;blockquote&gt;
  非常糟糕，一时大脑一片空白，之前只是简单知道双端队列的功能，却不知道具体的实现。。。下来看了下才发现，好简单。。。
&lt;/blockquote&gt;

&lt;blockquote&gt;
  头插入：首先创建一个临时指针指向头节点，然后让头指针指向加入进来的节点，如果队列开始为空，则让尾指针也指向加入进来的节点；如果队列不为空，那么让原头节点的prev指针指向新加入进来的节点即可，最后链表大小+1。
&lt;/blockquote&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;//LinkedList源码&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;addFirst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;linkFirst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;linkFirst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;prev&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;modCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
     * Links e as last element.
     */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;linkLast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Node&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;next&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;modCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;8.servlet是单例还是多例？为什么？怎样来判断它是单例还是多例？&lt;/strong&gt;

&lt;blockquote&gt;
  想了十几秒钟，说了是单例的。面试官看我停顿这么长时间就继续细问了后面两个问题。

  因为如果是多例的，那么每有一个请求都必须创建一个servlet，这样当请求多的时候，会占用很多资源。

  可以在serlvet里添加一个静态变量，在它的构造方法里进行自增打印，来看构造器执行了几次。
&lt;/blockquote&gt;

&lt;strong&gt;9.前端到数据库的数据传输是怎样的？&lt;/strong&gt;

&lt;blockquote&gt;
  我说，前端发送GET或POST请求，到Servlet，servlet调用service层方法，service层调用dao层方法访问数据库，连接数据库用JDBC。。。
&lt;/blockquote&gt;

&lt;strong&gt;10.GET和POST请求的区别。&lt;/strong&gt;

&lt;blockquote&gt;
  我说，使用GET请求，发送的数据会在地址栏里显示，使用POST请求，发送的数据不会再地址栏显示。回答了些皮毛。。。除了我回答的一点，还有：

  1.GET请求，请求的数据会附加在URL之后，以?分割URL和传输数据，多个参数用&amp;amp;俩捏。URL的编码格式采用的是ASCII编码，而不是uniclde，即是说所有的非ASCII字符都要编码之后在传输。POST请求会把请求的数据放置在HTTP请求体里。因此GET请求的数据会暴露在地址栏里，而POST请求则不会，而是在请求体里。

  2.传输数据的大小

  由于特定浏览器和服务器对URL的长度有限制，因此，发送GET请求时，传输数据会受到URL长度的限制。

  对于POST请求，由于不是URL传值，理论上是不会受限制的，但是实际上各个服务器会规定对POST请求提交数据大小进行限制。

  3.POST请求的安全性比GET更高。
&lt;/blockquote&gt;

&lt;strong&gt;11.课设有没有写登陆？登陆信息怎么保存的？&lt;/strong&gt;

&lt;blockquote&gt;
  我说，有，我目前是保存在session中的，当然也可以保存在cookie里。
&lt;/blockquote&gt;

&lt;strong&gt;技术面试结束，后面又和项目主管面试，问的不是技术问题，但是二面自我感觉不好。&lt;/strong&gt;

项目主管上来就问我，你现在是大三，后面考研不？	不。

那你为啥不考研？	我不想学习了。。。

Oh My God!	蹦出了自己心底的真实想法（手动滑稽）。

这样就开始了不在状态的面试。。。

讲清了为啥不考研后，让我做自我介绍，主要从以下方面：

&lt;blockquote&gt;
  自己擅长的地方，以后主要学习什么语言，希望在公司得到哪些提高（具体）？

  自己的优点和缺点？

  期间还询问了我一些其他方面的事情，感觉很多地方回答的不好。
&lt;/blockquote&gt;
</description>
        <pubDate>Fri, 14 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/14/%E8%A5%BF%E5%AE%89%E7%A0%94%E5%8D%8E%E7%AC%94%E8%AF%95+%E9%9D%A2%E8%AF%95/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/14/%E8%A5%BF%E5%AE%89%E7%A0%94%E5%8D%8E%E7%AC%94%E8%AF%95+%E9%9D%A2%E8%AF%95/</guid>
        
        
        <category>求职</category>
        
      </item>
    
      <item>
        <title>软件工程</title>
        <description>&lt;a id=&quot;top&quot;&gt;&lt;/a&gt;

&lt;h1 id=&quot;软件工程&quot;&gt;软件工程&lt;/h1&gt;

&lt;h2 id=&quot;第一章-软件工程的内容与方法&quot;&gt;第一章 软件工程的内容与方法&lt;/h2&gt;

&lt;strong&gt;1.软件定义&lt;/strong&gt;

&lt;blockquote&gt;
  软件 = 程序 + 数据 + 文档

  软件 = 知识 + 程序 + 数据 + 文档
&lt;/blockquote&gt;

&lt;strong&gt;2.软件危机与软件工程的关系&lt;/strong&gt;

&lt;blockquote&gt;
  软件工程来源于软件危机，即现有软件危机，后有软件工程。
&lt;/blockquote&gt;

&lt;strong&gt;3.软件工程定义&lt;/strong&gt;

&lt;blockquote&gt;
  软件工程师研究软件开发和软件管理的一门工程学科。

  一强调开发，二强调管理或过程管理。
&lt;/blockquote&gt;

&lt;strong&gt;4.软件工程课程研究的内容&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;序号&lt;/th&gt;
      &lt;th&gt;研究方面&lt;/th&gt;
      &lt;th&gt;具体内容&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;软件生命周期模型&lt;/td&gt;
      &lt;td&gt;瀑布模型、增量模型、原型模型、迭代模型、XP模型&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;软件开发方法&lt;/td&gt;
      &lt;td&gt;面向过程的方法、面向元数据的方法、面向对象的方法&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;软件支持过程&lt;/td&gt;
      &lt;td&gt;CASE工具Rose、北大青鸟系统、PowerDesigner、ERWin&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;软件管理过程&lt;/td&gt;
      &lt;td&gt;CMMI、软件企业文化、敏捷（XP）文化现象&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;软件工程标准与规范&lt;/td&gt;
      &lt;td&gt;命名标准与规范、设计标准与规范、编程标准与规范&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;5.软件工程基本原理&lt;/strong&gt;

&lt;blockquote&gt;
  1.用分阶段的生命周期计划严格管理软件开发。阶段划分为计划、分析、设计、编程、测试和运行维护。

  2.坚持进行阶段评审。若上一阶段评审不通过，则不能进入向下一阶段开发。

  3.实行严格的产品版本控制。

  4.采用现代程序设计技术。

  5.结果应能清除地审查。因此，对文档要有严格要求。

  6.开发小组的成员要少而精。

  7.要不断改进软件工程实践的经验和技术，要与时俱进。

  8.二八定律。在软件工程中，所谓二八定律，就是一般人常常将20%的东西误以为是80%的东西，而将80%的东西误以为是20%的东西。
&lt;/blockquote&gt;

&lt;strong&gt;6.研究二八定律的现实意义&lt;/strong&gt;

&lt;blockquote&gt;
  指导软件开发计划的指定与执行。如果实现掌握了二八定律，就能自觉地用二八定律去指定、跟踪与执行软件开发计划。只有这样，项目的开发计划与新项目的开发进度才能吻合。
&lt;/blockquote&gt;

&lt;strong&gt;7.软件工程在软件行业中的作用&lt;/strong&gt;

&lt;blockquote&gt;
  从历史上讲，是为了克服20世纪60年代出现的软件危机。

  从当前来讲，就是告诉人们怎样去开发软件和管理软件。具体低讲，它表现在与软件开发和管理有关的人员和过程上。为了说明这个问题，首先，分析软件行业的人才结构，看看这些人员的工作与软件工程有什么关系。
&lt;/blockquote&gt;

&lt;strong&gt;8.软件行业的专业人才层次组成&lt;/strong&gt;

&lt;blockquote&gt;
  高层管理人员、中层项目经理和软件工程师、软件蓝领工人

  软件营销人员、软件实施与维护人员、软件售前人员
&lt;/blockquote&gt;

&lt;strong&gt;9.软件生命周期模型概念&lt;/strong&gt;

&lt;blockquote&gt;
  软件生命周期模型是指在整个软件生命周期中，软件开发过程应遵循的开发路线图。或者说，

  软件生命周期模型是软件开发全部过程、活动和任务的结构框架。
&lt;/blockquote&gt;

&lt;strong&gt;10.软件开发方法概念&lt;/strong&gt;

&lt;blockquote&gt;
  软件开发方法是指在软件开发路线图中，开发人员对软件需求、设计、实现、维护所采用的开发思想、开发技术、描述方法、支持工具等。
&lt;/blockquote&gt;

&lt;strong&gt;11.软件工程方法论&lt;/strong&gt;

&lt;blockquote&gt;
  软件工程中软件开发方法的集合，成为软件工程方法论。
&lt;/blockquote&gt;

&lt;strong&gt;12.面向过程方法&lt;/strong&gt;

&lt;blockquote&gt;
  优点：以处理流程为基础，简单实用。

  缺点：只注重过程化写信息，忽略了信息的层面关系及相互关系。

  它企图实用简单的时序过程方法（顺序、分支、循环三种结构），来描述关系复杂（随机）的信息世界。
&lt;/blockquote&gt;

&lt;strong&gt;13.面向对象方法&lt;/strong&gt;

&lt;blockquote&gt;
  包括面向对象的需求分析、设计、编程、测试、维护、管理等。

  面向对象方法是一种运用对象、类、消息传递、继承、封装、聚合、多态性等概念来构造软件系统的软件开发方法。

  特点：将现实世界的事物(问题域)直接映射到对象。分析设计时由对象抽象出类(Class)，程序运行时由类还原对象(Object)。

  基本特点：将对象的属性和方法(即数据和操作)封装起来，形成信息系统的基本执行单位，再利用对象的继承特征，由基本执行单位派生出其他执行单位，从而产生许多新的对象。众多的离散对象通过事件或消息拦截起来，就形成了软件系统。

  开发平台：.Net平台和 J2EE平台

  优点：能描述无穷的信息世界，同时易于维护。

  缺点：对于习惯于面向过程的人，比较难掌握。
&lt;/blockquote&gt;

&lt;strong&gt;14.面向元数据方法&lt;/strong&gt;

&lt;blockquote&gt;
  元数据是关于数据的数据、组织数据的数据、管理数据的数据

  如类的名称、属性和方法，实体的名称、属性和关联，数据库中的表名、字段名、主键、外键、索引、视图等信息。

  就是在软件需求分析、设计、实现、测试、维护过程中，均以元数据为中心的软件工程方法。

  优点：通俗易懂，特别适合信息系统中数据层上的设计与实现。

  缺点：只能实现二维表格，不能实现窗口界面。
&lt;/blockquote&gt;

&lt;strong&gt;15.信息系统&lt;/strong&gt;

&lt;blockquote&gt;
  利用计算机网络技术、数字通信技术与数据库技术实现信息采集和处理的系统，称为信息系统。
&lt;/blockquote&gt;

&lt;strong&gt;16.”五个面向”实践论&lt;/strong&gt;

&lt;blockquote&gt;
  面向流程分析、面向元数据分析、面向对象实现、面向功能测试、面向过程管理
&lt;/blockquote&gt;

&lt;strong&gt;17.软件过程&lt;/strong&gt;

&lt;blockquote&gt;
  指软件生命周期中的时间序列。

  软件工程的支持过程，由支持软件声明周期各个阶段的生成工具组成。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第二章-软件生命周期与开发模型&quot;&gt;第二章 软件生命周期与开发模型&lt;/h2&gt;

&lt;h3 id=&quot;1瀑布模型&quot;&gt;1.瀑布模型&lt;/h3&gt;

&lt;strong&gt;1.模型本意&lt;/strong&gt;

&lt;blockquote&gt;
  在瀑布模型中，软件开发的各项活动严格按照线性方式进行，当前阶段的活动接受上一阶段活动的工作结果，实施完成所需的工作内容。需要对当前阶段活动的工作结果进行验证，如果验证通过，则该结果作为下一阶段活动的输入，继续进行下一阶段的活动，否则返回上一阶段修改。

  项目经理或软件管理人员，只要控制好每级台阶的高度和宽度，在每级台阶处设立里程碑或极限，并组织好对基线的评审与审计，就可以控制好项目的开发成本、进度与质量。
&lt;/blockquote&gt;

&lt;strong&gt;2.特点&lt;/strong&gt;

&lt;blockquote&gt;
  (1)里程碑或基线驱动，或者所文档驱动。

  (2)过程逆转性很差或者说不可逆转，根据上游的错误会在下游发散性传播的原理，逆转将会延误工期，增加成本，造成重大损失。

  优点：开发阶段界定清晰，便于评审、审计、跟踪、管理和控制。

  缺点：在整个分析、设计和实现阶段隐藏下来的问题，会在项目后期堆积暴露出来。
&lt;/blockquote&gt;

&lt;h3 id=&quot;2增量模型&quot;&gt;2.增量模型&lt;/h3&gt;

&lt;strong&gt;1.模型本意&lt;/strong&gt;

&lt;blockquote&gt;
  要开发一个大的软件系统，先开发其中的一个核心模块(或子系统)，然后再开发其他模块(或子系统)，这样一个个模块(或子系统)地增加上去，直至整个系统开发完毕。在每增加一个模块前，先要对该模块进行模块测试，通过后再将此模块加入到系统中。然后还要进行系统集成测试，系统集成测试成功后，再增加新的模块。这样多次循环，直到系统搭建完毕。
&lt;/blockquote&gt;

&lt;strong&gt;2.特点&lt;/strong&gt;

&lt;blockquote&gt;
  (1)任务或功能模块驱动，可以分阶段提交产品。

  (2)有多个任务单，这些任务单的集合构成项目的一个总《任务书》或总《用户需求报告》/《需求规格说明书》

  优点：相当于将一个大风险分解为多个小风险，从而降低了开发难度。人员分配灵活，刚开始不用投入大量人力资源。

  缺点：如果软件系统的组装与拆卸性不强，或开发人员全局把握水平不高，或者客户不同意分阶段提交产品，或者开发人员过剩，都不宜采用这种模型。
&lt;/blockquote&gt;

&lt;h3 id=&quot;3原型模型&quot;&gt;3.原型模型&lt;/h3&gt;

&lt;strong&gt;1.模型本意&lt;/strong&gt;

&lt;blockquote&gt;
  在初步需求分析之后，马上向客户展示一个软件产品原型，对客户进行培训，让客户试用，在试用中收集客户意见，根据客户意见立刻修改原型，之后再让客户试用，反复循环几次，知道客户确认为止。

  适用于企业资源规划ERP系统
&lt;/blockquote&gt;

&lt;strong&gt;2.模型的特点&lt;/strong&gt;

&lt;blockquote&gt;
  原型驱动。开发中必须先有一个原型，至少有一个原型的核心。

  优点：开发速度快，用户意见实时反馈，有利于开发商在短时间内推广并服务于多个客户。

  缺点：因为事先有一个展示型的产品原型，所以在一定程度上，不利于开发人员的创新。
&lt;/blockquote&gt;

&lt;h3 id=&quot;4迭代模型&quot;&gt;4.迭代模型&lt;/h3&gt;

&lt;blockquote&gt;
  课本上讲的迭代模型是由RUP推出的一种“逐步求精”的面向对象的软件开发过程模型。

  从宏观上看，它是一个大的迭代过程：横坐标表示软件产品所处的4个阶段状态：先启、精化、构建、产品化(移交)，纵坐标表示软件产品在每个阶段的工作流程。
&lt;/blockquote&gt;

&lt;strong&gt;1.模型本意&lt;/strong&gt;

&lt;blockquote&gt;
  多次执行各个开发工作流程，从而更好地理解需求，设计出更为强壮的软件构架，逐步提高开发组织能力，最终交付一系列逐步完善的实施成果。每次按顺序完成一些列工作流程就称为一次迭代，每次迭代均以次要里程碑结束，按照特定的迭代成功标准，对迭代的结果进行评估。通过一次又一次的迭代，实现递增成长，最后形成最终的软件系统或产品。
&lt;/blockquote&gt;

&lt;strong&gt;2.特点&lt;/strong&gt;

&lt;blockquote&gt;
  迭代或迭代循环驱动，每一次迭代或迭代循环，均要走完初始、精化、构建、产品化这4个阶段。

  (1)采用迭代的、增量式的开发过程。

  (2)采用UML语言描述软件开发过程。

  (3)有功能强大的软件工具Rational Rose支撑。

  优点：在开发的早期或中期，用户需求可以变化；在迭代之初，不要求有一个相近的产品原型；模型的适用范围很广，几乎适用于所有项目的开发。

  缺点：要求项目组成员具有很高的水平掌握先进的开发工具
&lt;/blockquote&gt;

​

&lt;h2 id=&quot;第三章-软件立项与合同&quot;&gt;第三章 软件立项与合同&lt;/h2&gt;

&lt;strong&gt;1.立项&lt;/strong&gt;

&lt;blockquote&gt;
  立项就是在市场调研的基础上，分析立项的必要性(是否有市场前景)和可能性(是否有能力实现)，并具体列出系统的功能、性能、接口和运行环境等方面的需求，当前客户群和潜在客户群的情况，以及投入产出分析。然后再按照编写参考指南书写《立项建议书》，并对它进行评审，评审通过后才算正式立项。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第四章-软件需求分析&quot;&gt;第四章 软件需求分析&lt;/h2&gt;

&lt;strong&gt;1.需求分析&lt;/strong&gt;

&lt;blockquote&gt;
  需求分析的输入是软件《合同》或软件《立项建议书》，以及对用户现场的调研、分析和确认

  输出是《用户需求报告》/《需求分析规格说明书》
&lt;/blockquote&gt;

&lt;strong&gt;2.定义&lt;/strong&gt;

&lt;blockquote&gt;
  (1)用户解决问题或达到目标所需的条件或能力。

  (2)系统或系统部件要满足合同、标准、规范或其他正式规定文档所需要具有的条件或能力。

  (3)一种反应第(1)或(2)所描述的条件或能力的文档说明。

  基本任务：准确地定义未来系统的目标，确定为了满足用户的需要系统必须做什么。

  两个阶段：需求获取阶段和需求归约阶段。

  两大类：功能性需求和非功能性需求。前者定义了系统做什么，后者定义了系统工作时的特性。
&lt;/blockquote&gt;

&lt;strong&gt;3.需求获取&lt;/strong&gt;

&lt;blockquote&gt;
  就是开发者与用户共同提取并共同确认需求。

  人们将“划分、抽象和投影”三要素作为需求获取的三原则。

  (1)划分，就是捕获问题空间的“整体/部分”关系。

  (2)抽象，就是捕获问题空间的“一般/特殊”或“一般/特例”关系。

  (3)投影，就是捕获问题空间的多为“视图”。
&lt;/blockquote&gt;

&lt;strong&gt;4.需求规约&lt;/strong&gt;

&lt;blockquote&gt;
  就是对获取并确认的需求进行定义与分析，并且解决需求中存在的二义性和不一致性问题，最后以一种系统化的文档新形势，准确地表达用户的需求，形成《需求分析规格说明书》。
&lt;/blockquote&gt;

&lt;strong&gt;5.名词解释&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;序号&lt;/th&gt;
      &lt;th&gt;名词&lt;/th&gt;
      &lt;th&gt;名词解释&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;基线&lt;/td&gt;
      &lt;td&gt;基线是软件工作产品，它要经内部和外部都评审过的，是下一阶段工作的基础&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;检查点&lt;/td&gt;
      &lt;td&gt;检查点只是由时间、计划、事件驱动的检查工作进度和质量的一个标记。一个检查点不一定对应一条基线或一个里程碑&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;里程碑&lt;/td&gt;
      &lt;td&gt;里程碑是一个标记，只需要经过内部评审。一个里程碑是一个检查点，但不一定对应一条基线&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;评审&lt;/td&gt;
      &lt;td&gt;是对软件工作产品质量的一次开会（或汇签）活动&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;审计&lt;/td&gt;
      &lt;td&gt;是复查评审活动程序的合法性，是否按程序与规范进行等&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;客户&lt;/td&gt;
      &lt;td&gt;客户是软件企业合同的签约方，是软件产品的销售对象。客户是顾客的一部分&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;顾客&lt;/td&gt;
      &lt;td&gt;“顾客”比“客户”的范围更广泛一些些，它包括潜在的客户&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;8&lt;/td&gt;
      &lt;td&gt;用户&lt;/td&gt;
      &lt;td&gt;用户是软件产品的最终使用者，用户是客户的一部分&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;9&lt;/td&gt;
      &lt;td&gt;软件工作产品&lt;/td&gt;
      &lt;td&gt;在CMMI中，“软件工作产品”是软件开发活动中的人工制品，如《用户需求报告》、《需求分析规格说明书》、《概要设计说明书》、《详细设计说明书》、源程序、《测试报告》、《用户手册》，也包括软件管理文档&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;10&lt;/td&gt;
      &lt;td&gt;软件产品&lt;/td&gt;
      &lt;td&gt;在CMMI中，“软件产品”是最终用户使用的软件，如操作系统Windows XP、财务系统、管理信息系统MIS。“软件产品”是“软件工作产品”的一部分。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;11&lt;/td&gt;
      &lt;td&gt;现有系统&lt;/td&gt;
      &lt;td&gt;指用户当前正在使用的系统，它可能是网络管理系统，也可能是手工管理系统&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;td&gt;目标系统&lt;/td&gt;
      &lt;td&gt;指将要实现的系统&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;6.需求分析的任务&lt;/strong&gt;

&lt;blockquote&gt;
  1.画出目标系统的组织结构图，列出各部门的岗位角色表，即组织机构模型。

  2.画出目标系统的业务操作流程图，即业务模型。

  3.画出目标系统的数据流图(DFD)，即单据和报表的流图，掌握业务规则，获得初步数据模型。

  4.列出目标系统的功能点列表，即功能模型。

  5.列出系统的性能点列表，即性能模型。

  6.列出目标系统的接口列表，即接口模型。

  7.确定目标系统的运行环境，即环境模型。

  8.目标系统的界面约定。即界面模型。

  9.对目标系统的开发工期、费用、开发进度、系统风险等问题进行分析与评估。
&lt;/blockquote&gt;

&lt;strong&gt;7.三中需求分析方法对比表&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;需求分析方法名称&lt;/th&gt;
      &lt;th&gt;目的&lt;/th&gt;
      &lt;th&gt;点评&lt;/th&gt;
      &lt;th&gt;适用范围&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;面向功能分析&lt;/td&gt;
      &lt;td&gt;为了获得功能模型&lt;/td&gt;
      &lt;td&gt;简单明了&lt;/td&gt;
      &lt;td&gt;系统软件和应用软件&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;面向对象分析&lt;/td&gt;
      &lt;td&gt;为了获得对象模型&lt;/td&gt;
      &lt;td&gt;复杂抽象&lt;/td&gt;
      &lt;td&gt;系统软件和应用软件&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;面向数据分析&lt;/td&gt;
      &lt;td&gt;为了获得数据模型&lt;/td&gt;
      &lt;td&gt;抓住本质&lt;/td&gt;
      &lt;td&gt;以关系数据库为平台的信息系统&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;8.需求描述工具&lt;/strong&gt;

&lt;blockquote&gt;
  面向元数据的X：实体关系图

  面向过程的X：数据流图、数据字典

  面向对象的X：用例图、类图、顺序图、活动图。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第五章-软件策划&quot;&gt;第五章 软件策划&lt;/h2&gt;

&lt;strong&gt;1.软件策划和软件项目策划&lt;/strong&gt;

&lt;blockquote&gt;
  输入是软件《合同》/《立项建议书》、《任务书》和《用户需求报告》

  输出是《软件开发计划书》（包括《质量保证计划》、《配置管理计划》、《测试计划》、《里程碑及评审计划》
&lt;/blockquote&gt;

&lt;strong&gt;2.软件策划的目的及基础&lt;/strong&gt;

&lt;blockquote&gt;
  目的：是为软件开发和软件管理制定合理的计划。

  基础：是软件生命周期模型的选取。
&lt;/blockquote&gt;

&lt;strong&gt;3.软件策划的步骤&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;步骤&lt;/th&gt;
      &lt;th&gt;步骤名称&lt;/th&gt;
      &lt;th&gt;步骤内容&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;估计软件工作产品的规模、工作量、费用及所需的资源&lt;/td&gt;
      &lt;td&gt;软件工作产品，包括需求规格说明书，概要设计说明书，详细设计说明书，源代码，测试计划和测试报告，质量保证计划，软件配置管理计划，里程碑及评审点计划。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;制定时间表&lt;/td&gt;
      &lt;td&gt;包括看法进度时间表和管理进度时间表：软件开发计划、质量保证计划、软件配置管理计划、测试计划、评审计划&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;鉴别和评估风险&lt;/td&gt;
      &lt;td&gt;政策风险、资源风险、市场突变风险、技术风险和技能风险等&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;与相关的组或人协商策划中的有关约定&lt;/td&gt;
      &lt;td&gt;策划的结果是要实事求是，要得到各有关方面的同意和认可&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;4.软件估计&lt;/strong&gt;

&lt;blockquote&gt;
  指对软件项目进行量化估计，并记录估计结果的过程。软件估计是软件度量的一部分，它既是软件策划的核心，又是软件策划的重点与难点。
&lt;/blockquote&gt;

&lt;strong&gt;5.Delphi法&lt;/strong&gt;

&lt;blockquote&gt;
  基本步骤：

  (1)协调人向各专家提供项目规格和估计表格

  (2)协调人召集小组会，各专家讨论与规模相关的因素

  (3)各专家匿名填写迭代表格

  (4)协调人整理出一个估计总结，以迭代的形式返回专家。

  (5)协调人召集小组会，讨论较大的估计差异

  (6)专家复查估计，总结并在迭代基础上提交另一个匿名估计

  (7)重复步骤(4)~(6)，知道达到一个最低和最高估计的一致性为止，以完成此次估计
&lt;/blockquote&gt;

&lt;strong&gt;6.类比法&lt;/strong&gt;

&lt;blockquote&gt;
  基本步骤：

  (1)整理出项目功能列表和实现每个功能的代码行

  (2)标识出每个功能列表与历史项目的相同点与不同点，特别要注意历史项目做得不够的地方

  (3)通过步骤(1)和(2)得出各个功能的估计值

  (4)产生规模估计
&lt;/blockquote&gt;

&lt;strong&gt;7.功能点估计法&lt;/strong&gt;

&lt;blockquote&gt;
  基本不住：

  (1)计算输入、输出、查询、主控文件和接口需求的数目。

  (2)将这些数据进行加权相乘。

  (3)估计者根据对复杂度的判断，总数可以用+25%、0或-25%调整。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第六章-软件建模&quot;&gt;第六章 软件建模&lt;/h2&gt;

&lt;strong&gt;1.软件建模&lt;/strong&gt;

&lt;blockquote&gt;
  软件建模的三个模型通常是指功能模型、业务模型和数据模型。

  (1)功能模型实质上是用户需求模型，用来描述用户需求模型，用来描述系统能做什么，即对系统的功能、性能、接口和界面进行定义

  (2)业务模型实质上是业务逻辑模型，用于描述系统在何时、何地、由何角色、按什么业务规则去做，以及做的步骤或流程，即对系统的操作流程进行定义。

  (3)数据模型实质上是实体或类的状态关系模型，用于描述系统工作前的数据来自何处，工作中的数据暂存在什么地方，工作后的数据放到何处，以及这些数据的状态及互相之间的关联，即对系统的数据结构进行定义。
&lt;/blockquote&gt;

&lt;strong&gt;2.数据库设计的10个步骤&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;设计步骤&lt;/th&gt;
      &lt;th&gt;设计内容&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;第1步&lt;/td&gt;
      &lt;td&gt;将原始单据分类整理，理清原始单据与输出报表之间的数据转换关系计算法，澄清一切不确定的问题&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第2步&lt;/td&gt;
      &lt;td&gt;从原始单据出发，划分出各个实体，给实体命名，初步分配属性，表示出主键或外键，理清实体之间的关系&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第3步&lt;/td&gt;
      &lt;td&gt;进行数据库概念模型CDM设计，画出实体关系图ERD，定义完整性约束&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第4步&lt;/td&gt;
      &lt;td&gt;进行数据库物理数据模型PDM设计，将概念模型CDM转换为物理数据模型PDM&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第5步&lt;/td&gt;
      &lt;td&gt;在待定的数据库管理系统上定义表空间，实现物理建表与建索引&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第6步&lt;/td&gt;
      &lt;td&gt;定义触发器与存储过程&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第7步&lt;/td&gt;
      &lt;td&gt;定义视图，说明数据库与应用程序之间的关系&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第8步&lt;/td&gt;
      &lt;td&gt;数据库加载与测试：向基表中追加记录，对数据库的功能、性能进行全面测试&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第9步&lt;/td&gt;
      &lt;td&gt;数据库性能优化：从数据库系统的参数配置、数据库设计的反规范化过程的两个方面，对数据库的性能进行优化&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;第10步&lt;/td&gt;
      &lt;td&gt;数据库设计评审：从数据库的整体功能与性能两个方面，请同行专家评审评价&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;3.数据库设计与软件周期的关系&lt;/strong&gt;

&lt;blockquote&gt;
  一个面向对象的系统，开发阶段：需求确认-概要设计-详细设计-编码-单元测试-集成测试-系统测试-维护。数据库设计步骤：需求分析-概念设计-逻辑设计-物理设计-数据库实施与维护。数据库设计的第一个阶段需求分析是在系统开发之前考虑的，也考虑用户需要知道什么数据，需要操作哪些数据。第二阶段概念设计到第四阶段都是围绕第一阶段设计考虑的。与系统开发阶段相关的是第一阶段需求分析和最后的实施维护，数据库设计和系统开发相辅相成，系统开发的需求是为了了解用户能看到哪些界面，拥有哪些操作。而界面中的信息，操作的数据结果是数据库设计的。
&lt;/blockquote&gt;

&lt;strong&gt;4.范式理论&lt;/strong&gt;

&lt;blockquote&gt;
  第一范式：1NF是对属性的原子性约束，要求具有原子性，不可再分解。

  2NF是对记录的唯一性约束，要求记录有唯一标识，即实体的唯一性。

  3NF是对字段冗余性的约束，即任何字段不能由其他字段派生出来，它要求字段没有冗余。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第七章-软件设计&quot;&gt;第七章 软件设计&lt;/h2&gt;

&lt;strong&gt;1.三层体系结构&lt;/strong&gt;

&lt;blockquote&gt;
  表示层、中间层和数据层，各个层之间通过对外接口互相访问。分层结构的主要目的是，允许各层可以随着需求或技术的变化而独立地升级或替换，如当替换数据库时只需要变化数据层。

  表示层也称浏览层，它通常采用图形化用户界面，在客户端PC或工作站上允许。

  中间层也称业务层，有时又称应用层，它由许多构件或组件组成，他们完全体现了用户的业务逻辑或业务规则。

  数据层是数据库服务器上的数据库层，它包括数据库管理系统DBMS和数据库DB两部分。
&lt;/blockquote&gt;

&lt;strong&gt;2.三层结构的优点&lt;/strong&gt;

&lt;blockquote&gt;
  ①三层之间的低耦合，互不干扰，哪一层出了问题就去哪一层解决。同时，由于同一层内的各个类之间，也是低耦合，所以不会出现Bug现象。

  ②三层结构减少了客户机的工作量，提高了网络系统的运行效率。

  ③三层结构有利于系统的维护和生意，各个层的维护，互不影响。
&lt;/blockquote&gt;

&lt;strong&gt;3.三层与多层的关系&lt;/strong&gt;

&lt;blockquote&gt;
  若将中间层按照应用逻辑进一步划分，三层体系结构就变成了多层体系结构。
&lt;/blockquote&gt;

&lt;strong&gt;4.“设计“&lt;/strong&gt;

&lt;blockquote&gt;
  “设计”在IEEE中的定义是：定义一个系统或部件的架构、组成、接口或其他特征的“过程”，或者是“该过程的结果“。

  软件设计是一个过程，它是软件生命周期的一部分，是对软件需求分析后产生软件内部结构的一种描述。软件设计的结果，应能描述软件的架构，即软件中各个部件是如何分解并组合在一起的，这些描述将作为软件构建的基础。
&lt;/blockquote&gt;

&lt;strong&gt;5.软件设计原理&lt;/strong&gt;

&lt;blockquote&gt;
  1.抽象，是将几个有区别的物体的共同性质或特性，形象地抽取出来，独立地进行考虑的过程。包括控制抽象、过程抽象、数据抽象。

  2.模块化，就是解决一个复杂问题时，自顶向下、逐步求精地把软件系统划分成若干模块的过程。

  3.信息隐藏，指在设计和确定模块时，使一个模块内包含的信息(过程或数据)，对于不需要这些信息的其他模块来说是不能访问的。

  4.模块独立性,模块独立性指每个模块只完成系统要求的独立的子功能,并且与其他模块的联系最少且接口简单

  5.封装,是将信息隐藏在一个实体中,使其内部细节对外部不可见.封装是实现“低耦合,高内聚”的技术手段之一。

  6.接口和实现分离，将接口和实现分离开来，对外只提供接口，隐藏具体实现。接口与实现的分离，保证了实现的独立性，降低了模块间的耦合。
&lt;/blockquote&gt;

&lt;strong&gt;6.软件设计和软件需求的区别&lt;/strong&gt;

&lt;blockquote&gt;
  需求分析阶段的主要任务时确定系统必须“做什么“，形成软件的《需求分析规格说明书》，软件设计阶段的主要任务时确定系统”怎么做“，从软件《需求规格分析说明书》触发，形成软件的具体设计方案。软件设计可以采用多种方法，如面向程序设计、面向元数据设计、面向对象设计。
&lt;/blockquote&gt;

&lt;strong&gt;7.面向过程设计&lt;/strong&gt;

&lt;blockquote&gt;
  详细设计的工具分为图形、表格、语言三种，包括程序流程图、盒图(N-S图)、程序设计语言PDL、PAD图。
&lt;/blockquote&gt;

&lt;strong&gt;8.面向对象设计&lt;/strong&gt;

&lt;blockquote&gt;
  统一建模语言UML是一种图形化语言，提供了描述软件系统的图形和语法。UML既是面向对象需求分析的描述工具，又是面向对象架构设计的描述工具，更是面向对象详细设计的描述工具，它使软件开发三个重要阶段的描述工具统一起来，而且实现了平滑过渡与无缝连接，形成了一个从需求到设计的提花流程，使这三个阶段之间没有明显的界限。

  UML主要包括7种图形，用例图、类图、顺序图、状态图、活动图、部件图和部署图。
&lt;/blockquote&gt;

&lt;strong&gt;9.面向对象设计步骤&lt;/strong&gt;

&lt;blockquote&gt;
  1.需求分析，建立系统初步的功能模型、业务模型和数据模型

  2.架构设计，建立系统完整的功能模型、业务模型和数据模型

  3.详细设计，将功能模型、业务模型和界面模型中的各个部件加以实现

  4.编程实现，将模型中的各个部件实现文档转换为相应代码
&lt;/blockquote&gt;

&lt;strong&gt;10.三种设计方法关系&lt;/strong&gt;

&lt;blockquote&gt;
  面向过程、面向对象和面向元数据这三种设计方法，在多层网络结构的应用系统中找到了共同点，发挥了各自的优势，实现了互相依存，达到了和平共处。面向元数据方法用在数据库服务器层次上系统的设计与实现，面向对象方法用在除数据库服务器层次之外的其他层次上系统的设计与实现，面向过程方法用在其他两种方法本身内部函数的设计与实现。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第八章-软件实现&quot;&gt;第八章 软件实现&lt;/h2&gt;

&lt;h2 id=&quot;第九章-软件测试&quot;&gt;第九章 软件测试&lt;/h2&gt;

&lt;strong&gt;1.什么是软件测试&lt;/strong&gt;

&lt;blockquote&gt;
  软件测试是测试中的特例，因为其测试对形象是软件产品，它是人的智力产品，表现异常复杂，所以软件测试有自身的特点与难度，并具有挑战性。

  软件测试是按照规定的测试规程发现软件缺陷的过程。
&lt;/blockquote&gt;

&lt;strong&gt;2.什么是软件缺陷&lt;/strong&gt;

&lt;blockquote&gt;
  (1)软件未实现产品说明书要求的功能。

  (2)软件出现产品说明书指明不应该出现的错误。

  (3)软件实现了产品说明书未说明的功能。

  (4)软件未实现产品说明书虽未明确提及但应该实现的目标。

  (5)软件难以理解，不易使用，运行速度慢，或者软件测试员、最终用户认为软件不好。
&lt;/blockquote&gt;

&lt;strong&gt;3.软件测试模型&lt;/strong&gt;

&lt;blockquote&gt;
  V模型、X模型
&lt;/blockquote&gt;

&lt;strong&gt;4.黑盒测试&lt;/strong&gt;

&lt;blockquote&gt;
  黑盒测试是面向功能模型的测试。不考虑(主观上屏蔽)或者不需要(客观条件限制)知道被测对象的内部实现细节，只关心输入和输出。在运用黑盒测试方法进行软件测试时，它不关心软件的内部逻辑结构和实现方法，而是站在使用者的角度，主要测试软件的功能指标，即测试系统的功能模型。

  黑盒测试方法：等价类划分法、边界值分析法、错误推测法、因果图分析法、场景分析法。
&lt;/blockquote&gt;

&lt;strong&gt;5.白盒测试&lt;/strong&gt;

&lt;blockquote&gt;
  白盒测试是面向程序执行路径进行穷举代码测试，直至覆盖所有路径，才算完成了白盒测试。侧重于软件单元、模块和构件等小规模对象，绝对不适合软件项目或产品等大规模测试对象。

  (1)语句覆盖是最基本的覆盖，它要求设计足够多的测试用例，使程序中每条语句至少被执行一次。

  (2)判定覆盖又称分支覆盖，它要求设计足够多的测试用例，使程序中每个判定至少取一次真值和一次假值。

  (3)条件覆盖要求设计足够多的测试用例，使得判定中的每个条件语句取一次真值和一次假值。

  (4)判定/条件覆盖，是将判定覆盖和条件覆盖结合起来，设计足够多的测试用例，使判定语句被取一次真值和假值的同时，每个条件语句也同时被取一次真值和假值。
&lt;/blockquote&gt;

&lt;h2 id=&quot;第十章-软件实施与维护&quot;&gt;第十章 软件实施与维护&lt;/h2&gt;

&lt;strong&gt;1.软件产品的分类&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;类别&lt;/th&gt;
      &lt;th&gt;产品特点&lt;/th&gt;
      &lt;th&gt;举例&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;不需要客户化的软件产品&lt;/td&gt;
      &lt;td&gt;系统软件&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;只需要少量客户化工作的产品&lt;/td&gt;
      &lt;td&gt;专业性特强的应用软件产品&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;需要重新做业务流程规范和需求规格定义的软件产品&lt;/td&gt;
      &lt;td&gt;分行业的ERP&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;2.项目与产品的区别与联系&lt;/strong&gt;

&lt;blockquote&gt;
  软件产品是指不局限于特定业务领域、能被广大用户直接使用的软件系统。软件项目是指针对特定专业领域、需要提供业务流程充足与优化的软件系统。软件项目的特点是，业务领域知识所占的比重大，工程性强.

  项目和产品既有显著的不同，又有紧密的关系。做软件项目是手段，做软件产品是目的，软件项目做多了，软件项目就慢慢地百年成了软件产品。
&lt;/blockquote&gt;

&lt;strong&gt;3.三分软件七分实施&lt;/strong&gt;

&lt;h2 id=&quot;第十一章-软件管理&quot;&gt;第十一章 软件管理&lt;/h2&gt;

软件管理是面向过程的，其主要模型时CMMI模型，ISO9001模型，软件企业文化模型。

CMMI是由美国卡内基-梅隆大学软件工程研究所CMU/SEI推出的评估软件能力与成熟度等级的一套标准。

&lt;strong&gt;1.CMMI的应用领域具体表现在三个方面&lt;/strong&gt;

&lt;blockquote&gt;
  (1)软件组织，用它来不断改进自身的软件过程管理能力。

  (2)评估机构，用它来评估某软件组织当前软件能力成熟度级别。

  (3)客户，用它来评价某承包商的软件能力。
&lt;/blockquote&gt;

&lt;strong&gt;2.CMMI阶段模型的成熟度等级&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;CMMI的等级&lt;/th&gt;
      &lt;th&gt;PA数目&lt;/th&gt;
      &lt;th&gt;管理特点&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ML1:Initial（初始级）&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;过程不可预测且缺乏控制&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ML2:Managed（已管理级）&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;过程为项目服务，即项目级管理&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ML3:Defined（已定义级）&lt;/td&gt;
      &lt;td&gt;11&lt;/td&gt;
      &lt;td&gt;过程为组织服务，即组织级管理&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ML4:Quantitatively Managed（定量管理级）&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;过程已度量和控制，即定量级管理&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;ML5:Optimizing（优化级）&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
      &lt;td&gt;集中于过程改进，即优化级管理&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;strong&gt;3.ISO 9001与 CMMI 的联系与区别&lt;/strong&gt;

&lt;blockquote&gt;
  相同点：CMMI和 ISO 9001标准都致力于质量和过程管理，都是为了解决同样的问题。

  不同点：CMMI 是动态的、开放的和持续改进的，它强调“没有最好，只有更好”，强调不断改进，强调人在软件开发方面的主动性，非常适用于软件过程的改进；ISO 9001是静态的质量控制，只要达到20个关键指标或过程，就能完成质量控制，它更适用于硬件制造行业和第三产业的质量控制

  CMMI是“专用”，ISO 9001是“通用”，ISO 9001不覆盖CMMI，CMMI也不完全覆盖ISO 9001。
&lt;/blockquote&gt;

&lt;strong&gt;4.项目经理对程序员的八项要求&lt;/strong&gt;

&lt;blockquote&gt;
  (1)团队协作精神的训练和要求

  (2)数据库和数据结构分析与设计能力的训练和要求

  (3)书写文档习惯的训练和要求

  (4)规范化代码编写能力的训练和要求

  (5)复用性能力和构件技术的训练和要求

  (6)测试习惯的训练和要求

  (7)学习和总结能力的训练和要求

  (8)引导程序员由”丑小鸭”变成”白天鹅”
&lt;/blockquote&gt;

&lt;a href=&quot;#top&quot;&gt;回到顶部&lt;/a&gt;
</description>
        <pubDate>Wed, 12 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/12/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/12/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/</guid>
        
        <category>软件工程</category>
        
        
        <category>软件工程</category>
        
      </item>
    
      <item>
        <title>Spring</title>
        <description>&lt;a id=&quot;top&quot;&gt;&lt;/a&gt;

&lt;h2 id=&quot;五spring&quot;&gt;五、Spring&lt;/h2&gt;

Spring是一个开源框架，它是为了解决企业应用开发的复杂性问题而创建的，Spring使用基本的JavaBean来完成组件封装。

&lt;strong&gt;1.使JavaEE的开发更容易、更简单&lt;/strong&gt;

&lt;blockquote&gt;
  1.方便解耦，简化开发

  2.AOP编程的支持

  3.声明式事务的支持

  4.方便程序的测试

  5.方便集成各种优秀的框架

  6.降低Java EE API 的使用难度
&lt;/blockquote&gt;

&lt;img src=&quot;F:\desk\md\Typora\images\spring模块.png&quot; alt=&quot;&quot; /&gt;

&lt;strong&gt;2.控制反转和依赖注入&lt;/strong&gt;

&lt;blockquote&gt;
  Inversion of Control ，IOC，控制反转，通过配置文件new对象。

  IOC是Spring容器的内核，AOP、声明事务等功能都是在此基础上发展衍生而来。

  AOP: Aspect Oriented Programming，面向切面编程。

  DI: 依赖注入。Dependency Inject，对象之间的依赖关系，通过配置文件进行关联。
&lt;/blockquote&gt;

&lt;strong&gt;3.导包&lt;/strong&gt;

&lt;blockquote&gt;
  spring-beans-x.jar：JavaBean对象

  spring-context-x.jar：上下文它一般指的是存放数据的地方(对象)，存放数据应当有”生命周期”。

  spring-core-x.jar：核心包

  spring-expression-x.jar：能够解析EL表达式

  commons-logging-x.jar：日志
&lt;/blockquote&gt;

&lt;strong&gt;4.applicationContext.xml&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot;
	&quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 默认单例，singleton设置是否单例 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 饿汉式，服务器启动就加载 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.User&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;singleton=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;false&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;张三&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userPass&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123456&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;email&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;email&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;email&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Email&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;emailID&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;address&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;abc@qq.com&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userManager&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.UserManager&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;group1&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;list&amp;gt;&lt;/span&gt;
            	&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.User&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
                	&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;张三&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userPass&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123456&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.User&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
                	&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;李四&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userPass&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123456&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/list&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/property&amp;gt;&lt;/span&gt;
        
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;group2&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;map&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;entry&amp;gt;&lt;/span&gt;
                    &lt;span class=&quot;nt&quot;&gt;&amp;lt;key&amp;gt;&amp;lt;value&amp;gt;&lt;/span&gt;前台&lt;span class=&quot;nt&quot;&gt;&amp;lt;/value&amp;gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
                    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.User&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userName&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;李四&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;userPass&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123456&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;/entry&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/map&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/property&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;5.测试&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestUser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ApplicationContext&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; 
            &lt;span class=&quot;n&quot;&gt;ClassPathXmlApplicationContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;applicationContext.xml&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBean&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//利用反射&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;User&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getBean&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;6.AOP的关键术语&lt;/strong&gt;

&lt;blockquote&gt;
  切面	Aspect	切面在什么时候在什么地方增强什么功能

  增强	Advice	增强的功能，也称为“通知”

  连接点	Joinpoint	时机

  切入点	Pointcut	位置

  目标对象	Target	原有业务对象

  代理对象	Proxy	使用了增强之后，创建的新对象其包含了原有对象

  织入	Weaving	把增强的功能织入原有对象的过程
&lt;/blockquote&gt;

&lt;strong&gt;7.需要新添加的包&lt;/strong&gt;

&lt;blockquote&gt;
  spring-aop-x.jar

  spring-aspects-x.jar

  aopalliance.jar	第三方库
&lt;/blockquote&gt;

&lt;strong&gt;8.applicationContext.xml&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 不再使用dtd的方式来限定xml文件中的标签，而使用新型xsd来限定! --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:p=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/p&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans 
                   http://www.springframework.org/schema/beans/spring-beans-3.2.xsd&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 配置原有业务对象 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.business.CustomerImpl&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 配置增强对象 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myAfterAdvice&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.aop.MyAfterAdvice&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myBeforeAdvice&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.aop.MyBeforeAdvice&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;regexpAop&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.aop.support.RegexpMethodPointcutAdvisor&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:advice-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myAfterAdvice&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:pattern=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;.*IPhone.*&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;methodAop&quot;&lt;/span&gt; 
          &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.aop.support.NameMatchMethodPointcutAdivsor&quot;&lt;/span&gt;
    	&lt;span class=&quot;na&quot;&gt;p:mappedNames=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;buyIPhone,buyIPhone7&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;p:advice-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myAfterAdvice&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 配置用于真正调用的业务代理对象，其内部使用了原有业务对象的功能和增强的功能 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customerProxy&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.aop.framework.ProxyFactoryBean&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:proxyInterfaces=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.business.ICustomer&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:target-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;customer&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:interceptorNames=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;myBeforeAdvice,regexpAop&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MyAfterAdvice&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AfterReturningAdvice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//本方法会在目标对象对应业务方法调用完毕后。自动调用本方法&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;afterReturning&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Method&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 
        &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Throwable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//参数1：原有业务方法的返回值（如果有的话）&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//参数2：原有业务方法的抽象对象&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//参数3：业务方法调用时，实际填入的参数形式的数组&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//参数4：调动业务方法的业务对象，也许为null&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arg3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CustomerImpl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;顾客买了苹果产品，赠送贴膜一张！&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MyBeforeAdvice&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MethodBeforeAdvice&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;befor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Method&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Throwable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;进店有礼，赠送代金券一张！&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;9.使用第三方包&lt;/strong&gt;

&lt;blockquote&gt;
  aspectj-x.jar

  aspectjweaver-x.jar

  cglib-nodep-x.jar
&lt;/blockquote&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nd&quot;&gt;@Aspect&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Camers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@Before&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;execution(* cn,dlian.business.Employee.*Eat*(..))&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foundEat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;发现员工准备吃东西，警告一次&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nd&quot;&gt;@AfterReturning&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;execution(* cn,dlian.business.Employee.*Game(..))&quot;&lt;/span&gt;
                   &lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;returning&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ret&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foundPlay&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;JoinPoint&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Signature&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getSingnature&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//增强器，拦截一次业务方法调用时形成的信息对象&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//String className = sig.getDeclaringTypeName(); //业务类名&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getArgs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//获得调用业务方法时填入的实参&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;methodName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sig&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//本次拦截的业务方法名&lt;/span&gt;
    	&lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;员工调用了&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;methodName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;,发现员工在玩游戏！&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;   
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 不再使用dtd的方式来限定xml文件中的标签，而使用新型xsd来限定! --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:p=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/p&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:aop=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/aop&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans 
                   http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd&quot;&lt;/span&gt;
       &lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 员工对象 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;emp&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.business.Employee&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 摄像头对象 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;camera&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.aop.Camera&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 开启aop自动注解扫描，它会自动扫描所有类里面的AOP注解 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;aop:aspectj-autoproxy&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;10整合mybatis&lt;/strong&gt;

&lt;blockquote&gt;
  spring-jdbc-x.jar

  spring-tx-x.jar

  commons-pool-x.jar：连接池

  commons-dbcp-x.jar

  commons-logging-x.jar
&lt;/blockquote&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 不再使用dtd的方式来限定xml文件中的标签，而使用新型xsd来限定! --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;beans&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:p=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/p&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:aop=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/aop&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xmlns:tx=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/tx&quot;&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.springframework.org/schema/beans 
                   http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd &quot;&lt;/span&gt;
       &lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 1.配置数据源，其用于连接数据库 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dataSource&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.apache.commons.dbcp.BasicDataSource&quot;&lt;/span&gt;
    	  &lt;span class=&quot;na&quot;&gt;p:driverClassName=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;com.mysql.cj.jdbc.Driver&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:url=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jdbc:mysql://127.0.0.1:3306/dssims?serverTimezone=UTC&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:username=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;root&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:password=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;xuelei123&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:initialSize=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;5&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:maxActive=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;50&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:maxIdle=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;20&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:minIdle=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;5&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:maxWait=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;10000&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:validationQuery=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;select 1 from dual&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:testOnBorrow=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;false&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:testOnReturn=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:testWhileIdle=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:minEvictableIdleTimeMillis=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;60000&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:timeBetweenEvictionRunsMillis=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;300000&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 2.根据已经配置好的数据源，生成sessionFactory对象 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sessionFactory&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:configLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;classpath:MyBatis-config.xml&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:dataSource-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dataSource&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:mapperLocations=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;classpath:cn/dlian/entities/*.xml&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!--  3.配置SqlSession，注入SqlSessionTemplate，
		Dao层使用它来进行数据库操作(而不是SessionFatory来open了)--&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sqlSession&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.mybatis.spring.SqlSessionTemplate&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;constructor-arg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;index=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;0&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sessionFactory&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/bean&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 4.设置spring的事务管理器 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;transactionManager&quot;&lt;/span&gt; 
          &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:dataSource-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dataSource&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 5.开启注解方式，进行自动事务处理的能力 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;tx:annotation-driven&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;transaction-manager=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;transactionManager&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 6.配置业务中所需的各个bean，及其依赖关系 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;empDao&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.dao.EmpDaoImpl&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:sessionFactory-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;sessionFactory&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;bean&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;empService&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.service.EmpServiceImpl&quot;&lt;/span&gt;
          &lt;span class=&quot;na&quot;&gt;p:empDao-ref=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;empDao&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/beans&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  @Transactional	自动事务处理
&lt;/blockquote&gt;

&lt;a href=&quot;#top&quot;&gt;回到顶部&lt;/a&gt;
</description>
        <pubDate>Tue, 11 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/11/Spring/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/11/Spring/</guid>
        
        <category>Spring</category>
        
        
        <category>JavaWeb</category>
        
      </item>
    
      <item>
        <title>MyBatis</title>
        <description>&lt;a id=&quot;top&quot;&gt;&lt;/a&gt;

&lt;h2 id=&quot;四mybatis&quot;&gt;四、MyBatis&lt;/h2&gt;

&lt;strong&gt;1.需要导三个包：&lt;/strong&gt;

&lt;blockquote&gt;
  数据库驱动包

  mybatis-3.4.4.jar

  log4j-1.2.16.jar+log4j.properties
&lt;/blockquote&gt;

&lt;strong&gt;2.创建MyBatis-config.xml配置&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE configuration PUBLIC
	&quot;-//mybatis.org//DTD Config 3.0//EN&quot; &quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 在XML Catalog进行配置，网址映射到本地文件 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- mybatis若取到空值，其类型为other，配置成NULL --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;settings&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;setting&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jdbcTypeForNull&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;NULL&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/settings&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 环境配置 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;environment&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;default=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;development&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;environment&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;development&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;transactionManager&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;JDBC&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;dataSource&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;POOLED&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
            	&lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;driver&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;oracle.jdbc.driver.OracleDriver&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;url&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;jdbc:oracle:thin:@127.0.0.1:1521/lizi&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;username&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SYSTEM&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;property&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;password&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Xuelei123&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/dataSource&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/environment&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/environment&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;mappers&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;mapper&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resource=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn/dlian/entities/EmpMapper.xml&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/mappers&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;3.Mappier.xml配置&lt;/strong&gt;

作用：

&lt;blockquote&gt;
  连接数据库，并且设置

  把所有的映射文件引用进来

  采用#可以防止sql注入
&lt;/blockquote&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE mapper PUBLIC
	&quot;-//mybatis.org//DTD Config 3.0//EN&quot; &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- EmpMappier.xml --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- namespace作用是找到当前映射文件中的某个具体语句，其值唯一 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mapper&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;namespace=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.EmpMapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 查询语句 --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getEmpById&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;int&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resultType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	select * from EMP where EMPNO = #{id}
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!--封装成一个对象，语句中写入其属性--&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getEmpsByJobAndSal&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;resultType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		select * from Emp where JOB=#{JOB} and SAL &amp;gt;#{SAL}
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!--将参数加入到Map中，传入Map,语句中写入key值--&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getEmpsBySalaryMinMax&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;hashmap&quot;&lt;/span&gt; 
            &lt;span class=&quot;na&quot;&gt;resultType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	select * from EMP where SAL between #{low} and #{high}
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getEmpByMultiInfo&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;resultType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		select * from EMP
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;where&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;if&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;test=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SAL != null&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
            	SAL &amp;gt; #{SAL}
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/if&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;if&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;test=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;COMM != null&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
            	and COMM &amp;gt; #{COMM}
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/if&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/where&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 插入 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;insert&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;insertEmp&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		inser into EMP values(#{EMPNO},#{ENAME},#{JOB},#{MGR},#{HIREDATE},#{SAL},#{COMM},#{DEPTNO})
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/insert&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 删除 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;delete&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;deleteEmpByID&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;int&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		delete from EMP where EMPNO = #{id}
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/delete&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 修改 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;update&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;updateEmp&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		update EMP set ENAME = #{ENAME},JOB=#{JOB}
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/update&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/mapper&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;4.MyBatisHelper&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MyBatisHelper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlSessionFactory&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sessionFactory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//此种方法加载一个文件，适用于jar包内!&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;InputStream&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
           &lt;span class=&quot;n&quot;&gt;MyBatisHelper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getClassLoader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;
               &lt;span class=&quot;n&quot;&gt;getResourceAsStream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MyBatis-config.xml&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//通过配置文件(的输入流)，创建一个SessionFactory&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sessinFactory&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlSessionFactoryBuilder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;   
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SqlSession&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getSqlSessionFactory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//通过一个已经连接好数据库的工厂类，获取当前连接会话对形象(用于正删改查),用完请归还 &lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sessionFactory&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;openSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;5.Dao层&lt;/strong&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EmpDaoImpl&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IEmpDao&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getEmpByID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//通过SessionFactory，获取当前session&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SqlSession&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyBatisHelper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getSqlSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//找到映射文件中的语句，并传递阐述，执行后获取返回结果！&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.EmpMapper.getEmpById&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;selectOne&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//手动关闭一个session，释放资源&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//传递对象的属性&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getEmpsByJobAndSal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SqlSession&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyBatisHelper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getSqlSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.EmpMapper.getEmpsByJobAndSal&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;selectList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//传递多个参数时，利用Map&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getEmpsBySalaryMinMax&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SqlSession&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MyBatisHelper&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getSqlSession&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.EmpMapper.getEmpsBySalaryMinMax&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;HashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Float&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HashMap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Float&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;low&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;high&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Emp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;selectList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;emps&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;strong&gt;6.关系映射&lt;/strong&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE mapper PUBLIC
	&quot;-//mybatis.org//DTD Config 3.0//EN&quot; &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- EmpMappier.xml --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- namespace作用是找到当前映射文件中的某个具体语句，其值唯一 --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;mapper&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;namespace=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.EmpMapper&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 1.多对一的映射，应当先定义出存放多对一结果的“结果类型”，MyBatis中称为“结果集“ --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 一对一在java代码中其实就是多对一，只是外键在数据库中唯一，导致逻辑上为一对一 --&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;resultMap&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EmpWithDeptType&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;id&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EMPNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EMPNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ENAME&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ENAME&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;JOB&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;JOB&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MGR&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MGR&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;HIREDATE&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;HIREDATE&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SAL&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SAL&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;COMM&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;COMM&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 在一个类的内部，“绑定”另一个对象 --&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;association&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dept&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;javaType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Dept&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;id&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DNAME&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DNAME&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
       		&lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LOC&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LOC&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/association&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/resultMap&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getEmpById&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;int&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resultMap=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EmpWithDeptType&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	select * from EMP join DEPT on EMP.DEPTNO = DEPT.DEPTNO where EMPNO = #{id}
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- 2.一对多映射，类似于多对一，也需要先定义一个“结果集” --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;resultMap&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DeptWithEmpsType&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Dept&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	&lt;span class=&quot;nt&quot;&gt;&amp;lt;id&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DNAME&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DNAME&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LOC&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;LOC&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;collection&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;emps&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ofType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cn.dlian.entities.Emp&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        	&lt;span class=&quot;nt&quot;&gt;&amp;lt;id&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EMPNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;EMPNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ENAME&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ENAME&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;JOB&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;JOB&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MGR&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MGR&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;HIREDATE&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;HIREDATE&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SAL&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SAL&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;COMM&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;COMM&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;result&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;property=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;column=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DEPTNO&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/collection&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/resultMap&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;select&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;getDeptWithEmpByID&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;parameterType=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;int&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;resultMap=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;DeptWithEmpsType&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    	select * from EMP join DEPT on EMP.DEPTNO = DEPT.DEPTNO where DEPT.DEPTNO = #{id} 
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/mapper&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Mon, 10 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/10/MyBatis/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/10/MyBatis/</guid>
        
        <category>MyBatis</category>
        
        
        <category>JavaWeb</category>
        
      </item>
    
      <item>
        <title>JSTL</title>
        <description>&lt;h2 id=&quot;三jstl&quot;&gt;三、JSTL&lt;/h2&gt;

&lt;strong&gt;使用了EL表达式可以简化JSP页面代码，但是如果需要进行逻辑判断该怎么办？&lt;/strong&gt;

&lt;blockquote&gt;
  虽然EL表达式可以访问JavaBean的属性，但是并不能实现在JSP中进行逻辑判断，因而要使用JSTL标签

  使用JSTL实现JSP页面中逻辑跳转，需要导包
&lt;/blockquote&gt;

&lt;strong&gt;1.什么是JSTL&lt;/strong&gt;

&lt;blockquote&gt;
  JSTL（JavaServerPages Standard Tag Library）JSP标准标签库

  JSTL通常会与EL表达式合作实现JSP页面的编码
&lt;/blockquote&gt;

&lt;strong&gt;2.JSTL标签库&lt;/strong&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;功能领域&lt;/th&gt;
      &lt;th&gt;URI&lt;/th&gt;
      &lt;th&gt;前缀&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Core&lt;/td&gt;
      &lt;td&gt;http://java.sun.com/jsp/jstl/core&lt;/td&gt;
      &lt;td&gt;c&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Format&lt;/td&gt;
      &lt;td&gt;http://java.sun.com/jsp/jstl/fmt&lt;/td&gt;
      &lt;td&gt;fmt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SQL&lt;/td&gt;
      &lt;td&gt;http://java.sun.com/jsp/jstl/sql&lt;/td&gt;
      &lt;td&gt;sql&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;XML&lt;/td&gt;
      &lt;td&gt;http://java.sun.com/jsp/jstl/xml&lt;/td&gt;
      &lt;td&gt;xml&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Functions&lt;/td&gt;
      &lt;td&gt;http://java.sun.com/jsp/jstl/functions&lt;/td&gt;
      &lt;td&gt;fn&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;pre&gt;&lt;code class=&quot;language-jsp&quot;&gt;&amp;lt;!-- jsp自带标签库 --&amp;gt;
&amp;lt;%@ page language=&quot;java&quot; import=&quot;java.util.*,cn.dlian.entities.*&quot; 
    contentType=&quot;text/html;charset=utf-8&quot; %&amp;gt;
&amp;lt;!-- 引入其他库标签 --&amp;gt;
&amp;lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&amp;gt;

&amp;lt;!-- 1.设置变量，及存储范围（4大作用域） --&amp;gt;
&amp;lt;c:set var=&quot;example&quot; value=&quot;10&quot; scope=&quot;page&quot; /&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;!-- 打印一个4大作用域的值 --&amp;gt;
&amp;lt;!-- out开闭标签之间的值，是在value值获取不到时，才能显示 --&amp;gt;
&amp;lt;c:out value=&quot;${example }&quot;&amp;gt;值存在&amp;lt;/c:out&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;!-- 2.删除一个4大作用域中已存在的值 --&amp;gt;
&amp;lt;c:remove var=&quot;example&quot; scope=&quot;page&quot; /&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;!-- 3.使用set标签中的值，作为value --&amp;gt;
&amp;lt;c:set var=&quot;data&quot;&amp;gt;data的数值&amp;lt;/c:set&amp;gt;&amp;lt;br&amp;gt;	&amp;lt;!-- 默认存放在pageContext中 --&amp;gt;
data的数值为:&amp;lt;c:out value=&quot;${data }&quot; /&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;!-- 4.结合jsp:userBean，来设置一个java bean对象 --&amp;gt;
&amp;lt;jsp:userBean id=&quot;user&quot; class=&quot;cn.dlian.entities.UserInfo&quot; scope=&quot;page&quot;&amp;gt;&amp;lt;/jsp:userBean&amp;gt;
&amp;lt;c:set target=&quot;${user }&quot; property=&quot;User_ID&quot; value=&quot;1&quot; /&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;c:set target=&quot;${user }&quot; property=&quot;User_ID&quot; value=&quot;zhangsan&quot; /&amp;gt;&amp;lt;br&amp;gt;

id:${user.USER_ID }&amp;lt;br&amp;gt;
name:&amp;lt;c:out value=&quot;${user.USER_NAME}&quot;&amp;gt;用户名不存在&amp;lt;/c:out&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;!-- 5.选择 --&amp;gt;
&amp;lt;c:choose&amp;gt;
	&amp;lt;c:when text=&quot;${score&amp;lt; 60}&quot;&amp;gt;不及格&amp;lt;/c:when&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;c:when text=&quot;${score&amp;gt;=60&amp;amp;&amp;amp;score&amp;lt;8}&quot;&amp;gt;及格&amp;lt;/c:when&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;c:when text=&quot;${score&amp;gt;=85}&amp;amp;&amp;amp;score&amp;lt;100&quot;&amp;gt;优秀&amp;lt;/c:when&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;c:otherwise&amp;gt;满分！&amp;lt;/c:when&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;/c:choose&amp;gt;

&amp;lt;!-- 6.循环 相当于Java张总的快速迭代 ,varStatus中存放了循环的下标、次数等特殊信息--&amp;gt;
&amp;lt;!-- varstatus为循环遍历时的辅助信息，它存放在pageCOntext中，也可用count代替index --&amp;gt;
&amp;lt;c:forEach var=&quot;hobby&quot; item=&quot;${paramValus.habbies }&quot; varStatus=&quot;stat&quot;&amp;gt;
	爱好${stat.index + 1} : ${hobby }&amp;lt;br&amp;gt;
    &amp;lt;c:if text=&quot;${stat.first }&quot;&amp;gt;第一个爱好：&amp;lt;/c:if&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;c:if text=&quot;${stat.last }&quot;&amp;gt;最后爱好：&amp;lt;/c:if&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;/c:forEach&amp;gt;

&amp;lt;!-- 7.数组 --&amp;gt;
&amp;lt;c:set var=&quot;str&quot; value=&quot;1,2,3,4,5&quot; /&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;c:forTokens item=&quot;${str }&quot; delims=&quot;,&quot; varStatus=&quot;stat&quot;&amp;gt;
第${stat.count }个元素为:${stat.curent }&amp;lt;br&amp;gt;
&amp;lt;/c:forTokens&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  uri告诉你东西是什么没告诉在哪

  url告诉你东西是什么并且在哪
&lt;/blockquote&gt;
</description>
        <pubDate>Sun, 09 Jun 2019 00:00:00 +0000</pubDate>
        <link>https://DaLian369.github.io/2019/06/09/JSTL%E6%A0%87%E7%AD%BE%E5%BA%93/</link>
        <guid isPermaLink="true">https://DaLian369.github.io/2019/06/09/JSTL%E6%A0%87%E7%AD%BE%E5%BA%93/</guid>
        
        <category>JSTL标签库</category>
        
        
        <category>JavaWeb</category>
        
      </item>
    
  </channel>
</rss>
