MySQL之表的约束

一 介绍

约束条件与数据类型的宽度一样,都是可选参数

作用:用于保证数据的完整性和一致性
主要分为:

PRIMARY KEY (PK)    标识该字段为该表的主键,可以唯一的标识记录
FOREIGN KEY (FK)    标识该字段为该表的外键
NOT NULL    标识该字段不能为空
UNIQUE KEY (UK)    标识该字段的值是唯一的
AUTO_INCREMENT    标识该字段的值自动增长(整数类型,而且为主键)
DEFAULT    为该字段设置默认值UNSIGNED 无符号
ZEROFILL 使用0填充

 

说明:

1. 是否允许为空,默认NULL,可设置NOT NULL,字段不允许为空,必须赋值
2. 字段是否有默认值,缺省的默认值是NULL,如果插入记录时不给字段赋值,此字段使用默认值
sex enum('male','female') not null default 'male'
age int unsigned NOT NULL default 20 必须为正值(无符号) 不允许为空 默认是20
3. 是否是key
主键 primary key
外键 foreign key
索引 (index,unique...)

二 not null与default

是否可空,null表示空,非字符串
not null - 不可空
null - 可空


默认值,创建列时可以指定默认值,当插入数据时如果未主动设置,则自动添加默认值
create table tb1(
nid int not null defalut 2,
num int not null
)

==================not null====================
mysql> create table t1(id int); #id字段默认可以插入空
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
mysql> insert into t1 values(); #可以插入空
mysql> create table t2(id int not null); #设置字段id不为空
mysql> desc t2;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | NO   |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
mysql> insert into t2 values(); #不能插入空
ERROR 1364 (HY000): Field 'id' doesn't have a default value==================default====================
#设置id字段有默认值后,则无论id字段是null还是not null,都可以插入空,插入空默认填入default指定的默认值
mysql> create table t3(id int default 1);
mysql> alter table t3 modify id int not null default 1;==================综合练习====================
mysql> create table student(-> name varchar(20) not null,-> age int(3) unsigned not null default 18,-> sex enum('male','female') default 'male',-> hobby set('play','study','read','music') default 'play,music'-> );
mysql> desc student;
+-------+------------------------------------+------+-----+------------+-------+
| Field | Type                               | Null | Key | Default    | Extra |
+-------+------------------------------------+------+-----+------------+-------+
| name  | varchar(20)                        | NO   |     | NULL       |       |
| age   | int(3) unsigned                    | NO   |     | 18         |       |
| sex   | enum('male','female')              | YES  |     | male       |       |
| hobby | set('play','study','read','music') | YES  |     | play,music |       |
+-------+------------------------------------+------+-----+------------+-------+
mysql> insert into student(name) values('egon');
mysql> select * from student;
+------+-----+------+------------+
| name | age | sex  | hobby      |
+------+-----+------+------------+
| egon |  18 | male | play,music |
+------+-----+------+------------+
验证

三 unique

============设置唯一约束 UNIQUE===============
方法一:
create table department1(
id int,
name varchar(20) unique,
comment varchar(100)
);方法二:
create table department2(
id int,
name varchar(20),
comment varchar(100),
constraint uk_name unique(name)
);mysql> insert into department1 values(1,'IT','技术');
Query OK, 1 row affected (0.00 sec)
mysql> insert into department1 values(1,'IT','技术');
ERROR 1062 (23000): Duplicate entry 'IT' for key 'name'
View Code
mysql> create table t1(id int not null unique);
Query OK, 0 rows affected (0.02 sec)mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | NO   | PRI | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)
not null+unique的化学反应
create table service(
id int primary key auto_increment,
name varchar(20),
host varchar(15) not null,
port int not null,
unique(host,port) #联合唯一
);mysql> insert into service values-> (1,'nginx','192.168.0.10',80),-> (2,'haproxy','192.168.0.20',80),-> (3,'mysql','192.168.0.30',3306)-> ;
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0mysql> insert into service(name,host,port) values('nginx','192.168.0.10',80);
ERROR 1062 (23000): Duplicate entry '192.168.0.10-80' for key 'host'
联合唯一

四 primary key

primary key字段的值不为空且唯一

一个表中可以:

单列做主键
多列做主键(复合主键)

但一个表内只能有一个主键primary key

============单列做主键===============
#方法一:not null+unique
create table department1(
id int not null unique, #主键
name varchar(20) not null unique,
comment varchar(100)
);mysql> desc department1;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id      | int(11)      | NO   | PRI | NULL    |       |
| name    | varchar(20)  | NO   | UNI | NULL    |       |
| comment | varchar(100) | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
rows in set (0.01 sec)#方法二:在某一个字段后用primary key
create table department2(
id int primary key, #主键
name varchar(20),
comment varchar(100)
);mysql> desc department2;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id      | int(11)      | NO   | PRI | NULL    |       |
| name    | varchar(20)  | YES  |     | NULL    |       |
| comment | varchar(100) | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
rows in set (0.00 sec)#方法三:在所有字段后单独定义primary key
create table department3(
id int,
name varchar(20),
comment varchar(100),
constraint pk_name primary key(id); #创建主键并为其命名pk_name

mysql> desc department3;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id      | int(11)      | NO   | PRI | NULL    |       |
| name    | varchar(20)  | YES  |     | NULL    |       |
| comment | varchar(100) | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
rows in set (0.01 sec)
单列主键
==================多列做主键================
create table service(
ip varchar(15),
port char(5),
service_name varchar(10) not null,
primary key(ip,port)
);mysql> desc service;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| ip           | varchar(15) | NO   | PRI | NULL    |       |
| port         | char(5)     | NO   | PRI | NULL    |       |
| service_name | varchar(10) | NO   |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)mysql> insert into service values-> ('172.16.45.10','3306','mysqld'),-> ('172.16.45.11','3306','mariadb')-> ;
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0mysql> insert into service values ('172.16.45.10','3306','nginx');
ERROR 1062 (23000): Duplicate entry '172.16.45.10-3306' for key 'PRIMARY'
多列主键

五 auto_increment

约束字段为自动增长,被约束的字段必须同时被key约束

#不指定id,则自动增长
create table student(
id int primary key auto_increment,
name varchar(20),
sex enum('male','female') default 'male'
);mysql> desc student;
+-------+-----------------------+------+-----+---------+----------------+
| Field | Type                  | Null | Key | Default | Extra          |
+-------+-----------------------+------+-----+---------+----------------+
| id    | int(11)               | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20)           | YES  |     | NULL    |                |
| sex   | enum('male','female') | YES  |     | male    |                |
+-------+-----------------------+------+-----+---------+----------------+
mysql> insert into student(name) values-> ('egon'),-> ('alex')-> ;mysql> select * from student;
+----+------+------+
| id | name | sex  |
+----+------+------+
|  1 | egon | male |
|  2 | alex | male |
+----+------+------+#也可以指定id
mysql> insert into student values(4,'asb','female');
Query OK, 1 row affected (0.00 sec)mysql> insert into student values(7,'wsb','female');
Query OK, 1 row affected (0.00 sec)mysql> select * from student;
+----+------+--------+
| id | name | sex    |
+----+------+--------+
|  1 | egon | male   |
|  2 | alex | male   |
|  4 | asb  | female |
|  7 | wsb  | female |
+----+------+--------+#对于自增的字段,在用delete删除后,再插入值,该字段仍按照删除前的位置继续增长
mysql> delete from student;
Query OK, 4 rows affected (0.00 sec)mysql> select * from student;
Empty set (0.00 sec)mysql> insert into student(name) values('ysb');
mysql> select * from student;
+----+------+------+
| id | name | sex  |
+----+------+------+
|  8 | ysb  | male |
+----+------+------+#应该用truncate清空表,比起delete一条一条地删除记录,truncate是直接清空表,在删除大表时用它
mysql> truncate student;
Query OK, 0 rows affected (0.01 sec)mysql> insert into student(name) values('egon');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+----+------+------+
| id | name | sex  |
+----+------+------+
|  1 | egon | male |
+----+------+------+
1 row in set (0.00 sec)
View Code
#在创建完表后,修改自增字段的起始值
mysql> create table student(-> id int primary key auto_increment,-> name varchar(20),-> sex enum('male','female') default 'male'-> );mysql> alter table student auto_increment=3;mysql> show create table student;
.......
ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mysql> insert into student(name) values('egon');
Query OK, 1 row affected (0.01 sec)mysql> select * from student;
+----+------+------+
| id | name | sex  |
+----+------+------+
|  3 | egon | male |
+----+------+------+
row in set (0.00 sec)mysql> show create table student;
.......
ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8#也可以创建表时指定auto_increment的初始值,注意初始值的设置为表选项,应该放到括号外
create table student(
id int primary key auto_increment,
name varchar(20),
sex enum('male','female') default 'male'
)auto_increment=3;#设置步长
sqlserver:自增步长基于表级别create table t1(id int。。。)engine=innodb,auto_increment=2 步长=2 default charset=utf8mysql自增的步长:show session variables like 'auto_inc%';#基于会话级别set session auth_increment_increment=2 #修改会话级别的步长#基于全局级别的set global auth_increment_increment=2 #修改全局级别的步长(所有会话都生效)#!!!注意了注意了注意了!!!
If the value of auto_increment_offset is greater than that of auto_increment_increment, the value of auto_increment_offset is ignored. 
翻译:如果auto_increment_offset的值大于auto_increment_increment的值,则auto_increment_offset的值会被忽略 
比如:设置auto_increment_offset=3,auto_increment_increment=2mysql> set global auto_increment_increment=5;
Query OK, 0 rows affected (0.00 sec)mysql> set global auto_increment_offset=3;
Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'auto_incre%'; #需要退出重新登录
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+create table student(
id int primary key auto_increment,
name varchar(20),
sex enum('male','female') default 'male'
);mysql> insert into student(name) values('egon1'),('egon2'),('egon3');
mysql> select * from student;
+----+-------+------+
| id | name  | sex  |
+----+-------+------+
|  3 | egon1 | male |
|  8 | egon2 | male |
| 13 | egon3 | male |
+----+-------+------+
步长increment与起始偏移量offset:auto_increment_increment,auto_increment_offset

六 foreign key

一 快速理解foreign key

员工信息表有三个字段:工号  姓名  部门

公司有3个部门,但是有1个亿的员工,那意味着部门这个字段需要重复存储,部门名字越长,越浪费

解决方法:

我们完全可以定义一个部门表

然后让员工信息表关联该表,如何关联,即foreign key

#表类型必须是innodb存储引擎,且被关联的字段,即references指定的另外一个表的字段,必须保证唯一
create table department(
id int primary key,
name varchar(20) not null
)engine=innodb;#dpt_id外键,关联父表(department主键id),同步更新,同步删除
create table employee(
id int primary key,
name varchar(20) not null,
dpt_id int,
constraint fk_name foreign key(dpt_id)
references department(id)
on delete cascade
on update cascade 
)engine=innodb;#先往父表department中插入记录
insert into department values
(1,'欧德博爱技术有限事业部'),
(2,'艾利克斯人力资源部'),
(3,'销售部');#再往子表employee中插入记录
insert into employee values
(1,'egon',1),
(2,'alex1',2),
(3,'alex2',2),
(4,'alex3',2),
(5,'李坦克',3),
(6,'刘飞机',3),
(7,'张火箭',3),
(8,'林子弹',3),
(9,'加特林',3)
;#删父表department,子表employee中对应的记录跟着删
mysql> delete from department where id=3;
mysql> select * from employee;
+----+-------+--------+
| id | name  | dpt_id |
+----+-------+--------+
|  1 | egon  |      1 |
|  2 | alex1 |      2 |
|  3 | alex2 |      2 |
|  4 | alex3 |      2 |
+----+-------+--------+#更新父表department,子表employee中对应的记录跟着改
mysql> update department set id=22222 where id=2;
mysql> select * from employee;
+----+-------+--------+
| id | name  | dpt_id |
+----+-------+--------+
|  1 | egon  |      1 |
|  3 | alex2 |  22222 |
|  4 | alex3 |  22222 |
|  5 | alex1 |  22222 |
+----+-------+--------+
示范 

二 如何找出两张表之间的关系 

分析步骤:
#1、先站在左表的角度去找
是否左表的多条记录可以对应右表的一条记录,如果是,则证明左表的一个字段foreign key 右表一个字段(通常是id)#2、再站在右表的角度去找
是否右表的多条记录可以对应左表的一条记录,如果是,则证明右表的一个字段foreign key 左表一个字段(通常是id)#3、总结:
#多对一:
如果只有步骤1成立,则是左表多对一右表
如果只有步骤2成立,则是右表多对一左表#多对多
如果步骤1和2同时成立,则证明这两张表时一个双向的多对一,即多对多,需要定义一个这两张表的关系表来专门存放二者的关系#一对一:
如果1和2都不成立,而是左表的一条记录唯一对应右表的一条记录,反之亦然。这种情况很简单,就是在左表foreign key右表的基础上,将左表的外键字段设置成unique即可

三 建立表之间的关系

#一对多或称为多对一
三张表:出版社,作者信息,书一对多(或多对一):一个出版社可以出版多本书关联方式:foreign key
=====================多对一=====================
create table press(
id int primary key auto_increment,
name varchar(20)
);create table book(
id int primary key auto_increment,
name varchar(20),
press_id int not null,
foreign key(press_id) references press(id)
on delete cascade
on update cascade
);insert into press(name) values
('北京工业地雷出版社'),
('人民音乐不好听出版社'),
('知识产权没有用出版社')
;insert into book(name,press_id) values
('九阳神功',1),
('九阴真经',2),
('九阴白骨爪',2),
('独孤九剑',3),
('降龙十巴掌',2),
('葵花宝典',3)
;
View Code
一夫多妻制#妻子表的丈夫id外键到丈夫表的id
其他例子

  

#多对多
三张表:出版社,作者信息,书多对多:一个作者可以写多本书,一本书也可以有多个作者,双向的一对多,即多对多关联方式:foreign key+一张新的表
=====================多对多=====================
create table author(
id int primary key auto_increment,
name varchar(20)
);#这张表就存放作者表与书表的关系,即查询二者的关系查这表就可以了
create table author2book(
id int not null unique auto_increment,
author_id int not null,
book_id int not null,
constraint fk_author foreign key(author_id) references author(id)
on delete cascade
on update cascade,
constraint fk_book foreign key(book_id) references book(id)
on delete cascade
on update cascade,
primary key(author_id,book_id)
);#插入四个作者,id依次排开
insert into author(name) values('egon'),('alex'),('yuanhao'),('wpq');#每个作者与自己的代表作如下
1 egon: 1 九阳神功2 九阴真经3 九阴白骨爪4 独孤九剑5 降龙十巴掌6 葵花宝典2 alex: 1 九阳神功6 葵花宝典3 yuanhao:4 独孤九剑5 降龙十巴掌6 葵花宝典4 wpq:1 九阳神功insert into author2book(author_id,book_id) values
(1,1),
(1,2),
(1,3),
(1,4),
(1,5),
(1,6),
(2,1),
(2,6),
(3,4),
(3,5),
(3,6),
(4,1)
;
View Code
单张表:用户表+相亲关系表,相当于:用户表+相亲关系表+用户表
多张表:用户表+用户与主机关系表+主机表中间那一张存放关系的表,对外关联的字段可以联合唯一
其他例子

 

#一对一
两张表:学生表和客户表一对一:一个学生是一个客户,一个客户有可能变成一个学校,即一对一的关系关联方式:foreign key+unique
#一定是student来foreign key表customer,这样就保证了:
#1 学生一定是一个客户,
#2 客户不一定是学生,但有可能成为一个学生
create table customer(
id int primary key auto_increment,
name varchar(20) not null,
qq varchar(10) not null,
phone char(16) not null
);create table student(
id int primary key auto_increment,
class_name varchar(20) not null,
customer_id int unique, #该字段一定要是唯一的
foreign key(customer_id) references customer(id) #外键的字段一定要保证unique
on delete cascade
on update cascade
);#增加客户
insert into customer(name,qq,phone) values
('李飞机','31811231',13811341220),
('王大炮','123123123',15213146809),
('守榴弹','283818181',1867141331),
('吴坦克','283818181',1851143312),
('赢火箭','888818181',1861243314),
('战地雷','112312312',18811431230)
;#增加学生
insert into student(class_name,customer_id) values
('脱产3班',3),
('周末19期',4),
('周末19期',5)
;
View Code
例一:一个用户只有一个博客用户表:id  name1    egon2    alex3    wupeiqi博客表   fk+uniqueid url name_id1  xxxx   12  yyyy   33  zzz    2例二:一个管理员唯一对应一个用户用户表:id user  password1  egon    xxxx2  alex    yyyy管理员表:fk+uniqueid user_id password1   1      xxxxx2   2      yyyyy

转载于:https://www.cnblogs.com/fu-yong/p/8495003.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/398593.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

eclipse静态部署tomcat

转载于:https://www.cnblogs.com/sprinng/p/4223798.html

jvm fastdebug

背景 RednaxelaFX 写道agapple 写道还有一个问题,就是在验证一些逃逸优化时,有些jvm参数用不了,比如-XX:printInlining,-XX:printAssembly,jdk用的是1.6.11和jdk1.6.18-XX:PrintInlining在product build的Sun JDK上可以…

设计模式杂谈(一)——设计模式概述

文章目录1 设计模式概述1.1 软件设计模式的产生背景1.2 软件设计模式的概念1.3 设计模式的必要性1.4 设计模式分类1 设计模式概述 1.1 软件设计模式的产生背景 设计模式最初并不是在软件设计中,而是被用于建筑领域的设计中。 1977年美国著名建筑大师、加利福尼亚…

hmailserver批量添加用户

2019独角兽企业重金招聘Python工程师标准>>> 将内容复制到txt文件中后缀改为vbs 将用户名密码替换为自己的 脚本内容如下: Option Explicit On Error resume nextDim obBaseApp Dim objFSO Dim objTextFile Dim strNewAlias,iDim scrreport Dim failed Dim added fa…

云说的到底对不对,京东到底行不行?

摘要:马云吐槽京东被引爆以来,似乎就没人去关注马云说的对不对,有没有价值,大家更多的是在关注马云攻击了京东,京东回击了马云,马云被偷录了,再和人说话要去澡堂了…但,马云说的到底…

JS-随机生成的密码

randPassword(size) >{ //数组 let seed new Array(A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z, a,b,c,d,e,f,g,h,i,j,k,m,n,p,Q,r,s,t,u,v,w,x,y,z, 2,3,4,5,6,7,8,9 ) //数组长度 seedlength seed.length; let creatPassword[]; for (i0;i<size;i) { j Mat…

数据库杂谈(九)——事务管理

文章目录9 事务管理9.1 恢复机制9.2 事务和日志9.2.1 事务9.2.2 运行记录的结构9.2.2.1 活动事务表9.2.2.2 提交事务表9.2.2.3 日志9.2.3 提交规则和先记后写规则9.2.3.1 提交规则9.2.3.2 先记后写规则9.3 更新策略以及故障后的恢复9 事务管理 9.1 恢复机制 数据对一个单位是…

CSS邮件相关

转载于:https://blog.51cto.com/8465917/1758775

MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes

今天在用Navicat导入SQL文件时报错&#xff1a;MySql 错误 Err [Imp] 1153 - Got a packet bigger than max_allowed_packet bytes 查了一下&#xff0c;原来是MySQL默认读取执行的SQL文件最大为16M&#xff0c;我这个SQL文件260M&#xff0c;所以执行不过去 解决方法&#xff…

沙箱模式以及其使用到的IIFE

//沙箱//与外界隔绝的一个环境&#xff0c;外界无法修改该环境内任何信息&#xff0c;沙箱内的东西单独属于一个世界//360沙箱模式//将软件和操作系统进行隔离&#xff0c;以达到安全的目的//苹果手的app使用的就是沙箱模式去运行//隔离app的空间&#xff0c;每个app独立运行//…

C++从0到1的入门级教学(十)——类和对象

文章目录10 类和对象10.1 封装10.1.1 封装的意义10.1.2 struct和class的区别10.1.3 成员属性设置为私有10.2 对象的初始化和清理10.2.1 构造函数和析构函数10.2.2 构造函数的分类及调用10.2.3 关于拷贝构造函数调用时机10.2.4 构造函数调用规则10.2.5 深拷贝和浅拷贝10.2.6 初始…

js二级导航

js写二级导航要点 1.ul li 2.js获取元素 3.setInterval(function(),time); 代码如下 1 <style type"text/css">2 ul,li,body{margin:0;padding: 0;}3 #nav{width: 500px;margin: 10px auto;}4 ul li{list-style: none;}5 .clear{clear: both;}6 #n…

关于STM32的两个小问题的总结

一、最近做了一个关于自动转速测试仪的项目&#xff0c;其中用到了STM32的RTC时钟的功能&#xff0c;然后开始写代码&#xff0c;并且成功的跑了起来&#xff0c;于是将自己的板子放到桌面上让它跑了一个晚上看下误差&#xff0c;结果发现经过一晚上&#xff0c;误差并不是很大…

深度学习修炼(六)——神经网络分类问题

文章目录6 分类任务6.1 前置知识6.1.1 分类6.1.2 分类的网络6.2 动手6.2.1 读取数据6.2.2 functional模块6.2.3 继续搭建分类神经网络6.2.4 继续简化6.2.5 训练模型6.3 暂退法6.3.1 重新看待过拟合问题6.3.2 在稳健性中加入扰动6.3.3 暂退法实际的实现6.4 后话6 分类任务 在这…

修改NavigationBar的分根线颜色

[self.navigationController.navigationBar setShadowImage:[Static ColorToImage:[Static colorWithHexString:[UIColor red]]]]; Static 里的几个静态方法 (UIImage *)ColorToImage:(UIColor *)color{CGRect rectCGRectMake(0.0f, 0.0f, 1.0f, 1.0f);UIGraphicsBeginImageCo…

Java IO 之 InputStream源码(2)

Writer&#xff1a;李强强 一、InputStream InputStream是一个抽象类&#xff0c;即表示所有字节输入流实现类的基类。它的作用就是抽象地表示所有从不同数据源产生输入的类&#xff0c;例如常见的FileInputStream、FilterInputStream等。那些数据源呢&#xff1f;比如&#xf…

【CTSC2017】【BZOJ4903】吉夫特 卢卡斯定理 DP

题目描述 给你一个长度为\(n\)的数列\(a\)&#xff0c;求有多少个长度\(\geq 2\)的不上升子序列\(a_{b_1},a_{b_2},\ldots,a_{b_k}\)满足\[ \prod_{i2}^k\binom{a_{b_{i-1}}}{a_{b_i}}\mod 2>0 \]   答案对\({10}^97\)取模。 \(n\leq211985,a_i\leq 233333\) \(\forall i\…

深度学习修炼(七)——卷积神经网络

文章目录7 卷积神经网络7.1 卷积网络和传统网络的区别7.2 卷积7.2.1 卷积过程画大饼7.2.2 图像的不变性7.2.3 互相关运算*(补充)7.2.4 图像颜色通道*(补充)7.2.5 步幅7.2.6 多次卷积7.2.7 边缘填充7.2.8 特征图的大小7.2.9 卷积参数共享7.3 池化7.4 整体网络架构7.5 后话7 卷积…

Java并发编程:ThreadLocal

Java并发编程&#xff1a;深入剖析ThreadLocal ThreadLocal ThreadLocal之我见 Struts2中的设计模式----ThreadLocal模式 ThreadLocal ThreadLocal原理及其实际应用 ThreadLocal 转载于:https://www.cnblogs.com/a198720/articles/4229366.html

用递归形成树结构数据

定义一个树形实体 public class orgTrees{public orgTrees(){this.Children new List<orgTrees>();}public int Id { get; set; }public int FatherId { get; set; }public string Name { get; set; }public int Lever { get; set; }public bool HasChildren { get; se…