<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Cole</title>
  <description>Cole - Free as the wind.</description>
  <atom:link href="/rss.xml" rel="self" type="application/rss+xml"/>
  <link></link>
  <lastBuildDate>Tue, 04 May 2021 11:02:00 +0800</lastBuildDate>
  <pubDate>Tue, 04 May 2021 11:02:00 +0800</pubDate>
  <ttl>1800</ttl>


  <item>
    <title>值得一读的文章</title>
    <description>
&lt;h3 id=&quot;2017-年&quot;&gt;2017 年&lt;/h3&gt;

&lt;h4 id=&quot;4-月&quot;&gt;4 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2017-04-10
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://xiaopiu.com&quot;&gt;优雅高效的免费在线APP原型工具&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://next.36kr.com/posts/collections/1&quot;&gt;产品原型工具&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;1-月&quot;&gt;1 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2017-01-01
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/24856035?utm_medium=social&amp;amp;utm_source=wechat_session&quot;&gt;React 常用面试题目与分析&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2016-年&quot;&gt;2016 年&lt;/h3&gt;

&lt;h4 id=&quot;12月&quot;&gt;12月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-12-08
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.liaoxuefeng.com/article/001373894410719a19c79d040c84fd4a7492efc60081be1000&quot;&gt;创建git私有仓库&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-12-04
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/deebloo/things-you-can-do-in-a-web-worker&quot;&gt;things-you-can-do-in-a-web-worker&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;11月&quot;&gt;11月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-11-28
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://gold.xitu.io/post/583b10640ce463006ba2a71a&quot;&gt;实现图片懒加载(Lazyload)&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.kancloud.cn/kancloud/create-voting-app/63983&quot;&gt;使用React、Node.js、MongoDB、Socket.IO开发一个角色投票应用&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-27
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000007611188&quot;&gt;Web前端从入门菜鸟到实践老司机所需要的资料与指南合集&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-18
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.html5rocks.com/en/tutorials/workers/basics/&quot;&gt;The Basics of Web Workers&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.uisdc.com/frontend-quick-search-sheet&quot;&gt;前端丨超全面+最流行的「前端速查表」高清版大全&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-17
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://ghmagical.com/article/page/id/W7Rz2GACEO0t&quot;&gt;CSS3滤镜-Filter&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/xufei/blog/issues/38&quot;&gt;流动的数据，使用 RxJS 构造复杂单页应用的数据逻辑&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://my.oschina.net/qiangdada/blog/786981&quot;&gt;一入前端深似海，从此红尘是路人系列第八弹之浅析Vue组件开发&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://my.oschina.net/osccreate/blog/785004&quot;&gt;阿里巴巴前架构师 360 度无死角剖析微服务&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-15
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.zhihu.com/question/22572900&quot;&gt;Meta Programming&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;http://www.cnblogs.com/liuyanlong/archive/2013/05/27/3102161.html&quot;&gt;元编程之javascript&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;http://es6.ruanyifeng.com/#docs/proxy&quot;&gt;Proxy和Reflect&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;X系列
        &lt;ul&gt;
          &lt;li&gt;1 &lt;a href=&quot;https://blog.risingstack.com/writing-a-javascript-framework-project-structuring://blog.risingstack.com/writing-a-javascript-framework-project-structuring/&quot;&gt;项目结构（Project structuring）&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;2 [执行调度（Execution timing](https://blog.risingstack.com/writing-a-javascript-framework-execution-timing-beyond-settimeout/&lt;/li&gt;
          &lt;li&gt;3 &lt;a href=&quot;https://blog.risingstack.com/writing-a-javascript-framework-sandboxed-code-evaluation/&quot;&gt;沙箱求值（Sandboxed code evaluation）&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;4 &lt;a href=&quot;https://blog.risingstack.com/writing-a-javascript-framework-data-binding-dirty-checking/&quot;&gt;数据绑定简介&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;5 &lt;a href=&quot;http://www.zcfy.cc/article/writing-a-javascript-framework-data-binding-with-es6-proxies-risingstack-1655.html&quot;&gt;使用 ES6 Proxy 实现数据绑定&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;6 自定义元素&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;7 客户端路由&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-14
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.w3cplus.com/javascript/learn-rollup-js.html&quot;&gt;如何使用Rollup打包JavaScript&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-11-08
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://blog.oyanglul.us/javascript/clojure-core.async-essence-in-native-javascript.html&quot;&gt;Clojure 风格的 JavaScript 并发编程JS-CSP&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/21479556&quot;&gt;消息队列设计精要&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;10月&quot;&gt;10月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-10-15
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.jianshu.com/p/083cc66a11b0/comments/1323960#cool&quot;&gt;大前端工具集 * 聂微东&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://uptodate.frontendrescue.org/zh/&quot;&gt;如何跟上最前沿的前端开发&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-10-13
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/more-readable-javascript-without-variables-339.html&quot;&gt;抛弃变量，编写更加可读的JavaScript代码&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/ruanyf/document-style-guide&quot;&gt;中文技术文档的风格约定&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/digging-into-react-choosing-component-styles-656.html&quot;&gt;深入React：选择组件类型&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-10-11
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://projects.lukehaas.me/css-loaders/&quot;&gt;CSS加载 * Demon+CSS&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/understanding-the-css-modules-methodology-1329.html&quot;&gt;理解CSS模块化(CSS Module)&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/22782487&quot;&gt;在 2016 年学 JavaScript 是一种什么样的体验？&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://gold.xitu.io/entry/57fc9ea40bd1d00058d170f9/&quot;&gt;Google Interview University - 坚持完成这套学习手册，你就可以去 Google 面试了&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/w3c-vs-whatwg-html5-specs-differences-documented-1364.html&quot;&gt;W3C vs. WhatWG HTML5 标准 - 差异记录&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-10-10
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://mp.weixin.qq.com/s?__biz=MzA4ODgwNjk1MQ==&amp;amp;mid=2653788337&amp;amp;idx=1&amp;amp;sn=96f41ec3de2a622e7bb1746f744a1305&amp;amp;mpshare=1&amp;amp;scene=1&amp;amp;srcid=1010HdxRgU6IG22rGIB9Wene#rd&quot;&gt;API杂谈&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;9月&quot;&gt;9月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-09-28
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.aegeank.com/&quot;&gt;设计师是怎样炼成的&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-09-19
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/nieweidong/fetool&quot;&gt;大前端工具集 - 聂微东&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://zhuanlan.zhihu.com/p/22276837?refer=passer&quot;&gt;有哪些值得关注的技术博客（前端篇）&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-09-18
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/reactjs/react-router-tutorial&quot;&gt;React-Router Tutorial&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/ReactTraining/react-router/tree/master/docs&quot;&gt;React-Router Docs&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-09-13
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000004295639&quot;&gt;react 实现pure render的时候，bind(this)隐患&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://medium.com/@housecor/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56?swoff=true&quot;&gt;React Binding Patterns: 5 Approaches for Handling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000004290333&quot;&gt;react如何性能达到最大化(前传)，暨react为啥非得使用immutable.js&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000003810652&quot;&gt;传统 Ajax 已死，Fetch 永生&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-09-12
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/kenberkeley/redux-simple-tutorial&quot;&gt;Redux 简明教程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/kenberkeley/redux-simple-tutorial/blob/master/redux-advanced-tutorial.md&quot;&gt;Redux 进阶教程&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-09-11
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/the-one-thing-that-no-one-properly-explains-about-react-why-virtual-dom-hashnode-1211.html`&quot;&gt;React中一个没人能解释清楚的问题——为什么要使用Virtual DOM&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/react-createclass-versus-extends-react-component-toddmotto-620.html&quot;&gt;React.createClass versus extends React.Component&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.zcfy.cc/article/the-16-most-popular-react-links-so-far-in-2016-929.html&quot;&gt;2016最受欢迎的16个React应用&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;5月&quot;&gt;5月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-05-13
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://es6.ruanyifeng.com/&quot;&gt;ECMAScript 6入门&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2015/03/react.html&quot;&gt;React 入门教程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2016/02/react-testing-tutorial.html&quot;&gt;React 测试入门&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2016/01/flux.html&quot;&gt;Flux 架构入门教程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://abramstyle.com/title/&quot;&gt;React和Redux开发资源整理&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000004660725&quot;&gt;玩物圈前端技术栈总结（React+Redux）&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.alloyteam.com/2016/01/reactjs-best-practices-for-2016/&quot;&gt;React.js 2016 最佳实践&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.alloyteam.com/2016/04/reactjs2016-what-lies-ahead/&quot;&gt;2016React大会之React展望&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000004172052&quot;&gt;Webpack 使用&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2014/05/restful_api.html&quot;&gt;RESTful API 设计指南&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-月-1&quot;&gt;4 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-04-02
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2012/06/sass.html&quot;&gt;SASS用法指南&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://j4n.co/blog/Creating-your-own-css-grid-system&quot;&gt;Creating-your-own-css-grid-system&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-月&quot;&gt;2 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2016-02-24
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://velocity.oreilly.com.cn/2015/index.php?func=session&amp;amp;id=8&quot;&gt;淘宝全站HTTPS实践&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://iyaozhen.com/nginx-https-conf.html&quot;&gt;Nginx HTTPS 配置实践&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://mozilla.github.io/server-side-tls/ssl-config-generator/&quot;&gt;Nginx HTTPS 配置自动生成&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-02-13
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.textarea.com/zhicheng/fenxiang-yige-https-a-di-nginx-peizhi-320/&quot;&gt;分享一个 HTTPS A+ 的 nginx 配置&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-02-08
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://iove86.sinaapp.com/ionic/ubuntu14-04-install-ionic-framework.html&quot;&gt;Ubuntu14.04安装ionic FrameWork&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://segmentfault.com/a/1190000003809277&quot;&gt;Ubuntu 15.04开发Ionic之环境配置&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2016-02-01
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://linux.cn/article-6871-1.html&quot;&gt;介绍一些适用于 Web 开发者的 Atom 编辑器插件&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.webrube.com/markdown-remarkjs-web_rube/3585&quot;&gt;Remarkjs: 使用 Markdown 做幻灯片&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.webrube.com/markdown-web_rube/4543&quot;&gt;10个免费的在线Markdown编辑器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.webrube.com/markdown-javascript-web_rube/6589&quot;&gt;简易Markdownd编辑器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.jianshu.com/p/09a3bbb8b362&quot;&gt;几个秒杀PPT的高（zhe）大(teng)上(ren)的幻灯工具&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2015-年&quot;&gt;2015 年&lt;/h3&gt;

&lt;h4 id=&quot;10-月&quot;&gt;10 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-10-20
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://python.jobbole.com/82423/&quot;&gt;用 Python 从零开始写一个简单的解释器&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-10-10
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.barretlee.com/blog/2015/10/05/how-to-build-a-https-server/&quot;&gt;HTTPS证书生成原理和部署细节&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://ljinkai.github.io/2015/08/13/http-cache/&quot;&gt;HTTP 缓存&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.2liang.me/archives/257&quot;&gt;八大排序算法的Python实现&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://liberize.me/tech/http-protocol.html&quot;&gt;HTTP 协议详解&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;9-月&quot;&gt;9 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-09-13
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/wanglin_lin/article/details/48165447&quot;&gt;adb 常用命令&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://top.jobbole.com/24707/&quot;&gt;Android 逆向工程工具集&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-09-12
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://fakefish.github.io/react-webpack-cookbook/index.html&quot;&gt;React Webpack Cookbook&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.oyanglul.us/javascript/understand-prototype.html&quot;&gt;理解JavaScript的原型链和继承&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html&quot;&gt;Flex布局&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-09-07
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/90364/&quot;&gt;这篇文章可以帮你掌握命令行的艺术&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;如果你使用Linux, 这篇文章必读&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-09-05
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.jonathan-petitcolas.com/2015/05/15/howto-setup-webpack-on-es6-react-application-with-sass.html&quot;&gt;How-to setup Webpack on an ES6 React Application with SASS?&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://www.python.org/dev/peps/&quot;&gt;Python Enhancement Proposals&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;强烈建议阅读，包含原理与事件&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;8-月&quot;&gt;8 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-08-31
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://tool.lu/&quot;&gt;Online Tools&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/88152/&quot;&gt;一起来写个简单的解释器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.allaboutcircuits.com/technical-articles/fsk-explained-with-python/&quot;&gt;FSK Explained with Python&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://domeide.github.io/&quot;&gt;Docker meets the IDE!&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-08-02
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://cokebar.info/archives/948&quot;&gt;Shadowsocks + Redsocks 实现 OpenWRT 路由器自动翻墙&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;7-月&quot;&gt;7 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-07-05
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/&quot;&gt;阮一峰&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2011/03/url_hash.html&quot;&gt;URL的井号&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2015/05/command-line-with-node.html&quot;&gt;Node.js 命令行程序开发教程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ruanyifeng.com/blog/2015/05/require.html&quot;&gt;require() 源码解读&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000&quot;&gt;JavaScript 教程 by 廖雪峰&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;6-月&quot;&gt;6 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-06-19
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.cnblogs.com/wupeiqi/p/4375445.html&quot;&gt;第一篇：白话tornado源码之一个脚本引发的血案&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-06-20
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://nginx.com/blog/thread-pools-boost-performance-9x/&quot;&gt;Nginx线程池，提升9被性能！&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-06-23
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/87509/&quot;&gt;如何生成每秒百万级别的 HTTP 请求？&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/87531/&quot;&gt;为最佳性能调优 Nginx&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/87503/&quot;&gt;用 LVS 搭建一个负载均衡集群&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://python.jobbole.com/81593/&quot;&gt;用 Python 和 OpenCV 检测和跟踪运动对象&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-06-24
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://top.jobbole.com/4866/&quot;&gt;Github干货系列：Python 免费资源集合&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;5-月&quot;&gt;5 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-05-01
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ido321.com/1545.html&quot;&gt;【译】编写更好的CSS必备的40个工具&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-05-21
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://cenalulu.github.io/linux/all-vim-cheatsheat/&quot;&gt;史上最全Vim快捷键键位图 – 入门到进阶&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://top.jobbole.com/21548/&quot;&gt;Sqlite全面学习系列&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://lifeofzjs.com/blog/2015/05/16/how-to-write-a-server/&quot;&gt;如何写一个Web服务器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://segmentfault.com/a/1190000002783199&quot;&gt;15个学习 AngularJS 最好的网站&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-月-2&quot;&gt;4 月&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;2015-04-11 &lt;a href=&quot;http://arccode.net/2015/04/08/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%AE%8C%E5%85%A8%E5%88%86%E7%A6%BB%E5%88%9D%E6%8E%A2/&quot;&gt;前后端完全分离初探&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;2015-04-12:
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.drbunsen.org/the-text-triumvirate/&quot;&gt;zsh, tmux和vim:文本三剑客&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ido321.com/1520.html&quot;&gt;JavaScript最全编码规范&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-04-18:
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/&quot;&gt;Gulp入门教程&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.html-js.com/article/Nimojs--frontend-development-1&quot;&gt;Gulp入门指南–比较全&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.gulpjs.com.cn/&quot;&gt;Gulp中文官网&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.gulpjs.com/&quot;&gt;Gulp官网&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://javascript.ruanyifeng.com/nodejs/npm.html&quot;&gt;npm模块管理器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://xdsnet.gitbooks.io/angular-phonecat-book-zhcn/content/index.html&quot;&gt;AngularJS 入门教程&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2015-04-19 &lt;a href=&quot;http://yeasy.gitbooks.io/docker_practice/content/&quot;&gt;Docker —— 从入门到实践&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;2015-04-22 &lt;a href=&quot;http://www.qianduan.net/zen-coding-a-new-way-to-write-html-code/&quot;&gt;Zen Coding:一种快速编写HTML/CSS代码的方法&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;2015-04-29
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ido321.com/1543.html&quot;&gt;【译】JavaScript：40+基本的Web开发工具&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/yanbober/article/details/45307739&quot;&gt;android-async-http框架库源码走读&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/yanbober/article/details/45306483&quot;&gt;Android Studio入门到精通&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html&quot;&gt;git-flow 备忘清单&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2020/12/31/excellent-programming-essays-all.html</link>
    <guid>/2020/12/31/excellent-programming-essays-all</guid>
    <pubDate>Thu, 31 Dec 2020 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>正确掌握React 生命周期(Lifecycle)</title>
    <description>
&lt;h2 id=&quot;前言&quot;&gt;前言&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;首先, 当面对一些问题:
    &lt;ul&gt;
      &lt;li&gt;1 React 用了这么久，经常遇到的问题是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState&lt;/code&gt;在这里写合适吗？&lt;/li&gt;
      &lt;li&gt;2 为什么&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState&lt;/code&gt;写在这里造成了重复渲染多次？&lt;/li&gt;
      &lt;li&gt;3 为什么你的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState&lt;/code&gt;用的这么乱?&lt;/li&gt;
      &lt;li&gt;4 组件传入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;是更新呢？重新挂载呢？还是怎样？&lt;/li&gt;
      &lt;li&gt;5 …&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;其次, 生命周期可以看到整个Component的运行过程, 在coding的时候很自然的找好他们的位置, 合作起来就会方便多了，这里极力推荐airbnb的react coding 规范.&lt;/li&gt;
  &lt;li&gt;所以整理了这篇文章。如果错误，欢迎指正。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;一-生命周期的8个方法&quot;&gt;一 生命周期的8个方法&lt;/h3&gt;

&lt;h4 id=&quot;1-componentwillmount&quot;&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillMount()&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render()&lt;/code&gt;方法之前&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;1 因为componentWillMount是在render之前执行，所以在这个方法中&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState&lt;/code&gt;不会发生重新渲染(re-render);&lt;/li&gt;
      &lt;li&gt;2 这是服务端渲染(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server render&lt;/code&gt;)中唯一调用的钩子(hook);&lt;/li&gt;
      &lt;li&gt;3 通常情况下，推荐用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;constructor()&lt;/code&gt;方法代替;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-render&quot;&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render()&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;1 在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillMount()&lt;/code&gt;方法之后&lt;/li&gt;
      &lt;li&gt;2 在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceive(nextProps, nextState)&lt;/code&gt;方法之后&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;==&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-componentdidmount&quot;&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentDidMount()&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render()&lt;/code&gt;方法之后&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;1 这个方法会在render()之后立即执行；&lt;/li&gt;
      &lt;li&gt;2 这里可以对DOM进行操作，这个函数之后ref变成实际的DOM(@TODO 表述可能不清晰);&lt;/li&gt;
      &lt;li&gt;3 这里可以加载服务器数据，并且如果使用了redux之类的数据服务，这里可以出发加载服务器数据的action;&lt;/li&gt;
      &lt;li&gt;4 这里可以使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState()&lt;/code&gt;方法触发&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;重新渲染(re-render)&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-componentwillreceivepropsnextprops&quot;&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceiveProps(nextProps)&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在已经挂在的组件(mounted component)接收到新props时触发;&lt;/li&gt;
      &lt;li&gt;简单的说是在除了第一次生命周期(componentWillMount -&amp;gt; render -&amp;gt; componentDidMount)之后的生命周期中出发;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;1 如果你需要在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;发生变化(或者说新传入的props)来更新&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;，你可能需要比较&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.props&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextProps&lt;/code&gt;, 然后使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState()&lt;/code&gt;方法来改变&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.state&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;注意
    &lt;ul&gt;
      &lt;li&gt;1 React可能会在porps传入时即使没有发生改变的时候也发生重新渲染, 所以如果你想自己处理改变，请确保比较props当前值和下一次值; 这可能造成组件重新渲染;&lt;/li&gt;
      &lt;li&gt;2 如果你只是调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState()&lt;/code&gt;而不是从外部传入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;, 那么不会触发&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceiveProps(nextProps)&lt;/code&gt;函数；这就意味着: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState()&lt;/code&gt;方法不会触发&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceiveProps()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;的改变或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;没有改变才会触发这个方法;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;5-shouldcomponentupdatenextprops-nextstate&quot;&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在接收到新&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;时，或者说在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceiveProps(nextProps)&lt;/code&gt;后触发&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;在接收新的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;时确定是否发生重新渲染，默认情况返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;，表示会发生重新渲染&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;注意
    &lt;ul&gt;
      &lt;li&gt;1 这个方法在首次渲染时或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forceUpdate()&lt;/code&gt;时不会触发;&lt;/li&gt;
      &lt;li&gt;2 这个方法如果返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;, 那么&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;发生改变的时候会阻止子组件发生重新渲染;&lt;/li&gt;
      &lt;li&gt;3 目前，如果&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;, 那么&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillUpdate(nextProps, nextState)&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentDidUpdate()&lt;/code&gt;都不会被触发;&lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Take care&lt;/code&gt;: 在未来，React可能把&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate()&lt;/code&gt;当做一个小提示(hint)而不是一个指令(strict directive)，并且它返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;仍然可能触发组件重新渲染(re-render);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Good Idea
    &lt;ul&gt;
      &lt;li&gt;在React 15.3以后, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;React.PureComponent&lt;/code&gt;已经支持使用，个人推荐，它代替了(或者说合并了)&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pure-render-mixin&lt;/code&gt;，实现了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shallowCompare()&lt;/code&gt;。&lt;a href=&quot;http://www.zcfy.cc/article/why-and-how-to-use-purecomponent-in-react-js-60devs-2344.html&quot;&gt;扩展阅读&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;6-componentwillupdatenextprops-nextstate&quot;&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillUpdate(nextProps, nextState)&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;发生改变或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;触发后, 在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;render()&lt;/code&gt;之前&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;1 这个方法在组件初始化时不会被调用;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;注意
    &lt;ul&gt;
      &lt;li&gt;1 &lt;strong&gt;千万不要在这个函数中调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState()&lt;/code&gt;方法.&lt;/strong&gt;;&lt;/li&gt;
      &lt;li&gt;2 如果确实需要响应&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;的改变，那么你可以在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillReceiveProps(nextProps)&lt;/code&gt;中做响应操作;&lt;/li&gt;
      &lt;li&gt;3 如果&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;，那么&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillUpdate()&lt;/code&gt;不会被触发;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;7-componentdidupdateprevprops-prevstate&quot;&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentDidUpdate(prevProps, prevState)&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在发生更新或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillUpdate(nextProps, nextState)&lt;/code&gt;后&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;1 该方法不会再组件初始化时触发;&lt;/li&gt;
      &lt;li&gt;2 使用这个方法可以对组件中的DOM进行操作;&lt;/li&gt;
      &lt;li&gt;3 只要你比较了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.props&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextProps&lt;/code&gt;，你想要发出网络请求(nextwork requests)时就可以发出, 当然你也可以不发出网络请求;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;注意
    &lt;ul&gt;
      &lt;li&gt;如果&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shouldComponentUpdate(nextProps, nextState)&lt;/code&gt;返回&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;, 那么&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentDidUpdate(prevProps, prevState)&lt;/code&gt;不会被触发;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;8-componentwillunmount&quot;&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentWillUnmount()&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;执行场景
    &lt;ul&gt;
      &lt;li&gt;在组件卸载(unmounted)或销毁(destroyed)之前&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;这个方法可以让你处理一些必要的清理操作，比如无效的timers、interval，或者取消网络请求，或者清理任何在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;componentDidMount()&lt;/code&gt;中创建的DOM元素(elements);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;相关-setstateobjectfunction&quot;&gt;相关 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setState(Object/Function)&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;解释
    &lt;ul&gt;
      &lt;li&gt;通过事件(event handlers)或服务请求回调(server request callbacks), 触发UI更新(re-render);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;参数
    &lt;ul&gt;
      &lt;li&gt;1 可以是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object&lt;/code&gt;类型, 这时是异步的setState, 同时接收一个在state发生改变之后的回调, 如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState(Object, callback)&lt;/code&gt;, 其中callback可以是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;() =&amp;gt; { ... this.state ... }&lt;/code&gt;;&lt;/li&gt;
      &lt;li&gt;2 可以是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Function&lt;/code&gt;类型, 这时是同步的setState, 例如: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(prevState, prevProps) =&amp;gt; nextState&lt;/code&gt;, 同步存在一定效率问题(不理解), 但是它有一个好处就是支持&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Immutable&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二-两种生命周期&quot;&gt;二 两种生命周期&lt;/h3&gt;

&lt;h4 id=&quot;1-组件初始化&quot;&gt;1 组件初始化&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;原因
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;组件第一次建立&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;触发
    &lt;ul&gt;
      &lt;li&gt;componentWillMount -&amp;gt; render -&amp;gt; componentDidMount&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2-组件更新--props-change&quot;&gt;2 组件更新 – props change&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;原因
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;props&lt;/code&gt;发生改变&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;触发
    &lt;ul&gt;
      &lt;li&gt;componentWillReceiveProps -&amp;gt; shouldComponentUpdate -&amp;gt; componentWillUpdate -&amp;gt; componentDidUpdate&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3-组件更新--state-change&quot;&gt;3 组件更新 – state change&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;原因
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;this.setState()&lt;/code&gt;使&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;state&lt;/code&gt;发生改变&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;触发
    &lt;ul&gt;
      &lt;li&gt;shoudlComponentUpdate -&amp;gt; componentWillUpdate -&amp;gt; componentDidUpdate&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;4-组件卸载或销毁&quot;&gt;4 组件卸载或销毁&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;原因
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;组件卸载或销毁&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;触发
    &lt;ul&gt;
      &lt;li&gt;componentWillUnmount&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三-相关链接&quot;&gt;三 相关链接&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;a href=&quot;https://facebook.github.io/react/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class&quot;&gt;Facebook: State and Lifecycle of React&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;2 &lt;a href=&quot;http://www.zcfy.cc/article/why-and-how-to-use-purecomponent-in-react-js-60devs-2344.html&quot;&gt;在React.js中使用PureComponent的重要性和使用方式&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;3 &lt;a href=&quot;https://zhuanlan.zhihu.com/p/24856035?utm_medium=social&amp;amp;utm_source=wechat_session&quot;&gt;React 常用面试题目与分析&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;4 &lt;a href=&quot;https://fraserxu.me/2014/08/31/react-component-lifecycle/&quot;&gt;React入门教程 - 组件生命周期&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2017/01/17/understand-react-lifecycle.html</link>
    <guid>/2017/01/17/understand-react-lifecycle</guid>
    <pubDate>Tue, 17 Jan 2017 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>对前后端API设计的一点思考 -- Status Code</title>
    <description>
&lt;h3 id=&quot;一问题&quot;&gt;一、问题&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;首先，扯点大方向: API规范
    &lt;ul&gt;
      &lt;li&gt;目前市面是规范比较多，大家都有自己的想法，这没错，但是遇到团队协作或者前后端交接的事件，各自遵循自己的规范可不见得是什么好事啊;&lt;/li&gt;
      &lt;li&gt;这个问题不仅是前后端对接，甚至是前端团队成员协调，都会出现一些不认同，或者要花很多的沟通成本，这个时间浪费是没有必要的，这是初衷。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;其次, 格式问题:
    &lt;ul&gt;
      &lt;li&gt;接口数据返回的格式，包括: Header + Data
        &lt;ul&gt;
          &lt;li&gt;Header: 就是常见的响应头(Response headers);&lt;/li&gt;
          &lt;li&gt;Data: 就是返回的接口数据，或者特定的业务数据;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二response-情况分类2种&quot;&gt;二、Response 情况分类(2种)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;正确&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;响应头(Response header)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt;: 200 或者 20x (&lt;a href=&quot;https://www.w3ctech.com/topic/854&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;这时: fetch的res.ok是正确的&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;主体(Body)
        &lt;ul&gt;
          &lt;li&gt;返回正确JSON数据 (关于正确数据格式规范, 单独文章讲讲我的理解…)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;出错&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;响应头(Response header)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt;: 400 或 40x 或 50x&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;主体(Body)
        &lt;ul&gt;
          &lt;li&gt;包含两个字段: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{ errcode: Number, errmsg: String }&lt;/code&gt;, 其中&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;errcode&lt;/code&gt;: 为开发/业务错误码，不是Http Status Code, 一般为Http Status扩展码, 比如 Http Status 为 400 时, errcode 为 400001等&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;errmsg&lt;/code&gt; : 为开发/业务错误信息, 提示开发者或者提示用户&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三例子-fetch&quot;&gt;三、例子: Fetch&lt;/h3&gt;

&lt;div class=&quot;language-javascript 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;// 以React + Redux + Redux-thunk 中使用fetch为例&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;options&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;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&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;nx&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 接下来会说说为什么用ok, 而不是用status&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;json&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;span class=&quot;nx&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&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;if&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;nx&quot;&gt;ok&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;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_err&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;nb&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;errmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;_err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;errcode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;errcode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_err&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;nx&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;FETCH_DATA_SUCCESS&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&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;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;err&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;nx&quot;&gt;dispatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;FETCH_ERROR&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;payload&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;na&quot;&gt;errcode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;errmsg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toString&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;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;你会发现上面有两个变量: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ok&lt;/code&gt;, 其中&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;status&lt;/code&gt;表示具体的Http Status Code, 而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ok&lt;/code&gt;在Http Status Code为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;20x&lt;/code&gt;的时候是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四参考&quot;&gt;四、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.w3ctech.com/topic/854&quot;&gt;这个API很“迷人”——(新的Fetch API)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://bubkoo.com/2015/05/08/introduction-to-fetch/&quot;&gt;fetch API 简介&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/camsong/blog/issues/2&quot;&gt;传统 Ajax 已死，Fetch 永生&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2017/01/17/think-more-about-api-design.html</link>
    <guid>/2017/01/17/think-more-about-api-design</guid>
    <pubDate>Tue, 17 Jan 2017 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>React - PropTypes and DefaultProps</title>
    <description>
&lt;h3 id=&quot;一-propstypes-取值&quot;&gt;一 PropsTypes 取值&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 常用
    &lt;ul&gt;
      &lt;li&gt;1 字符串: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.string&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;2 数字: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.number&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;3 函数: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.func&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;4 数组: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.array&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 对象: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.object&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;6 &lt;strong&gt;React元素&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.element&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;7 &lt;strong&gt;节点&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.node&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;8 &lt;strong&gt;任意&lt;/strong&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.any&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 高级
    &lt;ul&gt;
      &lt;li&gt;1 指定类型: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.instanceOf(TYPE)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;2 限定enum值之一: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.oneOf([&apos;foo&apos;, &apos;bar&apos;])&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;3 限定enum类型之一: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.oneOfType([PropTypes.string, PropTypes.array])&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;4 指定数组值的类型: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.arrayOf(PropTypes.object)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 指定对象的属性类型: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.objectOf(PropTypes.string)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;6 指定特定的对象类型: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.shape({id: PropTypes.string, color: PropTypes.string})&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二-限定proptypes类型&quot;&gt;二 限定PropTypes类型&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.string.isRequired&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PropTypes.shape({ id: PropTypes.string.isRequired, color: PropTypes.string}).isRequired&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三-自定义类型&quot;&gt;三 自定义类型&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 自定义格式(当不符合的时候，应该适当提示或者报错)
customPropTypes: function (props, propName, component) {
  if (!/^[0-9]/.test(props[propName])) {
    return new Error(&apos;Validation failed&apos;);
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四-defaultprops-es2016&quot;&gt;四 defaultProps (ES2016)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;设置默认值，但注意使用默认值时, isRequired属性将失效&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五-案例&quot;&gt;五 案例&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import React, {Component, PropTypes} from &apos;react&apos;;

export default class Table {
  static propTypes = {
    title: PropTypes.string,
    header: PropTypes.arrayOf(PropTypes.string),
    body: PropTypes.arrayOf(
      PropTypes.shape({
        id: PropType.oneOfType([PropType.string, PropTypes.number]).isRequired,
        name: PropTypes.string,
        value: PropTypes.number
      }).isRequired
    ),
  };

  render () {
    ....  
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2016/12/03/react-proptypes-and-defaultprops.html</link>
    <guid>/2016/12/03/react-proptypes-and-defaultprops</guid>
    <pubDate>Sat, 03 Dec 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>SVG 入门和进阶</title>
    <description>
&lt;h2 id=&quot;svg基础&quot;&gt;SVG基础&lt;/h2&gt;

&lt;h3 id=&quot;一定义与优势-svg---scalable-vector-graphics&quot;&gt;一、定义与优势: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVG&lt;/code&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Scalable Vector Graphics&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;定义
    &lt;ul&gt;
      &lt;li&gt;1 可伸缩矢量图&lt;/li&gt;
      &lt;li&gt;2 使用XML格式定义图形&lt;/li&gt;
      &lt;li&gt;3 W3C的标准&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;优势
    &lt;ul&gt;
      &lt;li&gt;容易修改&lt;/li&gt;
      &lt;li&gt;比JPEG和GIF小，可读性强&lt;/li&gt;
      &lt;li&gt;矢量，即在任何分辨率下都不会模糊，高清&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基本使用&quot;&gt;二、基本使用&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 1. 文件后缀必须为.svg
// 2. 栗子: 矩形
&amp;lt;svg width=&quot;100%&quot; height=&quot;100%&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&amp;gt;
  &amp;lt;rect width=&quot;100&quot; height=&quot;100&quot; stroke=&quot;black&quot; stroke-wdith=&quot;2&quot; fill=&quot;red&quot; /&amp;gt;
&amp;lt;/svg&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三基础shape和style属性&quot;&gt;三、基础Shape和Style属性&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;1 Common Style Attributes – &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;既可以独立使用(fill=&quot;red&quot;)，也可以写在style里(style=&quot;fill:red&quot;)&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; – 到浏览器左侧距离(Default: 0, 指0px)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt; – 到浏览器右侧距离(Default: 0)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;width&lt;/code&gt; – 宽&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;height&lt;/code&gt; – 高&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fill&lt;/code&gt; – 填充颜色(Default: #000)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fill-opacity&lt;/code&gt; – 填充颜色透明度(取值和opacity一样)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stroke&lt;/code&gt; – 线颜色(Default: #FFF)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stroke-width&lt;/code&gt; – 线宽(Default: 1, 主要这里1指1px, 大部分都是这样)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stroke-opacity&lt;/code&gt; – 线透明度&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt; – 滤镜(Advanced)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;style&lt;/code&gt; – 同DOM的style, 并且可以将以上搜集在一起&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 Shape 与 特有属性
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rect&lt;/code&gt; – 矩形
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rx&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ry&lt;/code&gt;: 使矩形产生圆角&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;circle&lt;/code&gt; – 圆形
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cx&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cy&lt;/code&gt;: 圆心坐标&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;: 圆半径&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ellipse&lt;/code&gt; – 椭圆
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cx&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cy&lt;/code&gt;: 椭圆圆心坐标&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rx&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ry&lt;/code&gt;: 椭圆水平、垂直半径&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;line&lt;/code&gt; – 线
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x1&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y1&lt;/code&gt;: 起点坐标&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x2&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y2&lt;/code&gt;: 终点坐标&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;polyline&lt;/code&gt; – 折线&lt;/li&gt;
      &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ploygon&lt;/code&gt; – 多边形(不少于三条边的图形)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;points&lt;/code&gt;: 点集, 其中点(x,y)与点(m,n)之间用空格分隔&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;path&lt;/code&gt; – 路径
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt;: 数据(data), 一下是数据中的指令
            &lt;ul&gt;
              &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;M&lt;/code&gt; – moveTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;M x,y&lt;/code&gt;): 将画笔移动到指定的坐标位置&lt;/li&gt;
              &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt; – lineTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L x,y&lt;/code&gt;): 画直线到指定的坐标位置&lt;/li&gt;
              &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;H&lt;/code&gt; – Horizontal lineTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;H X&lt;/code&gt;): 画水平线到指定的X坐标位置&lt;/li&gt;
              &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;V&lt;/code&gt; – Vertical lineTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;V Y&lt;/code&gt;): 画垂直线到指定的Y坐标位置&lt;/li&gt;
              &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C&lt;/code&gt; – curveTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C X1,Y1,X2,Y2,ENDX,ENDY&lt;/code&gt;): 三次Belzier曲线&lt;/li&gt;
              &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S&lt;/code&gt; – smooth curveTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;S X2,Y2,ENDX,ENDY&lt;/code&gt;)&lt;/li&gt;
              &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Q&lt;/code&gt; – qiadratic Belzier curve(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Q X,Y,ENDX,ENDY&lt;/code&gt;): 二次Belzier曲线&lt;/li&gt;
              &lt;li&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt; – smootg quadratic Belzier curveTo(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T ENDX,ENDY&lt;/code&gt;): 映射&lt;/li&gt;
              &lt;li&gt;9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; – elliptical Arc(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A RX,RY,XRotation,Flag1,Flag2,X,Y&lt;/code&gt;): 弧线&lt;/li&gt;
              &lt;li&gt;10 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Z&lt;/code&gt; – closepath: 关闭路径&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;// 栗子: Path&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  内容: 首先移动到点(0,0) -- moveTo(0,0)，然后画线到(0, 100) -- lineTo(0, 100), stroke颜色是red&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  注意: stroke的颜色默认为#fff，不手动赋值会是白色一片&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;svg&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;http://www.w3c.org/2000/svg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt; 
    &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;M0,0L0,100&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;stroke:red&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三滤镜filter--in-defs&quot;&gt;三、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;滤镜(Filter)&lt;/code&gt; – in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 效果分类
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feBlend&lt;/code&gt; – 与图像结合的滤镜&lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feColorMatrix&lt;/code&gt; – 用于彩色滤光片转换&lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feComponentTransfer&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feComposite&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feConvolveMatrix&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feDiffuseLighting&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feDisplacementMap&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feFlood&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feGaussianBlur&lt;/code&gt; – &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;高斯模糊&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;in&lt;/code&gt;: SourceGraphic定义了由整个图像创建效果&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stdDeviation&lt;/code&gt;: 定义模糊程度&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;10 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feImage&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;11 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feMerge&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;12 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feMorphology&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;13 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feOffset&lt;/code&gt; – 过来阴影&lt;/li&gt;
      &lt;li&gt;14 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feSpecularLighting&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;15 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feTile&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;16 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feTurbulence&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;17 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feDistantLight&lt;/code&gt; – 过滤照明&lt;/li&gt;
      &lt;li&gt;18 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fePointLight&lt;/code&gt; – 过滤照明&lt;/li&gt;
      &lt;li&gt;19 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;feSpotLight&lt;/code&gt; – 过滤照明&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 定义
    &lt;ul&gt;
      &lt;li&gt;必须在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;标签中定义, defs是definitions的缩写&lt;/li&gt;
      &lt;li&gt;必须指定需要滤镜的图像&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id&lt;/code&gt;, 其中在图形中定义id: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter=url(#ID)&lt;/code&gt;, 如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;rect ... filter=&quot;url(#ID)&quot;&amp;gt;&lt;/code&gt; 或者 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;rect ... style=&quot;...;filter=url(#ID)&quot;&amp;gt;&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;//  内容: &amp;lt;defs&amp;gt;中定义&amp;lt;filter&amp;gt;, id为Gaussian_Blur, 并在图形中使用style=&quot;filter:url(#Gaussian_blur)&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;svg&lt;/span&gt; 
  &lt;span class=&quot;nx&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;http://www.w3.org/2000/svg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;width:100%;height:100%;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
  
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;defs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Gaussian_Blur&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;feGaussianBlur&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;SourceGraphic&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stdDeviation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/filter&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/defs&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ellipse&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;150&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;rx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;70&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;fill:#ff0; stroke:#000; stroke-width:2, filter:url(#Gaussian_Blur);&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四渐变gradient--in-defs&quot;&gt;四、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;渐变(Gradient)&lt;/code&gt; – in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 定义
    &lt;ul&gt;
      &lt;li&gt;一种颜色到另一种颜色平滑过渡&lt;/li&gt;
      &lt;li&gt;另，可以把多个过渡颜色应用到同一个元素上&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 分类
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;线性渐变(linearGradient)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;类型
            &lt;ul&gt;
              &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;水平渐变&lt;/code&gt;: Y同, X不&lt;/li&gt;
              &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;垂直渐变&lt;/code&gt;: X同, Y不&lt;/li&gt;
              &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;斜渐变&lt;/code&gt;: X、Y均不同&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;属性
            &lt;ul&gt;
              &lt;li&gt;id: 需要渐变的图形&lt;/li&gt;
              &lt;li&gt;x1 + y1: 起点(百分比)&lt;/li&gt;
              &lt;li&gt;x2 + y2: 终点(百分比)&lt;/li&gt;
              &lt;li&gt;stop – 子元素，其属性: offset, stop-opacity, stop-color, style等&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;放射渐变(radialGradient)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;cx + cy + r: 外圆渐变的范围(cx+cy: 可百分比或者像素)和半径(r)&lt;/li&gt;
          &lt;li&gt;fx + fy: 内圆颜色渐变的范围(可百分比或者像素)&lt;/li&gt;
          &lt;li&gt;stop: 颜色标签&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;// One 线性渐变 -- Path矩形垂直渐变&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Two 放射渐变 -- Path矩形放射渐变&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;svg&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;xmlns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;http://www.w3.org/2000/svg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1.1&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt; 
    &lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;M0,0L0,100L100,100L100,0Z&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; 
    &lt;span class=&quot;nx&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;stroke:red;fill:url(#linearG)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;defs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;linearGradient&lt;/span&gt; 
      &lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;linearG&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;x1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;x2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;100%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;y2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;100%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;yellow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/linearGradient&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;  
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;radialGradient&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;radialG&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;cx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;50%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;50%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;50%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;fx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;50%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;50%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;0%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;100%&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;yellow&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/radialGradient&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/defs&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五svg图形组g&quot;&gt;五、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SVG图形组&amp;lt;g&amp;gt;&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;定义:
    &lt;ul&gt;
      &lt;li&gt;将图形分组，便于统一操作&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;功能
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;g&amp;gt;&lt;/code&gt;标签用来创建分组&lt;/li&gt;
      &lt;li&gt;属性继承&lt;/li&gt;
      &lt;li&gt;transform属性定义坐标变换&lt;/li&gt;
      &lt;li&gt;可以嵌套&lt;/li&gt;
      &lt;li&gt;元素属性可以在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;g&amp;gt;&lt;/code&gt;中定义一次就行, 如fill,stroke,stroke-wdith等&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;注意
    &lt;ul&gt;
      &lt;li&gt;可以在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;中定义&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;g&amp;gt;&lt;/code&gt;，并赋予id, 在其他&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;g&amp;gt;&lt;/code&gt;或者坐标中用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;use xlink=&quot;#ID&quot;&amp;gt;&lt;/code&gt;使用&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;svg-进阶&quot;&gt;SVG 进阶&lt;/h2&gt;

&lt;h3 id=&quot;六坐标系统--使用-transform-观察&quot;&gt;六、坐标系统 – 使用 transform 观察&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 视野(viewbox)的概念&lt;/li&gt;
  &lt;li&gt;2 分组的概念(&lt;g&gt;)&lt;/g&gt;&lt;/li&gt;
  &lt;li&gt;3 四个坐标
    &lt;ul&gt;
      &lt;li&gt;1 用户坐标系(User Coordinate)
        &lt;ul&gt;
          &lt;li&gt;世界的坐标系&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 自身坐标系(Current Coordinate)
        &lt;ul&gt;
          &lt;li&gt;每个图形元素或者分组独立与生俱来&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 前驱坐标系(Previous Coordinate)
        &lt;ul&gt;
          &lt;li&gt;父容器的坐标系&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 参考坐标系(Reference Coordinate)
        &lt;ul&gt;
          &lt;li&gt;使用其他坐标系来考究自身的情况时使用&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 坐标变换
    &lt;ul&gt;
      &lt;li&gt;线性变换 – (MD: 高数和图形变换都还给老师了)
        &lt;ul&gt;
          &lt;li&gt;transform属性
            &lt;ul&gt;
              &lt;li&gt;前驱坐标系: 父容器的坐标系&lt;/li&gt;
              &lt;li&gt;transform属性: 定义前驱坐标系到自身坐标系的线性变换&lt;/li&gt;
              &lt;li&gt;语法: rotate(deg) / translate(x, y) / scale(sx, sy) / matrix(a, b, c, d, e, f)&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七rgb与hsl&quot;&gt;七、RGB与HSL&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;基础
    &lt;ul&gt;
      &lt;li&gt;RGB: 用Red, Green, Blue分量来表示颜色
        &lt;ul&gt;
          &lt;li&gt;格式: rgb(r, g, b) 或者 #rrggbb&lt;/li&gt;
          &lt;li&gt;取值: 0-255&lt;/li&gt;
          &lt;li&gt;优劣: 容易显示器解析，但不符合人类描述颜色的习惯&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;HSL: 用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;颜色(Hue)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;饱和度(Saturation)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;亮度(Lightness)&lt;/code&gt;来表示
        &lt;ul&gt;
          &lt;li&gt;格式: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hsl(h, s%, l%)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;取值范围
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h: [0, 359]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s, l: [0, 100]&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;优势符合人类描述颜色的习惯&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/11/20/getting-started-with-svg.html</link>
    <guid>/2016/11/20/getting-started-with-svg</guid>
    <pubDate>Sun, 20 Nov 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Express 项目基础架构及使用文档</title>
    <description>
&lt;h3 id=&quot;1-项目文件结构&quot;&gt;@1 项目文件结构&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;img src=&quot;/images/ExpressProjectBasicFileStructure.png&quot; alt=&quot;ExpressProjectBasicFileStructure.png&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;解析
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.js&lt;/code&gt;: 项目入口文件&lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app&lt;/code&gt;: 项目目录
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;schemas&lt;/code&gt;: mongoose 数据结构&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;models&lt;/code&gt;: mongoose 模型文件&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;controllers&lt;/code&gt;: 控制器, 主要是路由动作函数&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt;: 静态文件目录
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib&lt;/code&gt;: 公用静态文件，如bootstrap&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;js&lt;/code&gt;: javascript&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;css&lt;/code&gt;: css&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;images&lt;/code&gt;: images&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;config&lt;/code&gt;: 项目配置目录
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;routes.js&lt;/code&gt;: 路由配置&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;middlewares.js&lt;/code&gt;: 全局中间件&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gulp.js&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package.json&lt;/code&gt;: 项目开发配置文件&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-version-4x-安装&quot;&gt;@2 version 4.x 安装&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 安装NPM&lt;/li&gt;
  &lt;li&gt;2 &lt;a href=&quot;https://github.com/creationix/nvm&quot;&gt;使用NVM安装和管理Node&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;3 安装 express
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;npm install express --save&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 &lt;a href=&quot;https://docs.npmjs.com/files/package.json&quot;&gt;开发配置之package.json&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-express-hello-world-web-server&quot;&gt;@3 Express Hello world web server&lt;/h3&gt;

&lt;div class=&quot;language-javascript 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;// app.js&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&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;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Hello World!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;App server listening on port 3000!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 运行Web Server&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  node app.js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-rest-http-methods&quot;&gt;@4 Rest: HTTP METHODS&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 HTTP请求 -&amp;gt; 事件 -&amp;gt; 数据库操作
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET  -&amp;gt;  查询  -&amp;gt; select&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST -&amp;gt;  新建  -&amp;gt; insert&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PUT  -&amp;gt;  更新  -&amp;gt; update&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DELETE -&amp;gt;  删除  -&amp;gt; delete&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用REST的HTTP请求
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MANY(列表数据)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET  -&amp;gt; LIST(列表)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST -&amp;gt; CREATE(创建)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ONE(单一数据)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET  -&amp;gt; RETRIEVE(查询)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PUT  -&amp;gt; UPDATE(更新)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DELETE -&amp;gt; DELETE(删除)/DESTROY(销毁)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 安全: 所有操作都要做好过滤，尤其是不安全操作
    &lt;ul&gt;
      &lt;li&gt;安全操作: GET&lt;/li&gt;
      &lt;li&gt;不安全操作: POST, PUT, DELETE&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-基本路由basic-route&quot;&gt;@5 基本路由(Basic Route)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.METHOD(PATH, HANDLER)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// HTTP GET
app.get(&apos;/&apos;, function (req, res) {
  res.send(&apos;GET&apos;);
})

// HTTP POST
app.post(&apos;/&apos;, function (req, res) {
  res.send(&apos;POST&apos;);
})

// HTTP PUT
app.put(&apos;/user/sama&apos;, function (req, res) {
  res.send(&apos;PUT&apos;);
});

// HTTP DELETE
app.delete(&apos;/user/sama&apos;, function (req, res) {
  res.send(&apos;DELETE&apos;);
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6-express-高级路由advanced-route&quot;&gt;@6 Express 高级路由(Advanced Route)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 路由方法(METHODS)
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.all(PATH, MIDDLEWARE_HANDLER)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;在对PATH路径的get/post/put/delete等请求前做处理&lt;/li&gt;
          &lt;li&gt;MIDDLEWARE_HANDLER: 请查看 @7 Express 中间件&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意区别: app.use(&apos;*&apos;, MIDDLEWARE_HANDLER);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 路由路径(PATH)
    &lt;ul&gt;
      &lt;li&gt;PATH
        &lt;ul&gt;
          &lt;li&gt;类型:
            &lt;ul&gt;
              &lt;li&gt;字符串(string): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.get(&apos;/user&apos;, ...);&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;字符模式(string pattern): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/user/:id&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;正则表达式(regular expression): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.get(/.*\.json$/, ...);&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;注意: 查询字符串(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;query strings&lt;/code&gt;)不属于路径的一部分，如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/user/:id?_t=4545&lt;/code&gt;中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_t&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 路由参数(parameters)
    &lt;ul&gt;
      &lt;li&gt;分析: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/user/:uid/books/:bid?start=0&lt;/code&gt;中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:uid&lt;/code&gt;与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:bid&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;params&lt;/code&gt;: uid&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;query&lt;/code&gt;: start&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body&lt;/code&gt;: POST/PUT等请求中的数据&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意区分: params、query、body&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 斜杠不是区分params的标志, 如: /flight/:from-:to&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;使用
        &lt;ul&gt;
          &lt;li&gt;req.params.uid&lt;/li&gt;
          &lt;li&gt;req.params.bid&lt;/li&gt;
          &lt;li&gt;req.params.from&lt;/li&gt;
          &lt;li&gt;req.params.to&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 路由处理函数
    &lt;ul&gt;
      &lt;li&gt;基本形式&lt;/li&gt;
      &lt;li&gt;多个中间件
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.METHOD(PATH, MIDDLEWARE@1, MIDDLEWARE@2, MIDDLEWARE@3, ..., HANDLER);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 基本形式
function (req, res, next) {
  // do something
  next(); // 最后必须执行next方法，才能进入下一个中间件或者最终处理函数
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5 路由响应方法
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.send(STRING | OBJECT)&lt;/code&gt;: 发送多种形式的响应，常见字符或者JSON&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.json(OBJECT)&lt;/code&gt;: 发送JSON响应&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;req.jsonp(OBJECT)&lt;/code&gt;: 发送JSONP响应&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.status(HTTP_CODE)&lt;/code&gt;: 注意: 只是设置HTTP响应CODE,没有做出响应，一般会: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.status(400).send(&apos;Bad Request&apos;)&lt;/code&gt;等&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.sendStatus(HTTP_CODE)&lt;/code&gt;: 设置HTTP响应CODE，并做出反应&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.redirect([STATUS_CODE,] PATH)&lt;/code&gt;: [设置code,并]跳转&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.render(VIEW[, LOCALS][, callback])&lt;/code&gt;: 渲染视图成HTML，并发送给客户端.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.sendFile(PATH[, OPTIONS][, fn])&lt;/code&gt;: 将文件以OCTET流形式发送&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.end()&lt;/code&gt;: 终止响应进程&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.download(PATH [, FILENAME][, fn])&lt;/code&gt;: 用于方便客户端进行文件下载&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6 路由连锁处理: app.route()&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript 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;// REST&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// MANY: LIST + CREATE&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/user&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MIDDLEWAREs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HANDLER&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;nx&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MIDDLEWAREs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HANDLER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
&lt;span class=&quot;c1&quot;&gt;// ONE: RETRIEVE + UPDATE + DELETE&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/user/:id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MIDDLEWAREs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HANDLER&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;nx&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MIDDLEWAREs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HANDLER&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;k&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MIDDLEWAREs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;...,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;HANDLER&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;ul&gt;
  &lt;li&gt;7 express.Router类 – 号称mini-app&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript 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;// birds.js&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;router&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Router&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// middlewares&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;router&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;next&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;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Time: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;next&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;nx&quot;&gt;router&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&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;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;GET bird&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;router&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/about&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;res&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;nx&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;exports&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;router&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;


&lt;span class=&quot;c1&quot;&gt;// app.js&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;birds&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./birds&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/birds&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;birds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 路径包含 /birds, /birds/about, /birds/*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;7-中间件middleware&quot;&gt;@7 中间件(Middleware)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;(1)组成: F(req, res, next)
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;req&lt;/code&gt;: HTTP request 对象&lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res&lt;/code&gt;: HTTP response 对象&lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next&lt;/code&gt;: 下一个中间件(函数)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;(2)作用:
    &lt;ul&gt;
      &lt;li&gt;1 执行任何代码&lt;/li&gt;
      &lt;li&gt;2 改变(修改、增加、删除)request和response对象的的属性&lt;/li&gt;
      &lt;li&gt;3 结束 request-response 循环，如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.end([DATA])&lt;/code&gt;直接响应，不再进入下一个中间件或者处理函数&lt;/li&gt;
      &lt;li&gt;4 调用栈中的下一个中间件(next);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;(3)注意及FAQ:
    &lt;ul&gt;
      &lt;li&gt;如果当前中间件不能结束&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;请求-响应(request-response)&lt;/code&gt;循环，那么必须调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next()&lt;/code&gt;来交给下一个中间件；&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;否则, 请求将会被挂起, 这也是HTTP请求一直没有反应的原因之一&lt;/code&gt;。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;(4)类型与使用
    &lt;ul&gt;
      &lt;li&gt;类型
        &lt;ul&gt;
          &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;应用级(Application-level)&lt;/code&gt;中间件&lt;/li&gt;
          &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;路由级(Router-level)&lt;/code&gt;中间件&lt;/li&gt;
          &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;错误处理(Error-handling)&lt;/code&gt;中间件&lt;/li&gt;
          &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;內建(Built-in)&lt;/code&gt;中间件&lt;/li&gt;
          &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第三方(Third-party)&lt;/code&gt;中间件&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Application-level&lt;/code&gt;中间件
        &lt;ul&gt;
          &lt;li&gt;1 与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app对象&lt;/code&gt;绑定的中间件叫应用级中间件, 也就是使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.use()&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.METHOD()&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next(&apos;route&apos;)&lt;/code&gt;会忽略剩下的所有中间件，之间到最后的处理函数（区别: next() 会进入下一个中间件，next(err)会跳到错误处理中间件(如果有)）。&lt;/li&gt;
          &lt;li&gt;3 FAQ
            &lt;ul&gt;
              &lt;li&gt;app.use(PATH, MIDDLEWARE): 只对PATH生效&lt;/li&gt;
              &lt;li&gt;app.use(MIDDLEWARE): 对所有挂载路径生效&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Router-level&lt;/code&gt;中间件
        &lt;ul&gt;
          &lt;li&gt;1 与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;router对象&lt;/code&gt;绑定, 其中router = express.Router(), 也是使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;router.use()&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;router.METHOD()&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;2 其他与应用级中间件一致&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Error-handling&lt;/code&gt;中间件
        &lt;ul&gt;
          &lt;li&gt;形式: function (err, req, res, next) { … }&lt;/li&gt;
          &lt;li&gt;next()不是必须执行，可以在这里报错res.end等&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Third-party&lt;/code&gt;中间件一般是应用级或者路由级中间件
        &lt;ul&gt;
          &lt;li&gt;常用
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body-parser&lt;/code&gt;: 解析body&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cookie-parser&lt;/code&gt;: 解析cookie&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;express-session&lt;/code&gt;: 保存session&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;morgan&lt;/code&gt;: 记录日志Logger&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;connect-multiparty&lt;/code&gt;: 解析文件上传&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server-favicon&lt;/code&gt;: 处理favicon&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Built-in&lt;/code&gt;中间件
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;express.static(root, [options])&lt;/code&gt;是唯一的內建中间件
            &lt;ul&gt;
              &lt;li&gt;root指定的目录是静态文件的根目录&lt;/li&gt;
              &lt;li&gt;options是可选参数&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript 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;nx&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;__dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// dofiles确定如何对待以`.`开头的文件或目录(也就是是否显示)，&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// String类型, 可选值ignore, deny, allow，&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 其中ignore与deny的区别是，deny以403拒绝请求隐藏文件(以.开头)，ignore会在找不到文件的时候返回404&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;dofiles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ignore&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  
  &lt;span class=&quot;c1&quot;&gt;// 开启或禁用Etag生成标志&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 关于Etag: http://www.sxt.cn/u/324/blog/2188&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;etag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&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;na&quot;&gt;extensions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&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;na&quot;&gt;fallthrough&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&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;na&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;index.html&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  
  &lt;span class=&quot;c1&quot;&gt;// 响应头: Last-Modified&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;lastModified&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  
  &lt;span class=&quot;c1&quot;&gt;// 响应头: Cache-Control (缓存)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// 值: 默认是毫秒的数字0, 可以设置&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//  其他字符串值 &apos;1d&apos; = 86400000, &apos;1h&apos;=3600000, &apos;1m&apos;=60000, &apos;5s&apos;=5000&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// More: https://www.npmjs.org/package/ms&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;maxAge&lt;/span&gt;&lt;span class=&quot;p&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;c1&quot;&gt;// 默认true, 在路径是目录时跳转到/，也就是在路径后面加/&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;redirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&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;na&quot;&gt;setHeaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;stat&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;c1&quot;&gt;// res.set(&apos;x-timestamp&apos;, Date.now());&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;h3 id=&quot;8-模板引擎template-engines&quot;&gt;@8 模板引擎(Template Engines)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;常见
    &lt;ul&gt;
      &lt;li&gt;pug (就是以前的jade, 默认)&lt;/li&gt;
      &lt;li&gt;mustache&lt;/li&gt;
      &lt;li&gt;ejs&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;使用
    &lt;ul&gt;
      &lt;li&gt;1 设置模板引擎: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.set(&apos;view engine&apos;, &apos;pug&apos;);&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;2 设置模板根目录: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app.set(&apos;views&apos;, &apos;./app/views&apos;);&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;3 渲染模板: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;res.render(TEMPLATE_NAME, LOCALS);&lt;/code&gt;, 其中TEMPLATE_NAME为./app/views下的文件, LOCALS为传入模板的文件&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;9-数据库集成database-integeration&quot;&gt;@9 数据库集成(Database Integeration)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;常用
    &lt;ul&gt;
      &lt;li&gt;MongoDB -&amp;gt; Mongoose&lt;/li&gt;
      &lt;li&gt;Mysql&lt;/li&gt;
      &lt;li&gt;PostgreSQL -&amp;gt; pg-promise&lt;/li&gt;
      &lt;li&gt;Redis&lt;/li&gt;
      &lt;li&gt;Neo4j&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongoose&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://mongoosejs.com/index.html&quot;&gt;DOCUMENT&lt;/a&gt;
```javascript
// 安装 mongoose
// npm install mongoose
var mongoose = require(‘mongoose’);
var URL = ‘mongodb://localhost/DATABASE_NAME’;
mongoose.connect(URL, function (err, db) {
if (err) {
console.log(‘Error: MongoDB connect error, check whether mongo server has been running.’);
console.log(‘Error Detail: ‘, err);
}
});&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;```&lt;/p&gt;
</description>
    <link>/2016/07/12/use-with-express.html</link>
    <guid>/2016/07/12/use-with-express</guid>
    <pubDate>Tue, 12 Jul 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>全站 HTTPS 实践</title>
    <description>
&lt;h3 id=&quot;参考&quot;&gt;参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.seabornlee.cn/post/bian-cheng/2016-01-03-enable-https-for-codignstyle-cn&quot;&gt;创业者HTTPS实践&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://zangxixi.xyz/post/practise/2015-12-05&quot;&gt;Https使用的那些事儿&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.embbnux.com/2015/12/29/letsencrypt_with_nginx_config_for_wordpress/&quot;&gt;Let’s Encrypt网站启用https以及nginx配置安全优化&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://imququ.com/post/my-nginx-conf.html&quot;&gt;本博客 Nginx 配置之完整篇&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://imququ.com/post/letsencrypt-certificate.html&quot;&gt;Let’s Encrypt，免费好用的 HTTPS 证书&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.textarea.com/zhicheng/fenxiang-yige-https-a-di-nginx-peizhi-320/&quot;&gt;分享一个 HTTPS A+ 的 nginx 配置&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/06/14/web-https.html</link>
    <guid>/2016/06/14/web-https</guid>
    <pubDate>Tue, 14 Jun 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>program docs search tools</title>
    <description>
&lt;h3 id=&quot;文档查询工具&quot;&gt;文档查询工具&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://kapeli.com/dash&quot;&gt;Dash&lt;/a&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mac&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zealdocs.org/download.html&quot;&gt;Zeal&lt;/a&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cross Platform&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;快速查询工具&quot;&gt;快速查询工具&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;[Alfred]&lt;/li&gt;
  &lt;li&gt;[Mutate]&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;文档快速生成&quot;&gt;文档快速生成&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Python
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.sphinx-doc.org/en/stable/&quot;&gt;Sphinx&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;https://github.com/snide/sphinx_rtd_theme&quot;&gt;Uwsgi Theme&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://readthedocs.org/&quot;&gt;https://readthedocs.org/&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/04/29/program-docs-search-tools.html</link>
    <guid>/2016/04/29/program-docs-search-tools</guid>
    <pubDate>Fri, 29 Apr 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux 开发有用的工具集</title>
    <description>
&lt;h3 id=&quot;一网络&quot;&gt;一、网络&lt;/h3&gt;

&lt;h4 id=&quot;流量分析&quot;&gt;流量分析&lt;/h4&gt;

&lt;h5 id=&quot;http&quot;&gt;HTTP&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;a href=&quot;https://linux.cn/article-4148-1.html&quot;&gt;httpry&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;定义: Linux 命令行下嗅探 HTTP 流量的工具&lt;/li&gt;
      &lt;li&gt;常用命令:
        &lt;ul&gt;
          &lt;li&gt;sudo httpry -i DEVICE ＃监听DEVEICE的http流量, DEVICE可以为wlan0, eth0, eno1 等任何网络接口&lt;/li&gt;
          &lt;li&gt;sudo httpry -i DEVICE -m get,head # -m 监听指定的HTTP方法&lt;/li&gt;
          &lt;li&gt;sudo httpry -i DEVICE -o FILE # -o 指定输出文件&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo httpry -i DEVICE | grep xxx&lt;/code&gt; # 结合管道&lt;/li&gt;
          &lt;li&gt;其他 httpry -h 获取&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;a href=&quot;https://m.oschina.net/blog/212701&quot;&gt;tcpdump&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;定义: 一个运行在命令行下的嗅探工具&lt;/li&gt;
      &lt;li&gt;常用命令:
        &lt;ul&gt;
          &lt;li&gt;sudo tcpdump tcp port 80 -n -X -s 0 # http数据包抓取&lt;/li&gt;
          &lt;li&gt;sudo tcpdump tcp port 80 -n -X -s 0 # 抓取htto包数据指定文件进行输出package&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;sudo tcpdump tcp port 80 -n -X -s 0 -l&lt;/td&gt;
                  &lt;td&gt;grep xxx # 结合管道流&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
          &lt;li&gt;sudo tcpdump tcp host 10.16.2.85 and port 2100 -s 0 -X # 只监控特定的ip主机&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;其他选项:
        &lt;ul&gt;
          &lt;li&gt;-i DEVICE 指定接口&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://guo583.iteye.com/blog/1330791&quot;&gt;More&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 &lt;a href=&quot;http://stackoverflow.com/questions/9241391/how-to-capture-all-the-http-packets-using-tcpdump&quot;&gt;ngrep&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;定义: 是grep(在文本中搜索字符串的工具)的网络版，他力求更多的grep特征， 用于搜寻指定的数据包&lt;/li&gt;
      &lt;li&gt;常用命令:
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/9241391/how-to-capture-all-the-http-packets-using-tcpdump&quot;&gt;ngrep -q -d DEVICE -W byline host HOST and port 80&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;ngrep -q -d DEVICE -W byline host HOST and port 80&lt;/td&gt;
                  &lt;td&gt;grep xxx # 结合管道&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/04/29/linux-develop-useful-tools-set.html</link>
    <guid>/2016/04/29/linux-develop-useful-tools-set</guid>
    <pubDate>Fri, 29 Apr 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Nginx 禁止未绑定域名(包括IP)范围</title>
    <description>
&lt;h3 id=&quot;问题&quot;&gt;问题&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;随意绑定域名到IP, 都可以访问；但是不想被其他未指定的域名绑定, 返回404或者其他.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;解决方法一&quot;&gt;解决方法(一)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;编辑 nginx.conf 或者 自己配置的server文件&lt;/li&gt;
  &lt;li&gt;在其他server里指定server_name, 比如: colesmith.space;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 添加以下代码, 作为默认服务(访问)
// 其他 server 不能设置为default_server;
// 检测: nginx -t
// vim /etc/nginx/nginx.conf
server {
    listen      80 default_server;
    server_name _;
    return      404; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 在其他server里指定server_name, 比如: colesmith.space
// 浏览器访问: http://colesmith.space 可以访问
// 其他域名即使绑定，也指向404页面
// 
// server_name 可以指定IP， 开放IP访问
// server_name 可以指定多个域名，用空格隔开
server {
    listen      80;
    ...
    server_name colesmith.space love.me 112.113.114.115;
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;解决方法二&quot;&gt;解决方法(二)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;编辑nginx.conf
    &lt;ul&gt;
      &lt;li&gt;1 设置default_server&lt;/li&gt;
      &lt;li&gt;2 设置server_name, 限制指定域名访问，其他域名404页面&lt;/li&gt;
      &lt;li&gt;3 在default_server中用try_files
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try_files $uri $uri/ @error&lt;/code&gt; (Django or other)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try_files $uri $uri/index.php?$args 404&lt;/code&gt; (PHP or other)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/17798457/how-can-i-make-this-try-files-directive-work&quot;&gt;参考&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 
server {
    listen      80 default_server;
    server_name colesmith.space 111.222.333.444;
    ...

    location / {
        ...
        try_files $uri $uri 404;
    }
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;相关&quot;&gt;相关&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://nginx.org/en/docs/&quot;&gt;Nginx 官方文档&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/taobao/nginx-book&quot;&gt;Nginx开发从入门到精通&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/01/29/nginx-prohibites-the-access-of-unbounded-domains.html</link>
    <guid>/2016/01/29/nginx-prohibites-the-access-of-unbounded-domains</guid>
    <pubDate>Fri, 29 Jan 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Vsftpd 虚拟用户及其家目录的配置</title>
    <description>
&lt;h3 id=&quot;参考&quot;&gt;参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://askubuntu.com/questions/575523/how-to-setup-virtual-users-for-vsftpd-with-access-to-a-specific-sub-directory&quot;&gt;How to setup virtual users for vsftpd with access to a specific sub directory?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/liangxanhai/article/details/8157922&quot;&gt;在ubuntu下vsftpd建立虚拟用户的详解&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;一os&quot;&gt;一.OS&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ubuntu 14.04&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二vsftpd-version&quot;&gt;二.Vsftpd Version&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vsftpd: version 3.0.2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三准备工作&quot;&gt;三.准备工作&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;下载VSFTPD: FTP 服务
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt-get install vsftpd&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;下载&lt;a href=&quot;http://www.ibm.com/developerworks/cn/linux/l-pam/index.html&quot;&gt;PAM(Pluggable Authentication Module)&lt;/a&gt;: 插入验证模块
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt-get install libpam-pwdfile&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;下载apache2-utils(使用到htpasswd, 密码管理)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;apt-get install apache2-utils&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四覆盖vsftpd配置文件etcvsftpdconf&quot;&gt;四.覆盖VSFTPD配置文件(/etc/vsftpd.conf)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 以下全是/etc/vsftpd.conf中的内容&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# 监听服务(IPV4), 如果是IPV6, 则应开启listen_ipv6=YES
listen=YES
# 不允许匿名用户登陆, 如果要开启, 则anonymous_enable=YES
anonymous_enable=NO
# 允许本地用户登录, 虚拟用户依赖于待会儿新建的本地用户vsftp
local_enable=YES
# 本地用户写入(上传)权限
write_enable=YES
# 本地用户的umask
local_umask=022
# 本地用户的根目录, 虚拟用户目录配置在下面
local_root=/var/www
# @TODO 不理解, 拥有本地用户权限
chroot_local_user=YES
# @TODO 允许chroot写入
allow_writeable_chroot=YES
# @TODO 隐藏ID ?
hide_ids=YES

#################
#  虚拟用户配置 #
#################
# !important: 用户配置目录
# 要自己新建: mkdir -p /etc/vsftp/users_conf
# 假设已经新建用户, 其用户名为user1
# 那么配置完$user_config_dir, vsftpd服务会去查找$user_config_dir/user1文件
# $user_config_dir/user1 这个文件和/etc/vsftpd.conf一样, 所以你可以在这个目录下重新配置每个用户的家目录
# 例如: 希望设置user1的家目录为: /var/www/web_user1
#   创建目录: mkdir -p /var/www/web_user1 
#   编写配置文件($user_config_dir/user1文件是自己新建的):
#         内容为: local_root=/var/www/web_user1
user_config_dir=/etc/vsftpd/users_conf

# PAM服务的名字， 匹配文件: /etc/pam.d/vsftpd
pam_service_name=vsftpd
# @TODO 没有权限用户
nopriv_user=vsftpd
# @TODO 允许访客登陆 不理解
guest_enable=YES
# 访客用户名
guest_username=vsftpd
# 让虚拟用户使用本地用户的权限
virtual_use_local_privs=YES
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五虚拟用户创建与配置&quot;&gt;五.虚拟用户创建与配置&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;创建目录/etc/vsftpd,用于存放虚拟用户
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir /etc/vsftpd&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;运用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;htpasswd&lt;/code&gt;创建虚拟用户和密码
        &lt;ul&gt;
          &lt;li&gt;Situation 1: 第一次创建虚拟用户文件(/etc/vsftpd/ftpd.passwd)和虚拟用户(user1)&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;htpasswd -cd /etc/vsftpd/ftpd.passwd user1&lt;/code&gt;
    * Situation 2: 只是添加新的虚拟用户(user1)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;htpasswd -d /etc/vsftpd/ftpd.passwd user1&lt;/code&gt;
    * &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tips: -c 选项会覆盖文件&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;创建或覆盖文件: /etc/vsftpd/ftpd.passwd, 写入以下两行
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auth required pam_pwdfile.so pwdfile /etc/vsftpd/ftpd.passwd&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;account required pam_permit.so&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;# 注: 这将允许使用/ect/vsftpd/ftpd.passwd中的虚拟用户登陆&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;# 并且更重要的是: 禁止本地用户登陆, 比如root等&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;添加个本地用户给虚拟用户使用, 这些虚拟用户没有权限使用Shell
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;定义每个虚拟用户的访问目录(或叫权限)
        &lt;ul&gt;
          &lt;li&gt;涉及/etc/vsftpd.conf中的user_config_dir变量, 它的值为/etc/vsftpd/users_conf&lt;/li&gt;
          &lt;li&gt;创建 $user_config_dir 目录&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkdir /etc/vsftpd/users_conf&lt;/code&gt;
    * 其他请参考&lt;a href=&quot;#四.覆盖VSFTPD配置文件(/etc/vsftpd.conf)&quot;&gt;四.覆盖VSFTPD配置文件(/etc/vsftpd.conf)&lt;/a&gt;中的配置&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六重启vsftpd服务&quot;&gt;六.重启VSFTPD服务&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;service vsftpd restart&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七faq&quot;&gt;七.FAQ&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如果没用创建 user conf file (虚拟用户配置文件)
        &lt;ul&gt;
          &lt;li&gt;默认根目录为: $local_root, 即/var/www&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/01/25/setup-vsftpd-virtual-users-and-their-home-directory.html</link>
    <guid>/2016/01/25/setup-vsftpd-virtual-users-and-their-home-directory</guid>
    <pubDate>Mon, 25 Jan 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Django 1.9 Issues</title>
    <description>
&lt;h3 id=&quot;issue-1-django-mysqldb&quot;&gt;Issue #1 Django MySQLdb&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Detail:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;No module named &apos;MySQLdb&apos;&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Solved:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install mysqlclient&lt;/code&gt; &lt;a href=&quot;https://github.com/PyMySQL/mysqlclient-python&quot;&gt;github&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2016/01/11/django-19-issues.html</link>
    <guid>/2016/01/11/django-19-issues</guid>
    <pubDate>Mon, 11 Jan 2016 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>栈应用 - 括号匹配</title>
    <description>
&lt;h3 id=&quot;一原理&quot;&gt;一、原理&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;很简单，遇到左括号用栈存起来，遇到右括号就从栈取出一个比较即可.&lt;/li&gt;
  &lt;li&gt;特殊情况:
    &lt;ul&gt;
      &lt;li&gt;在栈空的情况下遇到右括号肯定不匹配;&lt;/li&gt;
      &lt;li&gt;在括号扫描结束的情况下，栈不为空，肯定不匹配.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二步骤&quot;&gt;二、步骤&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Step 1: 从左到右扫描括号字符串&lt;/li&gt;
  &lt;li&gt;Step 2: 左括号入栈&lt;/li&gt;
  &lt;li&gt;Step 3: 判断右括号与栈顶元素是否匹配
    &lt;ul&gt;
      &lt;li&gt;如果存储左括号的栈空或不匹配，返回false&lt;/li&gt;
      &lt;li&gt;如果匹配出栈，扫描下一个字符&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Step 4: 扫描结束后，如果栈不为空，则肯定不匹配&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三实现&quot;&gt;三、实现&lt;/h3&gt;

&lt;div class=&quot;language-c 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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;init&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;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;(&apos;&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;o&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;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;)&apos;&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;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;[&apos;&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;o&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;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;]&apos;&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;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;{&apos;&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;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;}&apos;&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;mi&quot;&gt;3&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;cm&quot;&gt;/**
 * @Desc 括号匹配
 * @param   s 输入的括号字符串
 * @return  true 括号匹配
 *          false 括号不匹配
 */&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BracketsMatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&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;c1&quot;&gt;// 初始化BRACKETS_VALUE, 方便比较左右括号&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 左括号为负值，右括号为正值&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 每组括号，左右和为0&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 用处: 只要查看左右括号和是否为0即可判断是否匹配&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;init&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;n&quot;&gt;stack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Step 1: 从左到右扫描括号字符串&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;sc&quot;&gt;&apos;\0&apos;&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;n&quot;&gt;i&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;c1&quot;&gt;// Step 2: 左括号入栈&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&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;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Step 3: 右括号与栈顶元素是否匹配&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//   如果存储左括号的栈空或不匹配，返回false&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//   如果匹配出栈，扫描下一个字符&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&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;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;BRACKETS_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&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;mi&quot;&gt;0&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;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&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;span class=&quot;c1&quot;&gt;// Step 4: 栈是否为空 ? 匹配 : 不匹配;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&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;n&quot;&gt;storeLeft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&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;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&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;h3 id=&quot;四实例&quot;&gt;四、实例&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/work/algorithm/Stack-2-Bracket-Match.cpp&quot;&gt;地址&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/17/stack-bracket-match.html</link>
    <guid>/2015/10/17/stack-bracket-match</guid>
    <pubDate>Sat, 17 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>栈应用 - 中缀表达式->后缀表达式</title>
    <description>
&lt;h3 id=&quot;一原理&quot;&gt;一、原理&lt;/h3&gt;

&lt;h3 id=&quot;二步骤&quot;&gt;二、步骤&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Step 1: 从左向右开始扫描中缀表达式&lt;/li&gt;
  &lt;li&gt;Step 2: 如果是数字或字母，直接输出 或者 存取在其他地方&lt;/li&gt;
  &lt;li&gt;Step 3: 遇到运算符时, 3 IF
    &lt;ul&gt;
      &lt;li&gt;若为’(‘或栈空, 入栈;&lt;/li&gt;
      &lt;li&gt;若为’)’, 出栈直到’(‘为止;&lt;/li&gt;
      &lt;li&gt;若为其他, 比较运算符优先级,
        &lt;ul&gt;
          &lt;li&gt;如果栈非空并且tmpC&amp;lt;=栈顶元素，栈顶元素出栈；&lt;/li&gt;
          &lt;li&gt;比较下一个栈顶元素, 直到栈空或左括号;&lt;/li&gt;
          &lt;li&gt;最后将tmpC入栈.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三实现&quot;&gt;三、实现&lt;/h3&gt;

&lt;div class=&quot;language-c 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;nfixExpression2Postfix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&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;c1&quot;&gt;// 用于临时存放操作符的栈&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;stack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;// Step 1: 从左向右开始扫描中缀表达式&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&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;n&quot;&gt;i&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;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmpChar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Step 2: 如果是数字或字母，直接输出 或者 存取在其他地方&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isAlphaOrNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmpChar&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;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmpChar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&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;c1&quot;&gt;// Step 3: 遇到运算符时, 3 IF&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  若为&apos;(&apos;或栈空, 入栈;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  若为&apos;)&apos;, 出栈直到&apos;(&apos;为止;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  若为其他, 比较运算符优先级, &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    [  如果tmpC优先级&amp;gt;栈顶符号优先级，入栈;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//      否则，从栈顶开始，依次弹出与tmpC比较, &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    直到tmp优先级&amp;gt;栈顶元素优先级或者栈空或者遇到一个左括号为止.&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    优先级: */ &amp;gt; +- &amp;gt; ()]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    --&amp;gt; 思想转换: 如果栈非空并且tmpC&amp;lt;=栈顶元素，栈顶元素出栈；&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//                比较下一个栈顶元素, 直到栈空或左括号;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//                最后将tmpC入栈.&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// IF 1  &lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&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;sc&quot;&gt;&apos;(&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmpChar&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;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmpChar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&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;c1&quot;&gt;// IF 2&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;)&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmpChar&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;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&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;sc&quot;&gt;&apos;(&apos;&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;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&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;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;continue&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;c1&quot;&gt;// IF 3&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/*
        if (highPriority(tmpChar, operatorStack.top())) {
            operatorStack.push(tmpChar);
        } else {
            while(! operatorStack.empty() &amp;amp;&amp;amp; \
                    ! highPriority(tmpChar, operatorStack.top())) {
                cout &amp;lt;&amp;lt; operatorStack.top();
                operatorStack.pop();
            }
            operatorStack.push(tmpChar);
        }*/&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&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;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; \
        &lt;span class=&quot;c1&quot;&gt;// highPriority(a, b)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  如果a优先级高于b, true; 否则, false&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;highPriority&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmpChar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&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;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&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;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmpChar&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;c1&quot;&gt;// Step 4: 当扫描的中缀表达式结束时，栈中的所有运算符依次输出加入后缀表达式&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&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;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&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;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;operatorStack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pop&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;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&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;h3 id=&quot;四实例&quot;&gt;四、实例&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/work/algorithm/Stack-1-Arithmetic-Expression-Conversion.cpp}&quot;&gt;例子&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/17/stack-arithmetic-expression-convertion.html</link>
    <guid>/2015/10/17/stack-arithmetic-expression-convertion</guid>
    <pubDate>Sat, 17 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>数据结构中的逻辑结构与物理结构</title>
    <description>
&lt;h3 id=&quot;一理解重点&quot;&gt;一、理解(重点)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;比如数据结构中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;树&lt;/code&gt;的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;存储&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;逻辑结构&lt;/code&gt;: 很形象啊，在你脑海里不就是一棵树吗?&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;物理结构&lt;/code&gt;: 这棵&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;树&lt;/code&gt;在物理内存中可以用数组存储(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;顺序存储&lt;/code&gt;), 也可以在内存中用链表存储(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;链式存储&lt;/code&gt;);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二课本原理&quot;&gt;二、课本原理&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;逻辑结构:
    &lt;ul&gt;
      &lt;li&gt;指数据元素之间的逻辑关系;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;物理结构:
    &lt;ul&gt;
      &lt;li&gt;指数据结构在计算机中的表示(又称映像);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/zjsjknd/article/details/7203191&quot;&gt;这里讲的不错，不妨看看&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三类型&quot;&gt;三、类型&lt;/h3&gt;

&lt;h4 id=&quot;1逻辑结构&quot;&gt;(1)逻辑结构&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1)集合结构
    &lt;ul&gt;
      &lt;li&gt;数据元素之间无序, 例如大圆圈里许多互不相干的小圆圈;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2)线性结构
    &lt;ul&gt;
      &lt;li&gt;一对一, 例如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数组&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3)树形结构
    &lt;ul&gt;
      &lt;li&gt;一对多, 例如数据结构中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;树&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4)图形结构
    &lt;ul&gt;
      &lt;li&gt;多对多, 例如数据结构中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;图&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2物理结构又称存储结构&quot;&gt;(2)物理结构(又称存储结构)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1) 顺序存储&lt;/li&gt;
  &lt;li&gt;2) 链式存储&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 存储结构与存储方式相区别&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;存取方式&lt;/code&gt;包括顺序存取、随机存取;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/08/logical-and-physical-structure-in-algorithm.html</link>
    <guid>/2015/10/08/logical-and-physical-structure-in-algorithm</guid>
    <pubDate>Thu, 08 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>分治算法(Divide And Conquer Method)</title>
    <description>
&lt;h3 id=&quot;重要性&quot;&gt;重要性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;要我说呢，这是算法中基础中的基础，但并不是不重要，相反，非常重要，而且有一定理解难度，至少对初学者，或者我来说，完全理解并灵活运用，绝非易事。&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;所以，这个分治法(Divide-And-Conquer-Method)得反复看.尤其是递归的时候，必须反思反思分治法.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;一基本思路&quot;&gt;一、基本思路&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1.将问题的实例分为几个较小的实例，最好具有相等规模(事实上,一般说分为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2个实例&lt;/code&gt;居多，并且注意是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;递归的分.&lt;/code&gt;);&lt;/li&gt;
  &lt;li&gt;2.对这些较小的实例求解(一般使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;递归&lt;/code&gt;的方法, 但在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;问题规模足够小&lt;/code&gt;的时候也可以采用另一个算法(停止递归));&lt;/li&gt;
  &lt;li&gt;3.如果有必要的话，合并这些较小问题的解，以得到原始问题的解.(事实上, 一个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;分支算法的精华就在于合并解的过程&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二分析-tn--atnb--fn&quot;&gt;二、分析: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n) = aT(n/b) + f(n)&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;大多数都是规模规模为n的问题，被规划为2个规模为n/2的问题.&lt;/li&gt;
  &lt;li&gt;一般情况下:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一个规模为n的实例可以被划分为b个规模为n/b的实例, 其中a个实例是需要求解的.&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;递推式: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n) = aT(n/b) + f(n)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n)&lt;/code&gt;: 原始问题的解法;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt;: 原始问题的规模, 与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt;区别;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt;: a个实例, 一般等于n/b;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt;: 原始问题划分成小问题后, 每个问题的最小实例的规模;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f(n)&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;表示将求解得到的a个子问题的解合并起来所需要的时间复杂度.&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;对于«&lt;a href=&quot;http://www.cnblogs.com/kkgreen/archive/2011/06/10/2077923.html&quot;&gt;分治法&lt;/a&gt;»中&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;主定理&lt;/code&gt;的理解, 得慢慢消化;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三适用情况&quot;&gt;三、适用情况&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;有点类是标题二的文字版&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;能用分治法解决的问题T(n)的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4个特征&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;1)该问题的规模缩小到一定程度b可以很容易解决T(n/b)(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;类似数学归纳法第一步&lt;/code&gt;)&lt;/li&gt;
      &lt;li&gt;2)该问题可以分解为若干(a个实例)规模较小(规模为b)的相同问题, 即该问题具有最优子结构性质(T(n) ~= aT(n/b));&lt;/li&gt;
      &lt;li&gt;3)利用该问题费解出的子问题就可以合并为该问题的解(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n) = aT(b/n) + f(n)&lt;/code&gt;);&lt;/li&gt;
      &lt;li&gt;4)该问题分解出的各个子问题T(n/b)是相互独立的, 即子问题之间不包含公共的子问题.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;分析:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;每个特征都是下一个特征的前提, 呈上下属关系;&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第二个特征是应用分治法的前提&lt;/code&gt;, 反应在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;递归思想&lt;/code&gt;的运用;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第三个特征是关键, 能否利用分治法完全取决于问题是否具有第三个特征&lt;/code&gt;;
        &lt;ul&gt;
          &lt;li&gt;如果具备了第一、二个特征，而不具备第三个特征，可以考虑&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;贪心法&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;动态规划法&lt;/code&gt;;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第四个特征设计到算法效率&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;如果各个子问题是不独立的则分治法要做许多不必要的工作，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;重复地解公共的子问题(递归计算的诟病)&lt;/code&gt;，此时虽然可以用分治法，但&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一般使用动态规划法较好&lt;/code&gt;.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四分治法的基本步骤&quot;&gt;四、分治法的基本步骤&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;根据前两个标题的讲述，分治法在每一层递归上有三个步骤:
    &lt;ul&gt;
      &lt;li&gt;Step 1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;分解&lt;/code&gt;: 将原问题T(n)分解为若干(a个)规模(为b)较小，相互独立，与原问题相同形式的子问题T(n/b);&lt;/li&gt;
      &lt;li&gt;Step 2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;解决&lt;/code&gt;: 若子问题规模较小而容易被解决，则直接解，否则递归解决各个子问题; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;递归的递归&lt;/code&gt;)&lt;/li&gt;
      &lt;li&gt;Step 3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;合并&lt;/code&gt;: 将各个子问题的解合并为原来问题的解: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n)=aT(n/b)+f(n)&lt;/code&gt;;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五设计模式&quot;&gt;五、设计模式&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Divide-and-Conquer(P)
    &lt;ul&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;1) if&lt;/td&gt;
              &lt;td&gt;P&lt;/td&gt;
              &lt;td&gt;&amp;lt;= n0 //&lt;/td&gt;
              &lt;td&gt;P&lt;/td&gt;
              &lt;td&gt;表示问题P的规模, n0为阈值&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;2)   then return (ADHOC(P))&lt;/li&gt;
      &lt;li&gt;3) 将P分解为较小规模的子问题P1, P2,…, Pk&lt;/li&gt;
      &lt;li&gt;4) for I = 1 -&amp;gt; k&lt;/li&gt;
      &lt;li&gt;5) do answerI &amp;lt;- Divide-and-Conquer(Pi); // &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;递归解决子问题Pi=T(b/n)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;6) T &amp;lt;- MERGE(answer1, answer2,…, answerk); // &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;合并子问题T(n)=aT(n/b)+f(n)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;7) return (T)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;分析:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1)&lt;/code&gt;: 表示当问题规模足够小到不超过n0是，问题已经容易直接解出，不必再继续分解.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2)&lt;/code&gt;: ADHOC(P)是该分治算法中的基本子算法，用于独立地、直接地解决小规模的问题.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6)&lt;/code&gt;: 算法MERGE(answer1,…,answerk)是原问题P的各个子问题的合并算法.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六复杂性分析&quot;&gt;六、复杂性分析&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;一个分治法将规模为n的问题分成a个规模为n/b的子问题去解;&lt;/li&gt;
  &lt;li&gt;设费解阈值n0=1, 且adhoc解规模为1的问题耗时1个单位时间;&lt;/li&gt;
  &lt;li&gt;再设将原问题分解为k个子问题以及用merge将a个子问题的解合并为原问题的解所需要f(n)个单位时间;&lt;/li&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;用T(n)表示该分支算法解规模为&lt;/td&gt;
          &lt;td&gt;P&lt;/td&gt;
          &lt;td&gt;=n的问题所需要的计算时间, 则有:&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T(n) = aT(n/b) + f(n)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;通过迭代法求得方程的解:
    &lt;ul&gt;
      &lt;li&gt;递归方程及其解只给出n等于b的方幂时T(n)的值, 但是如果认为T(n)足够平滑, 那么由n等于b的方幂时T(n)的值可以估计T(n)的增长速度.通常嘉定T(n)是单调上升的，从而当bi &amp;lt;= n &amp;lt;= bi+1时，T(bi) &amp;lt;= T(n) &amp;lt;= T(bi+1).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七经典问题案例&quot;&gt;七、经典问题案例:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;(1) [二分搜索]/2015/10/05/one-out-of-eight-kinds-of-algorithm-1-1-halfinsertsort.html)(又称折半查找法)&lt;/li&gt;
  &lt;li&gt;(2) 大乘数法&lt;/li&gt;
  &lt;li&gt;(3) Strassen矩阵乘法&lt;/li&gt;
  &lt;li&gt;(4) 棋盘覆盖&lt;/li&gt;
  &lt;li&gt;(5) 合并排序&lt;/li&gt;
  &lt;li&gt;(6) &lt;a href=&quot;/2015/10/05/one-out-of-eight-kinds-of-algorithm-4-quicksort.html&quot;&gt;快速排序&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;(7) 线性时间选择&lt;/li&gt;
  &lt;li&gt;(8) 最接近点对问题&lt;/li&gt;
  &lt;li&gt;(9) 循环赛日程表&lt;/li&gt;
  &lt;li&gt;(10) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;汉诺塔&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;八总结&quot;&gt;八、总结&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;依据分治法设计程序时的思维过程
    &lt;ul&gt;
      &lt;li&gt;实际上类似于数学归纳法，眨动解决问题的求解方程公式，然后根据方程公式设计递归程序.
        &lt;ul&gt;
          &lt;li&gt;1、一定是先找到最小问题规模时的求解方法;&lt;/li&gt;
          &lt;li&gt;2、然后考虑随着问题规模增大时的求解方法;&lt;/li&gt;
          &lt;li&gt;3、找到求解的递归函数式后(各种规模或因子)，实际递归程序即可.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    整篇说了这么多，无不是在重复分治法这一思想，为的是说明分治法真的很重要!
            分治法, 很重要!
            分治法, 很重要!
            分治法, 很重要!
            Divide-And-Conquer-Method ! important;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;参考&quot;&gt;参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.cnblogs.com/kkgreen/archive/2011/06/10/2077923.html&quot;&gt;分治法(一)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.jobbole.com/83944/&quot;&gt;五大常用算法之一：分治算法&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/08/divide-and-conquer-method.html</link>
    <guid>/2015/10/08/divide-and-conquer-method</guid>
    <pubDate>Thu, 08 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之7 归并排序(Merge Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;归并排序依赖于递归合并操作, 即将一个数组递归分成两个子数组并分别进行排序,，然后将这两个有序数组排序.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础-合并两个有序列表&quot;&gt;二、基础: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;合并两个有序列表&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;合并有序数列的效率
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;O(n)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;步骤:
    &lt;ul&gt;
      &lt;li&gt;1.申请空间，使其大小为两个已经排序序列之和，然后将待排序数组复制到该数组中.&lt;/li&gt;
      &lt;li&gt;2.设定两个指针，最初位置分别为两个已经排序序列的起始位置&lt;/li&gt;
      &lt;li&gt;3.比较复制数组中两个指针所指向的元素，选择相对小的元素放入到原始待排序数组中，并移动指针到下一位置&lt;/li&gt;
      &lt;li&gt;4.重复步骤3直到某一指针达到序列尾.&lt;/li&gt;
      &lt;li&gt;5.将另一序列剩下的所有元素直接复制到原始数组末尾&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/**
 * @desc 合并两个有序数组a和b到数组c, 其中c的长度为a和b长度之和.
 * @param a[]   有序数组a;
 * @param n     有序数组a的长度;
 * @param b[]   有序数组b;
 * @param m     有序数组b的长度;
 * @param c     长度等于n+m的用于存放有序列表的数组
 * @return 
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MergeTwoOrderedArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// i: 循环a&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// j: 循环b&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// k: 循环c&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&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;c1&quot;&gt;// 从小到大排序&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 1.两个数组逐位比较，谁小去谁, 取了以后iushanchu数列中的这个数,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  直到a和b中有一个有序数组为空;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 2.当一个数组为空时，另一个数组依然是有序的&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  由于剩下的数组有序，则直接添加到c的末尾即可.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&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;c1&quot;&gt;// 谁小谁NB&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// 这里两个while循环实际上只有一个进行&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 不确定的情况下，只是为了正确性多写点代码，无他&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  i是循环a剩下的，如果i==n, 说明a数组用完了，只有b数组的循环会进行;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 反之, j与b亦然.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/**
 * @desc 合并一个前半部分有序，后半部分有序，但总体无序的数组.
 *      类似合并连个有序序列.
 * @param array     待排序数组
 * @param first     待排序起始位置
 * @param mid       待排序中间位置
 * @param last      待排序结束位置
 * @param tmp       存放array有序数据的临时数组
 * @return
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MergeArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;o&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&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;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&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;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;else&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&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;i&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;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;cm&quot;&gt;/**
 * @desc 归并排序的关键操作: 递归分解数组，然后合并
 * 
 * @param array     待排序数组
 * @param first     待排序起始位置
 * @param last      待排序结束位置
 * @param tmp       存放array有序数据的临时数组
 * @return 
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;divideAndMerge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&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;n&quot;&gt;first&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;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&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;c1&quot;&gt;// 一般只分左右两边递归&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;divideAndMerge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;n&quot;&gt;divideAndMerge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;c1&quot;&gt;// 将左右两个有序序列合并&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;MergeArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/*
 * @desc 合并排序
 *
 * @param array     待归并排序的数组
 * @param len       数组长度
 */&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MergeSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;divideAndMerge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&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;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;掌握分治法、两个有序序列的合并 =&amp;gt; 归并排序.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五参考&quot;&gt;五、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/morewindows/article/details/6678165/&quot;&gt;白话经典算法系列之五 归并排序的实现&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.cnblogs.com/yangecnu/p/Introduce-Merge-Sort.html&quot;&gt;浅谈算法和数据结构: 三 合并排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-7-mergesort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-7-mergesort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之6 堆排序(Heap Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;先堆化，然后利用堆的性质排序.
    &lt;ul&gt;
      &lt;li&gt;最大堆: 根节点最大&lt;/li&gt;
      &lt;li&gt;最小堆: 根节点最小&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础-堆heap&quot;&gt;二、基础: 堆(Heap)&lt;/h3&gt;

&lt;h4 id=&quot;1二叉堆一般简称堆的定义&quot;&gt;(1)二叉堆(一般简称堆)的定义&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;二叉堆是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;完全二叉树&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;近似完全二叉树&lt;/code&gt;(只能有最后一个节点不完全)&lt;/li&gt;
  &lt;li&gt;二叉堆&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;个特性:
    &lt;ul&gt;
      &lt;li&gt;a.父结点的键值总是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;大于或等于(最大堆)&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;小于或等于(最小堆)&lt;/code&gt;任何一个子结点的键值.&lt;/li&gt;
      &lt;li&gt;b.每个节点节点的左子树和右子树都是一个二叉堆(最大堆/最小堆).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;类型:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;最大堆&lt;/code&gt;: 父结点的值总是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;大于或等于&lt;/code&gt;任何一个子结点的值.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;最小堆&lt;/code&gt;: 父结点的值总是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;小于或等于&lt;/code&gt;任何一个子结点的值.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;2堆的存储-堆一般就指二叉堆&quot;&gt;(2)堆的存储 (堆一般就指二叉堆)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;存储类型:
    &lt;ul&gt;
      &lt;li&gt;一般用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数组&lt;/code&gt;存储堆.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;结点位置关系: 假设当前节点索引为i
    &lt;ul&gt;
      &lt;li&gt;其&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;父结点&lt;/code&gt;: (i-1)/2 (根节点没有父结点，或者认为根节点的父结点就是它本身.)&lt;/li&gt;
      &lt;li&gt;其&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;子结点&lt;/code&gt;(2个): 2&lt;em&gt;i+1 和 2&lt;/em&gt;i+2.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;3堆的操作--插入与删除&quot;&gt;(3)堆的操作 – 插入与删除&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;注意: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;堆的操作都是为了重新将非堆数组调整回堆.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5 id=&quot;1-插入操作从底部向顶部调整&quot;&gt;$1 插入操作(从底部向顶部调整)&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;只需要将插入子结点与它的父结点逐级向上调整即可&lt;/code&gt;.
    &lt;ul&gt;
      &lt;li&gt;因为如果存在左子结点，那么堆本身的父结点就比左结点小(最小堆)或者大(最大堆)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/* 最小堆的插入操作的上调整
 * array: 存放堆的数组，简称堆
 * child_id: 新加入的子结点，也就是有效数组的最后一个节点
 * parent_id: 子结点child_id的父结点
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapFixup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;child_id&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;c1&quot;&gt;// 计算子结点child_id的父结点&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent_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;n&quot;&gt;child_id&lt;/span&gt; &lt;span class=&quot;o&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;o&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;c1&quot;&gt;// 如果子结点为父结点，即这个堆只有一个节点，不用插入了&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 如果子结点的父结点小于0, 说明该子节点child_id已经是父结点，和上一条重复了&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 所以实际上只要一个条件: parent_id &amp;gt;= 0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;child_id&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;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;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;p&quot;&gt;{&lt;/span&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;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;child_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&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;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;child_id&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;c1&quot;&gt;// 现在从要调整的&quot;新子结点&quot;为原来的父结点&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;child_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 然后查找&quot;新子结点&quot;的父结点&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parent_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;n&quot;&gt;child_id&lt;/span&gt; &lt;span class=&quot;o&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;o&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;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/*
 * @description 堆的插入操作
 *
 * @param array 存放数组的堆，简称堆
 * @param len   原数组的有效长度
 * @insertChild 插入子结点的值
 * @return 
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapAddNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;insertChild&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;c1&quot;&gt;// 插入子结点到数组&apos;末尾&apos;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&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;n&quot;&gt;insertChild&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;n&quot;&gt;MinHeapFixup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;h5 id=&quot;2-删除操作从顶部向底部调整&quot;&gt;$2 删除操作(从顶部向底部调整)&lt;/h5&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;需要父结点在子结点中找出较小或较大者逐级向下比较&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/**
 * @desc 堆删除操作后的从节点
 *      堆化调整的时候是从parentId节点开始自顶向下直到树叶节点(即没有子结点的节点)的.
 * 
 * @param array 堆数组
 * @param len 删除根节点后的堆数组的长度, 此时原来的最后一个子结点已经是现在的根节点，不能算堆，所以要重新调整.
 * @param parent_id 根节点, 从parent_id节点开始向下调整
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapFixdown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&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;c1&quot;&gt;// 理论上的左右两个子结点，不一定存在，还得和数组长度len作比较.&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&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;c1&quot;&gt;// int rightChildId = 2 * parentId + 2;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rightChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt; &lt;span class=&quot;o&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;c1&quot;&gt;// 等待和父结点比较的节点的ID&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchangeId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// 最后一个节点ID: len-1 (数组长度为len, 数组下标从0开始)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//   如果leftChildId&amp;lt;len, 也即leftChildId&amp;lt;=len-1,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 则说明左子结点存在, 此时右子结点还不确定&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;c1&quot;&gt;// 默认要要与父结点交换的结点是左子结点&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;exchangeId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 右子结点=leftChildId+1, 如果存在&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 并且小于leftChildId的值，说明右子结点更小，要和根节点换.&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rightChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rightChildId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;exchangeId&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rightChildId&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;c1&quot;&gt;// (最小堆)如果较小的子结点比父结点大，说明已经是堆了&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchangeId&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&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;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchangeId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 更新需要调整的&quot;新根节点&quot;和它的左右子结点&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchangeId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&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;n&quot;&gt;rightChildId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leftChildId&lt;/span&gt; &lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* 
 * @desc 堆删除操作后的自顶向下调整 - 去掉没用的中间变量
 *   是 MinHeapFixdown 的简化
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapFixdown__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&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;c1&quot;&gt;// 要和父结点交换的子结点ID: childId, 默认是左结点&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;c1&quot;&gt;// 是否存在右节点，并且右节点是否小于左结点&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 如果满足，更新需要和父结点交换的ID: childId&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;o&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;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;childId&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;c1&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;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;childId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parentId&lt;/span&gt; &lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapDeleteNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;MinHeapFixdown__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;mi&quot;&gt;0&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;h4 id=&quot;4堆化数组&quot;&gt;(4)堆化数组&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;从最后一个带子结点的节点开始向上堆化调整&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c 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;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MinHeapSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;c1&quot;&gt;// 在排序前必须进行堆化数组, 构成堆以后再继续从最后一个节点开始修正&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;MakeMinHeap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;c1&quot;&gt;// 而将根节点放在相对最后面用的是:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//     根节点和相对最后一个元素然交换, 就相当于堆的删除操作(后重新构成堆)，但并非真的删除.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;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;n&quot;&gt;i&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;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&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;n&quot;&gt;MinHeapFixdown__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&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;c1&quot;&gt;// cout &amp;lt;&amp;lt; &quot;每次堆化后根节点: &quot; &amp;lt;&amp;lt; array[0] &amp;lt;&amp;lt; endl;&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-bash 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;o&quot;&gt;)&lt;/span&gt; 和 堆化操作 &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; 堆排序.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五参考&quot;&gt;五、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/morewindows/article/details/6709644/#quote&quot;&gt;白话经典算法系列之七 堆与堆排序&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/%E5%A0%86%E6%8E%92%E5%BA%8F&quot;&gt;Wikipedia - 堆排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-6-heapsort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-6-heapsort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之5 选择排序(Select Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;选择排序和冒泡排序是差不多的一种排序.&lt;/li&gt;
  &lt;li&gt;和冒泡选择不一样的的是, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;选择排序只有在确定了最小(或最大)的数据之后，才会发生交换.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础&quot;&gt;二、基础&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/2015/10/05/one-out-of-eight-kinds-of-algorithm-3-bubblesort.html&quot;&gt;冒泡排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/**
 * array : 数组
 * len : 数组长度
 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SelectSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;c1&quot;&gt;// 当前的值最小的数组下标&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;min_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 长度len的数组，排序len-1次交换就行了&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 每次只有最小的排到相对最前面&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// i 刚好存放每次相对最小的数, 也就是要交换的数&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;c1&quot;&gt;// 默认假设最后一个(len-1)数是最小的数&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;min_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt; &lt;span class=&quot;o&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;c1&quot;&gt;// 每次从a[i...len-1]找出相对最小值的下标只需要len-i+1步&lt;/span&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;cm&quot;&gt;/* 
         * 冒泡排序     选择排序
         * * * * * * * * * * * *
         * 每次都交换   只有找到最小值的时候交换
         * */&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;p&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;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min_id&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;min_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Min[&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;]: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 每次和a[i]交换，a[i]此时就是相对最小值，本轮结束&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;min_id&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    与冒泡排序的唯一区别就是，只有在找到相对最小值的时候才发生交换.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五参考&quot;&gt;五、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/feixiaoxing/article/details/6874619&quot;&gt;一步一步写算法（之选择排序）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/%E9%80%89%E6%8B%A9%E6%8E%92%E5%BA%8F&quot;&gt;维基百科-选择排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-5-selectsort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-5-selectsort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之4 快速排序(Quick Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;挖坑填数&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;分治法(Divide and Conquer Method)&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;1、先从数列中取出一个数作为基准数&lt;/li&gt;
  &lt;li&gt;2、分区过程，将比这个数大或者等于的数全放到它右边，小它的数全部放到它的左边&lt;/li&gt;
  &lt;li&gt;3、再对左右区间重复第二步，知道各区间只有一个数.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;复杂度&quot;&gt;复杂度&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;时间复杂度
    &lt;ul&gt;
      &lt;li&gt;O(NlogN), 效率较高&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础-分治法&quot;&gt;二、基础: 分治法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;分治法(Divide And Conquer Method)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;待续: 独立一篇文章写写&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;写好了: &lt;a href=&quot;/2015/10/08/divide-and-conquer-method.html&quot;&gt;分治法&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;h4 id=&quot;1调整数组-挖坑填数思想&quot;&gt;(1)调整数组: 挖坑填数思想&lt;/h4&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/* 挖坑填数部分: (其实只是一轮左小右大的排序, 调整数组, 确定基准数作为相对中间数)
     1. i=left, j=right; 将基准数middle(=a[i])挖出形成第一个坑a[i]
     2. 找小: j--由后往前找比它小的数，找到后挖出此数a[j]填到前一个坑a[i]中, 此时新坑是a[j];
     3. 找大: i++由前往后找比它大的数, 找到后挖出次数a[i]填到前一个坑a[j]中, 此时新坑是a[i];
     4. 再从夫执行2, 3步骤知道i==j, 然后将基准数填入a[i]中.
*/&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;/*
 * Array: 数组
 * left: 希望被排序的起始位置
 * right: 希望被排序的末尾位置
 * 因此: left和right可对数组部分调整
 * 当left=0 且 right=len-1时，则是对整个数组Array调整.
 *  该函数有两个作用:
 *      1.一轮下来，将数组分为左小右大两部分，自然基准数就是相对中间数了, 接下来只要分别对左右两半分别继续调整即可
 *      2.返回基准数最终存放的位置, 为的是区分左右两半部分
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AdjustArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 基数middle(=a[i]=a[left]确定, 第一个坑a[i]挖好&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/* 选择左边第一个数作为基准数 */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 从右到左找小, 要填到左边坑a[i]中&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 注意条件: array[j]大于等于middle&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 找到比基准数小的a[j]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 此时坑a[i]已经填上a[j], a[j]为新坑&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;i&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;c1&quot;&gt;// 因为当前a[i]位置的值a[j], 是和基准数middle比较过的，所以只需要从i的下一位开始&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 从左往右找大, 要填到右边坑a[j]中&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;i&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;c1&quot;&gt;// 找到比基准数大的a[i]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 此时坑a[j]已经填上a[j], a[i]为新坑&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 因为a[j]位置的值a[i], 已经和基准数比较，所以只需要从j的下一位开始&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;cm&quot;&gt;/*
 * Array: 数组
 * left: 希望被排序的起始位置
 * right: 希望被排序的末尾位置
 * 因此: left和right可对数组部分排序
 * 当left=0 且 right=len-1时，则是对整个数组Array排序.
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;c1&quot;&gt;// 只有当数组范围大于1的时候才进行调整&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;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;left&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;c1&quot;&gt;// 一轮调整, i左边的都比a[i]小, i右边的都比a[i]大&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// i 为基准数一轮后存放的位置&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AdjustArray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;c1&quot;&gt;// 由于i左边, 即left-&amp;gt;i-1, 都比a[i]小但是顺序不确定, 以同样的方法调整左小右大两部分,但缩小范围, 只左边&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;c1&quot;&gt;// 由于i右边, 即i+1-&amp;gt;right, 都比a[i]大但无序, 以用样方法调整成左小右大两部分,但范围只有右半部分&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;right&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;h4 id=&quot;2调整数组-交换位置思想&quot;&gt;(2)调整数组: 交换位置思想&lt;/h4&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/*
    由于右边的坑总是填左边的坑，也就是相当于先找到右边的坑，然后找到左边的坑，接着相互交换位置，然后重复这一步即可
*/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AdjustArrayEmiddlechange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 基准数middle&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 从右往左，直到找到比基准数middle小的数&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
            &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 由于第一个i是基准数middle的位置, 已经确定&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 所以在找出右边的坑j后立即交换&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 然后再更新左边的坑i&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 新一个左边的坑i&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 从左往右，知道找到比基准数middle大或者等于的数&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
            &lt;span class=&quot;n&quot;&gt;i&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;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;h4 id=&quot;3调整数组-交换位置思想二&quot;&gt;(3)调整数组: 交换位置思想二&lt;/h4&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/*
    由于基本原理:(middle为基准数, i左, j右)
        a[i] &amp;gt;= middle, 放在右边
        a[j] &amp;lt;  middle, 放在左边
    为什么这么分呢?
        因为往往基准数是选择左边的第一个元素, 
        正是因为此时基准数已经是左边的第一个元素，
        所以它只能往右放, 所以是a[i]等于middle时也放在右边
        (由此，如果你选择的基准数是右边第一个元素，那么a[j]等于middle时应该放在左边, 也即a[i]&amp;gt;middle, 放右边; a[j]&amp;lt;=middle放左边.)
    
    由基本原理, 即使选择左边第一个元素作为基准数，i=left, j=right, 不妨假设左边第一个元素并不知晓，只是从数组中选择了一个基准数, 然后从头开始，先找出左边的第一个坑i, 再找出右边的第一个坑j, 然后交换.
    (与上一个交换唯一不同的就是: `默认第一个i未知`)
*/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AdjustArrayExchange2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;h4 id=&quot;4将两个函数合并成一个&quot;&gt;(4)将两个函数合并成一个&lt;/h4&gt;

&lt;div class=&quot;language-c 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;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;right&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;Swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;QuickSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;right&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    挖坑思想是是关键，从挖坑法想到交换法, 分治基础不可少, 快速搞定.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五参考&quot;&gt;五、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/morewindows/article/details/6684558&quot;&gt;白话经典算法系列之六 快速排序 快速搞定&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/快速排序&quot;&gt;维基百科-快速排序(Quick Sort)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-4-quicksort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-4-quicksort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之3 冒泡排序(Bubble Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;由字面意思:
    &lt;ul&gt;
      &lt;li&gt;鱼儿吐泡般，将轻的泡往上浮, i个泡总共需要i-1轮&lt;/li&gt;
      &lt;li&gt;j从len-1(最后一个元素)到每次都有一个相对最轻的泡到相对顶部&lt;/li&gt;
      &lt;li&gt;这个过程隐含将重的泡往下挤, 直到所有轻的泡都浮在重的泡上面&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;完全相反的方法:
    &lt;ul&gt;
      &lt;li&gt;相对于轻的泡上浮，相反的思路是重的泡下沉.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础&quot;&gt;二、基础&lt;/h3&gt;

&lt;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;h4 id=&quot;1轻泡上浮&quot;&gt;(1)轻泡上浮&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 轻泡上浮法
void BubbleSort(int array[], int len) {
    // 总共len个元素，每轮有一个元素到达相对顶部，那么至少冒泡len-1轮
    // i+1正好表示第几轮
    // i+1正好表示冒泡后顶部第i+1个元素a[i], 此时a[i]是相对最小的
    for (int i=0; i&amp;lt;len-1; ++i) {
        // 从当前最后一个元素开始冒泡, 轻泡上浮最上
        // 当前最后一个元素是a[i]=a[j]
        // 然后不断比较j(后)和j-1(前)
        //      如果满足a[j]&amp;lt;a[j-1], 说明后一个元素比前一个元素轻，应该将气泡上浮
        //      否则说明前一个(上面)的气泡更轻，不用移动
        //   然后j=j-1, 即上浮后的元素再跟它前一个元素比较，直到j=i+1, 也即到相对的第一个元素
        //   每一轮都会使一个相对最小的元素上浮到顶部(此时的最顶部是j-1=i)
        // 然后进入下一轮i
        for (int j=len-1; j&amp;gt;i; --j)
            if (array[j] &amp;lt; array[j-1])
                Swap(array[j], array[j-1]);

        cout &amp;lt;&amp;lt; &quot;第 &quot; &amp;lt;&amp;lt; i+1 &amp;lt;&amp;lt; &quot; 轮排序第&quot; &amp;lt;&amp;lt; i+1 &amp;lt;&amp;lt; &quot;个元素: &quot; &amp;lt;&amp;lt; array[i] &amp;lt;&amp;lt; endl;
        display(array, len);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2重泡下沉&quot;&gt;(2)重泡下沉&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 重泡下沉法
void BubbleSortDown(int array[], int len) {
    // 总共len-1轮
    for (int i=0; i&amp;lt;len-1; ++i) {
        // 该步是和 轻泡上浮法 的关键区别
        // 每一轮有一个最重的泡到相对最底部(与轻泡上浮每次一个最轻到泡到相对最顶部)
        // 每次都是从第一个元素j=0开始，直到j=len-1-i+1, 因为每一步步是j和j+1, 最后异步步j=len-i-1 + 1时, j+1=len-1-i是相对最后一个元素
        for (int j=0; j&amp;lt;len-i-1; ++j) {
            if (array[j] &amp;gt; array[j+1])
                Swap(array[j], array[j+1]);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;重点理解总共需要len-1轮, 而每一轮是内部全比较(除了上一轮的最轻元素，它已经在最顶部)，浮出相对最轻气泡.&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;这里所有的｀相对最轻&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;、&lt;/code&gt;相对最重&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;、&lt;/code&gt;相对顶部&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;等里的&lt;/code&gt;相对`
    &lt;ul&gt;
      &lt;li&gt;是指: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;每一轮和上一轮找到上浮最轻的元素到顶部或者下沉最重的元素到顶部后，剩下的元素之间比较，浮出此时的最轻或下沉此时的最重.&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五参考&quot;&gt;五、参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/冒泡排序&quot;&gt;维基百科-冒泡排序(下沉法)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-3-bubblesort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-3-bubblesort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之2 希尔排序(Shell Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;希尔排序是插入排序的一种改进算法, 是非稳定排序.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;s2&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;p&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;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二基础&quot;&gt;二、基础&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/2015/10/04/One-out-of-eight-kinds-of-algorithm-1-insertsort.html&quot;&gt;直接插入排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;div class=&quot;language-c 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;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ShellSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 用gap分分组, 分组gap个组&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;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;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;o&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;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 每组进行直接插入排序, 每组相邻元素相差gap个元素&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// i从gap到len-1, 然后从后往前进行插入排序&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 为什么不是i从0到gap-1呢，因为如果数组array是基数，这样就无法获取到最后一个元素，i从gap到len-1则可以，无论什么情况，数组最好一个元素是a[len-1]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 与普通直接插入排序(步长为1)的区别是，每组元素其实相差gap个单位(步长为gap)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  普通: a[1], a[2], a[3], [a4] a[5] a[6] a[7] a[8] a[9]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  希尔排序中(假设第一步步长为3):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//      第一步(步长: 3):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          a[0] a[3] a[6]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          a[1] a[4] a[7]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          a[2] a[5] a[8]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          a[9] &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          (分组进行直接插入排序)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//      第二步(步长: 3/2=1) (步长等于1(&amp;gt;0)最后一步, 相当于普通插入排序):&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//          a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 最后一个无序变量&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 插入到前面i/gap个元素的有序列表中, 变成i/gap+1个元素的有序列表&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 如果 gap = 1, 则是最后一步，也就是整个数组直接插入排序&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&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;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gap&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;n&quot;&gt;temp&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;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    希尔排序其实就是分gap次(2^gap&amp;lt;=len), 每次new_gap(=gap, gap/=2)个分组的直接插入排序,最终new_gap=1时，就是最直接的直接插入排序.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;参考&quot;&gt;参考&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net/morewindows/article/details/6668714&quot;&gt;白话经典算法系列之三 希尔排序的实现&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zh.wikipedia.org/wiki/希尔排序&quot;&gt;维基百科-希尔排序&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-2-shellsort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-2-shellsort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之1-2 折半插入排序(Binary Insert Sort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;在&lt;a href=&quot;/2015/10/04/One-out-of-eight-kinds-of-algorithm-1-insertsort.html&quot;&gt;直接插入排序&lt;/a&gt;的基础上，与其通过从后往前一一比较(或比较交换交换), 折半插入排序则利用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;折半查找(BinarySearch)&lt;/code&gt;的(low, high)确定带插入的数字的位置hight+1，是比middle小(左半部分)还是大(右半部分)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础-折半查找法直接插入排序&quot;&gt;二、基础: 折半查找法+直接插入排序&lt;/h3&gt;

&lt;div class=&quot;language-c 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;// 折半查找(BinarySearch)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BinarySearch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&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;c1&quot;&gt;// 标记元素:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//      low: &quot;第一个&quot;元素下标&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//      high: &quot;最后一个&quot;元素下标&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//      middle: low和high中间的元素下标(low + high)/2&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;low&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;n&quot;&gt;high&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// 注意条件: low 小于等于 high&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//  Why:&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//      假设数组a共两个元素(0, 1), 那么low=0, high=1,&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//          如果BinarySearch查找0, middle=(low+high)/2=0, a[middle]==0, 找到;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//          如果BinarySearch查找1, middle=(low+high)/2=0, a[middle] &amp;lt; 1, 这时low=middle + 1 = 1, 也即low==high, 新middle=1, a[middle]==1, 找到.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;high&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;n&quot;&gt;middle&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;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;high&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;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&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;c1&quot;&gt;// 如果待查找的值value小于中间值，&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//  则说明value在low-&amp;gt;middle-1之间, 也就是左半部分(假设low左, hight右);&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//      (middle-1, 是因为middle已经不等于value, 没有必要了)&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//  则更新high = middle - 1, 继续循环&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&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;c1&quot;&gt;// 如果待查找的值value大于中间值,&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//  则说明value在middle+1-&amp;gt;high之间, 也就是右半部分&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//  更新low = middle + 1, 继续循环&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// 待查找的值等于中间值a[middle], 找到&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;序号: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&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;span class=&quot;c1&quot;&gt;// 查找完整个数组，并未找到待查找的值value&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&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;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;div class=&quot;language-c 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;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;BinaryInsertSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&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;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&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;n&quot;&gt;i&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;low&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;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 已知哨兵应该插入的位置是high+1, &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  利用折半查找确定high这个位置&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;high&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;n&quot;&gt;middle&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;n&quot;&gt;low&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;high&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;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&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;else&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;low&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;middle&lt;/span&gt; &lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 找到存放哨兵guard值(其实是a[i]的值)的位置: high + 1&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 那么将a[high+1...i-1]后移一位 -&amp;gt; a[high+2...i]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 再将guard插入a[high+1]&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 因为guard是a[i], 所以不会存在溢出或覆盖问题&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 插入guard&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;high&lt;/span&gt; &lt;span class=&quot;o&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;guard&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;

&lt;div class=&quot;language-bash 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;sb&quot;&gt;`&lt;/span&gt;折半查找&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;BinarySearch&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;快速找到插入点high+1, 
    比直接插入排序从后往前一一对比&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;
</description>
    <link>/2015/10/05/one-out-of-eight-kinds-of-algorithm-1-1-halfinsertsort.html</link>
    <guid>/2015/10/05/one-out-of-eight-kinds-of-algorithm-1-1-halfinsertsort</guid>
    <pubDate>Mon, 05 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>八种排序算法之1 直接插入排序(StraightInsertSort)</title>
    <description>
&lt;h3 id=&quot;一基本思想&quot;&gt;一、基本思想&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;每次将一个待排序的记录a[i]，插入到前面已经排好序的子序列a[0…i-1]中的适当位置, 知道全部记录插入完成为止(i==n为止).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;复杂度&quot;&gt;复杂度&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;时间复杂度:
    &lt;ul&gt;
      &lt;li&gt;O(n^2)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;空间复杂度:
    &lt;ul&gt;
      &lt;li&gt;O(1)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二基础-有序列表插入单个元素&quot;&gt;二、基础: 有序列表插入单个元素&lt;/h3&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/*
 * 这里: a[0...n-2]为有序元素, a[n-1]为无序的
 * Why:
 *    将value插入到a[0...m-1], 
 *    如果n-2=m-1的话, 就是value插入到a[0...n-2],
 *    很明显，
 *      最终的元素个数: n个(a[0...n-1]), 
 *          (n = n-1(a[0-n-1]的元素) + 1(待插入的元素)) 
 *    其实也就是就是其实是将a[n-1]插入到有序列表a[0...n-2]中, 
 *
 *  现在将一个元素value插入到a[0..m-1] (n = m + 1)
 *   等价于
 *  将a[n-1]插入到a[0...n-2]中
 *
 * 求解步骤:(默认: 从小到大)
 *  Step 1: 令j = n-1 -&amp;gt; 0 (n个元素) (如果j=n-&amp;gt;0, 说明有n+1个元素)
 *  step 2:
 *      如果 a[j] &amp;gt; a[j-1], 说明a[0...j]已经是有序的 (a[0...j-1]是有序的), 跳出;
 *      如果 a[j] &amp;lt; a[j-1], 也就是a[j]比a[j-1]小, 说明a[j]应该排在a[j-1]前面, 那么交换a[j]和a[j-1];
 *
 * */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;SortedListInsertElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&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;c1&quot;&gt;// 总共n个元素：0 -&amp;gt; n-1, a[n-1]是最后一个元素&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// a[n-1]为乱序，a[0...n-2]为有序&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;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;n&quot;&gt;j&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;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;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;h3 id=&quot;三解题方法&quot;&gt;三、解题方法&lt;/h3&gt;

&lt;h4 id=&quot;1循环法默认从小到大排序&quot;&gt;(1)、循环法(默认从小到大排序)&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;设数组为a[0…n-1]
    &lt;ul&gt;
      &lt;li&gt;Step 1: 初始时, a[0]自成1个有序子序列, 无序区为a[i…n-1].令i=1&lt;/li&gt;
      &lt;li&gt;Step 2: (有序列表插入一个元素)将a[i]插入当前有序子序列a[0…i-1]中，形成a[0…i]的有序子序列;此时无序区为a[i+1…n-1], i=i+1, 执行第三步&lt;/li&gt;
      &lt;li&gt;Step 3: 循环重复第二步,知道i==n-1,排序完成&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/* 以下两个有序列表插入元素的方法 */&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
  有序列表插入元素1:
    将a[i]插入已经排好序的序列a[0...i-1]中，形成有序的a[0...i]
        start = 0; // 默认第一个元素
        end = i - 1; // a[0...i-1]中的最后一个元素a[i-1]的下标
        wait = i; // 等待插入的元素
*/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;insertAndSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wait&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;c1&quot;&gt;// 在 j 从 end -&amp;gt; start 中&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&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;c1&quot;&gt;// 如果 a[wait] 大于 a[j], 那么对于有序列表来说j前面的都比wait小，&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// j是比wait小的最后一位,&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 也就是wait前(0...j)都比wait小，wait后(j+1...n-1)都比wait大, &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// (从小到大排序)说明wait应该排在j后面以为,也就是j+1位,&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// 但是前提要先把j+1到end后移一位&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wait&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;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// 将j+1到end后移一位&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&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;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// wait排在j后面一位&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wait&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;cm&quot;&gt;/*
  有序列表插入元素2:
    1.假设有序列表a原来有m-1个元素(0...m-2), 插入一个元素x以后，最终有m个元素(0...m-1); 
    2.那么不妨在插入之前，将x写成a[m-1]=x (总共m个元素, m-1是最后一个元素);
    3.这时也就是将a[m-1]插入到a[0...m-2]之间了.
    4.又因为a[0...m-2]已经是排好序的有序列表, 假设最后一个元素j=m-1, 也即a[0...j-1]是有序的, 那么只要
        * 如果a[j] &amp;gt; a[j-1], 说明a[0...j]这m个元素已经是有序的了,跳出
        * 如果a[j] &amp;lt; a[j-1], 说明后一个元素比前一个元素小，只要交换即可; 然后j=j-1, 重复重复该步骤(4)
*/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;InsertAndSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;c1&quot;&gt;// 总共i个元素, a[i-1]是最后一个元素&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;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;n&quot;&gt;j&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;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;swap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&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;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/* 直接插入排序 */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;InsertSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Step 1, Step 3&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&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;n&quot;&gt;i&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;c1&quot;&gt;// Step 2: 有序列表插入元素&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 有序列表插入元素1: 比较笨，找到中间并后移&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  insertAndSort(a, 0, i-1, i);&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// 有序列表插入元素2: 比较灵活, 将a[0..i]个元素从后往前交换&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;insertAndSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&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;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;h4 id=&quot;2递归法&quot;&gt;(2)、递归法&lt;/h4&gt;

&lt;div class=&quot;language-c 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;cm&quot;&gt;/**
    数组a, 有n个元素, a[0...n-1]
*/&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;InsertSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&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;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&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;return&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;n&quot;&gt;InsertSort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&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;c1&quot;&gt;// 主要插入有序列表动作&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;SortedListInsertElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&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;h3 id=&quot;四总结&quot;&gt;四、总结&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;掌握有序列表插入一个元素是基础，但很重要，初学仔细体会.&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/10/04/One-out-of-eight-kinds-of-algorithm-1-insertsort.html</link>
    <guid>/2015/10/04/One-out-of-eight-kinds-of-algorithm-1-insertsort</guid>
    <pubDate>Sun, 04 Oct 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>为HuaWei HG255D 路由器编译 Openwrt 固件</title>
    <description>
&lt;h3 id=&quot;参考资料&quot;&gt;参考资料&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://wiki.openwrt.org/doc/start&quot;&gt;官方文档&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://wiki.openwrt.org/doc/howto/easy.build&quot;&gt;Easy Build&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://wiki.openwrt.org/doc/howto/obtain.firmware.generate&quot;&gt;Image Generator&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk&quot;&gt;SDK&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.cnphp6.com/archives/27122&quot;&gt;HG255D配置修改&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;其他
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://my.oschina.net/zuobz/blog/208034&quot;&gt;Man 1&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.jianshu.com/p/66c7b0969a31&quot;&gt;Man 2&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/whatwewant/ShadowVPN&quot;&gt;Openwrt ShadowVPN&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/shadowsocks/openwrt-shadowsocks&quot;&gt;Openwrt Shadowsocks&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/liuqun/openwrt-clients&quot;&gt;Openwrt njit8021xclient&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://downloads.openwrt.org&quot;&gt;官方固件地址&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://downloads.openwrt.org/barrier_breaker/14.07/ramips/rt305x/&quot;&gt;ramips&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;搜索引擎:
    &lt;ul&gt;
      &lt;li&gt;Google&lt;/li&gt;
      &lt;li&gt;百度(中文信息较多)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;相关网站:
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/&quot;&gt;Stackoverflow&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.openwrt.org.cn/bbs/&quot;&gt;Openwrt中文网技术论坛&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.right.com.cn/&quot;&gt;恩山论坛&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.jianshu.com/&quot;&gt;简书&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.oschina.net&quot;&gt;开源中国社区&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://blog.csdn.net&quot;&gt;CSDN&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;其他&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;一openwrt-版本&quot;&gt;一、Openwrt 版本&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://downloads.openwrt.org/barrier_breaker/14.07/&quot;&gt;Barrier Breaker 14.07&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;另:
    &lt;ul&gt;
      &lt;li&gt;当然也可以是Chaos Calmer 15.05或trunk, 但是好像后面的都不支持了&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二路由信息&quot;&gt;二、路由信息&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Machine:
    &lt;ul&gt;
      &lt;li&gt;HuaWei HG255D&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;CPU型号(Target System)
    &lt;ul&gt;
      &lt;li&gt;Ralink RT3052 id:1 rev:3&lt;/li&gt;
      &lt;li&gt;属于 Ramips&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三交叉编译环境搭建&quot;&gt;三、交叉编译环境搭建&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;OS:
    &lt;ul&gt;
      &lt;li&gt;Ubuntu 14.04&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;所需依赖:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;subversion &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    build-essential &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    libncurses5-dev &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    zlib1g-dev &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    gawk &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    git &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    ccache &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    gettext &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    libssl-dev &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    xsltproc &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    file &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    unzip &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    flex &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    quilt &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    libxml-parser-perl &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    mercurial &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    bzr &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    ecj &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    cvs &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    python &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                    wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四下载openwrt源码以及编译&quot;&gt;四、下载Openwrt源码以及编译&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Infomation:
    &lt;ul&gt;
      &lt;li&gt;Version: barrier_breaker&lt;/li&gt;
      &lt;li&gt;Kernel: 3.10.x&lt;/li&gt;
      &lt;li&gt;Support HuaWei HG255D: Y&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;具体步骤&quot;&gt;具体步骤&lt;/h4&gt;

&lt;div class=&quot;language-bash 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;# Step 1: 下载源码&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; ~/openwrt
    &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; ~/openwrt
    &lt;span class=&quot;c&quot;&gt;# 下载barrier_breaker分支，当然你可以选择trunk(开发分支)或者其他分支&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 开发分支: svn://svn.openwrt.org/openwrt/trunk&lt;/span&gt;
    svn co &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; 36088 svn://svn.openwrt.org/openwrt/branches/barrier_breaker
    &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;barrier_breaker
    
&lt;span class=&quot;c&quot;&gt;# Step 2: 更新软件包&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# *******************&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 提示: 最好在VPS上或者挂VPN, 可能有些更新不了&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# *******************&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 更新种子&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 相关文件: feeds.conf.default&lt;/span&gt;
    ./scripts/feeds update &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 下载更新&lt;/span&gt;
    ./scripts/feeds &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt;
    
&lt;span class=&quot;c&quot;&gt;# Step 3: 生成默认配置&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    make clean &lt;span class=&quot;c&quot;&gt;# 清除&lt;/span&gt;
    make defconfig &lt;span class=&quot;c&quot;&gt;# 非必须&lt;/span&gt;
    
&lt;span class=&quot;c&quot;&gt;# Step 4: 进入配置菜单进行配置&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#   1、在这一步之前，修改一些配置以适应HG255D，非常重要&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 具体见 为HG255D修改配置&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#   2、选择shadowsocks、shadowvpn、njit8021xclient: 见七、自己添加的包&lt;/span&gt;
    make menuconfig
    &lt;span class=&quot;c&quot;&gt;#   2.1、如果需要修改包，请参见 十、对一些包的修改&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#　 3、选择基础包: 见六、固件推荐包&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;##&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 仔细阅读以上3条,再继续; Or Exit&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# &lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 基础信息&lt;/span&gt;
    Target System &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;Ralink RT288x/RT3xxx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    Subtarget &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;RT3x5x/RT5350 based boards&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    Target Profile &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;HuaWei HG255D&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    Target Image &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; squashfs
    
    &lt;span class=&quot;c&quot;&gt;############################&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 以下个人建议推荐 begin&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Advanced configuration options &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;developers&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;# 从ImageBuilder构建固件,这个非常好用，&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 见八、从[ImageGenerator](http://wiki.openwrt.org/doc/howto/obtain.firmware.generate)生成固件&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Build the OpenWrt Image Builder
    
    &lt;span class=&quot;c&quot;&gt;# SDK可用于直接编译所需要的包,也就是不在需要源码，只要SDK和包&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 见九、从[SDK](http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk)编译软件包&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Build the OpenWrt SDK
    
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Build the Openwrt based Toolchain
    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Image configuration
    &lt;span class=&quot;c&quot;&gt;# 推荐 end&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;############################&lt;/span&gt;
    
    &lt;span class=&quot;c&quot;&gt;# 推荐的包&lt;/span&gt;
    Base System &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; base-files
                    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; block-mount
                    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; dnsmasq
    &lt;span class=&quot;c&quot;&gt;# Base System --&amp;gt; [*] dnsmasq-dncpv6&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# Base System --&amp;gt; [*] bridge&lt;/span&gt;
    Administration &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;#                   [*] syslog-ng3&lt;/span&gt;
    Kernel modules &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; FIlesystems &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-fs-ext4
                                        &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-fs-ntfs
                                        &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-fs-vfat
                   &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; LED modules &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-leds-gpio
                                        &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-ledtrig-default-on
                                        &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-ledtrig-gpio
                                        &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-ledtrig-heartbeat
                   &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Network Support &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-pptp
                                           &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-tun &lt;span class=&quot;c&quot;&gt;# For ShadowVPN&lt;/span&gt;
                   &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; USB Support &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-usb2
                   &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Wireless Drivers &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-rt2800-soc
                                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-rtl8187
                                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; kmod-rt73-usb
    Language &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Python &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; ipython &lt;span class=&quot;c&quot;&gt;# 是否嵌入Python，自己决定&lt;/span&gt;
                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; python　# 只作为模块编译[&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M]
                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] python-django
                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] python-mysql
                            &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] python-sqlite3
             &lt;span class=&quot;c&quot;&gt;# --&amp;gt; PHP&lt;/span&gt;
             &lt;span class=&quot;c&quot;&gt;# --&amp;gt; Lua 默认即可&lt;/span&gt;
             &lt;span class=&quot;c&quot;&gt;# --&amp;gt; Javascript&lt;/span&gt;
    Libraries &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; database &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; libsqlite3
    LUCI &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Collections &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci
                             &lt;span class=&quot;c&quot;&gt;# [*] luci-ssl # https支持&lt;/span&gt;
         &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Applications &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-chinadns
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-commands &lt;span class=&quot;c&quot;&gt;# LuCI Shell Commands&lt;/span&gt;
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-ddns &lt;span class=&quot;c&quot;&gt;# 动态DNS&lt;/span&gt;
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-firewall &lt;span class=&quot;c&quot;&gt;# 防火墙&lt;/span&gt;
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-p2pblock
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-polipo
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-qos
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-radvd
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-redsocks2
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-shadowsocks-spec
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] luci-app-shadowvpn &lt;span class=&quot;c&quot;&gt;# ShadowVPN有BUG,不宜内建&lt;/span&gt;
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-samba &lt;span class=&quot;c&quot;&gt;# 好像编译会出错,不选&lt;/span&gt;
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-tinyproxy
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-transmission
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-upnp
                              &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-app-wol
         &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Themes &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-theme-bootstrap
         &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Translations &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; luci-i18n-chinese
    Network &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; BitTorrent &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; transmission-daemon
                               &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; transmission-web
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Captive Portals &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; wifidog &lt;span class=&quot;c&quot;&gt;# ...&lt;/span&gt;
                                    &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] wifidog-auth
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; File Transfer &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; aria2 &lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;
                              &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; curl
                              &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; vsftpd
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; SSH &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; autossh
                    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; openssh-keygen
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; VPN &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; pptpd
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] chaosvpn&lt;/span&gt;
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] l2tpd&lt;/span&gt;
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] l2tpns&lt;/span&gt;
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] n2n&lt;/span&gt;
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] openvpn-* # 我不想要，麻烦&lt;/span&gt;
                    &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] xl2tpd&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Version Control Systems &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] git
                                        &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] subversion-libs
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Web Servers/Proxies &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# [M] apache # 下载不了&lt;/span&gt;
                                    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] nginx
                                    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] redsocks
                                    &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 其他默认
            &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; dial-in/up &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 尚且不知学不需要
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; ChinaDNS
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] ShadowVPN
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; agan8021xclient
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; mentohust
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; netcat &lt;span class=&quot;c&quot;&gt;# nc&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; njit8021xclient
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; odhcp6c
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; odhcpd
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; ppp-mod-pppoe
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; ppp-mod-pptp
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; redsocks2
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] shadowsocks-libev
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] shadowsocks-libev-polarssl
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadowsocks-libev-spec
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] shadowsocks-libev-spec-polarssl
          &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [M] wpa-cli&lt;/span&gt;
          &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [M] wpa-supplicant&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; wpad
          &lt;span class=&quot;c&quot;&gt;# --&amp;gt; [*] wpad-mini # IEEE 802.1x Authenticator/Supplicant(WPA-PSK only)&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; Utilities &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; database &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] mysql-server
                                   &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; sqlite3-cli
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; backup &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] rsnapshot
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] bash
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadow-passwd
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadow-su
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadow-useradd
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadow-userdel
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; shadow-usermod
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] squashfs-tools-mksquashfs
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] squashfs-tools-unsquashfs
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; tessert &lt;span class=&quot;c&quot;&gt;# 下载不了&lt;/span&gt;
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] tmux
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; wifitoggle
                      &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] zsh

&lt;span class=&quot;c&quot;&gt;# Step 5: 下载所需要的软件源码&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 最好在VPS或通过VPN下载&lt;/span&gt;
    make download &lt;span class=&quot;nv&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;99 &lt;span class=&quot;c&quot;&gt;# V=99 == V=s, 输出所有信息&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Step 6: 开始编译&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 其中也有些包需要联网下载，这点好像不太合适，因为应该安排在上一步，怪作者..&lt;/span&gt;
    make &lt;span class=&quot;nv&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;99 
    &lt;span class=&quot;c&quot;&gt;# 建议 make -j 4 V=99 # 主流机器都支持 -j 4, 比直接make V=99快很多&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Step 7: 如果有错误&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 可以 make menuconfig 入后 输入 /, 查找并去除出错的包&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 然后再make -j 4 V=99即可，最好不用make clean, 否则之前编译的包都没了&lt;/span&gt;
    
&lt;span class=&quot;c&quot;&gt;# Step 8&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 在 bin/ramips/下查找&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# 可安装固件:&lt;/span&gt;
        openwrt-ramips-rt305x-hg255d-squashfs-sysupgrade.bin
    &lt;span class=&quot;c&quot;&gt;# 软件包文件夹:&lt;/span&gt;
        packages/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# SDK&lt;/span&gt;
        OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
    &lt;span class=&quot;c&quot;&gt;# ImageBuilder&lt;/span&gt;
        OpenWrt-ImageBuilder-ramips_rt305x-for-linux-x86_64.tar.bz2
    &lt;span class=&quot;c&quot;&gt;# Toolchain&lt;/span&gt;
        OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
    &lt;span class=&quot;c&quot;&gt;# 不知道的文件&lt;/span&gt;
        openwrt-ramips-rt305x-uImage.bin
        openwrt-ramips-rt305x-vmlinux.bin
        等
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五为huawei-hg255d修改配置&quot;&gt;五、为HuaWei HG255D修改配置&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1、打开对HG255D板的支持
    &lt;ul&gt;
      &lt;li&gt;File: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target/linux/ramips/image/Makefile&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Image/Build/Profile/HG255D=$(call BuildFirmware/Default16M/$(1),$(1),hg255d,HG255D)
...
$(call Image/Build/Profile/HG255D,$(1))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2、修改源码脚本的错误
    &lt;ul&gt;
      &lt;li&gt;File: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target/linux/ramips/base-files/lib/ramips.sh&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;将

*&quot;HG255D&quot;)
    name=&quot;hg255d&quot;
    ;;

修改为

*&quot;HuaWei HG255D&quot;
    name=&quot;hg255d&quot;
    ;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3、解决电源LED灯不能正常工作的问题
    &lt;ul&gt;
      &lt;li&gt;File: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target/linux/ramips/base-files/etc/diag.sh&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;在
    hlk-rm04&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;status_led&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hlk-rm04:red:power&quot;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;;;&lt;/span&gt;
下添加
    hg255d&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;status_led&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hg255d:power&quot;&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;ul&gt;
  &lt;li&gt;4、设置默认打开Wlan, 密码为空
    &lt;ul&gt;
      &lt;li&gt;File: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package/kernel/mac80211/files/lib/wifi/mac80211.sh&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;注释 option disabled 0 即可

# option disabled 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5、添加root账号密码为admin
    &lt;ul&gt;
      &lt;li&gt;File: package/base-files/files/etc/shadow&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;将
    root::0:0:99999:7:::
修改为
    root:&lt;span class=&quot;nv&quot;&gt;$1$21u5EotL$B9ebsVgEQe&lt;/span&gt;.C7lsk0iMf10:0:0:99999:7:::
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六固件推荐软件包&quot;&gt;六、固件推荐软件包&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 添加USB挂载
    &lt;ul&gt;
      &lt;li&gt;Base system –&amp;gt; block-mount&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 添加磁盘格式支持
    &lt;ul&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Filesystems –&amp;gt; kmod-fs-ext4&lt;/li&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Filesystems –&amp;gt; kmod-fs-msdos&lt;/li&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Filesystems –&amp;gt; kmod-fs-ntfs&lt;/li&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Filesystems –&amp;gt; kmod-fs-vfat&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 语言支持
    &lt;ul&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Native Language Support –&amp;gt; kmod-nls-utf8&lt;/li&gt;
      &lt;li&gt;LUCI –&amp;gt; Translations –&amp;gt; luci-i18n-chinese&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 网络支持
    &lt;ul&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Network Support –&amp;gt; kmod-pppol2tp&lt;/li&gt;
      &lt;li&gt;Kernel modules –&amp;gt; Network Support –&amp;gt; kmod-pptp&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 USB支持
    &lt;ul&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;kernel-modulesusb-supportkmod-usb-hid&quot;&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-hid&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;kernel-modulesusb-supportkmod-usb-printer&quot;&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-printer&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;kernel-modulesusb-supportkmod-usb-serial---usb转串口&quot;&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-serial  # usb转串口&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;kernel-modulesusb-supportkmod-usb-serial-cp210x&quot;&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-serial-cp210x&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;kernel-modulesusb-supportkmod-usb-serial-pl2303&quot;&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-serial-pl2303&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-storage&lt;/li&gt;
      &lt;li&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb-storage-extras&lt;/li&gt;
      &lt;li&gt;Kernel modules–&amp;gt;USB Support–&amp;gt;kmod-usb2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6 USB无线网卡驱动
    &lt;ul&gt;
      &lt;li&gt;Kernel modules–&amp;gt;Wireless Drivers–&amp;gt;kmod-rt2800-usb&lt;/li&gt;
      &lt;li&gt;Kernel modules–&amp;gt;Wireless Drivers–&amp;gt;kmod-rt73-usb&lt;/li&gt;
      &lt;li&gt;Kernel modules–&amp;gt;Wireless Drivers–&amp;gt;kmod-rtl8187&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7 添加libffmpeg-mini支持ushare需要
    &lt;ul&gt;
      &lt;li&gt;Libraries–&amp;gt;libffmpeg-mini&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8 LUCI (网页管理)
    &lt;ul&gt;
      &lt;li&gt;LuCI–&amp;gt;Collections–&amp;gt;luci&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-ddns&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-hd-idle&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-multiwan&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-ntpc&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-p910nd&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-qos&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-samba&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-tinyproxy&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-upnp&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-ushare&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Applications–&amp;gt;luci-app-wol&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Themes–&amp;gt;luci-theme-bootstrap&lt;/li&gt;
      &lt;li&gt;LuCI–&amp;gt;Translations–&amp;gt;luci-i18n-chinese&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9 Network
    &lt;ul&gt;
      &lt;li&gt;Network –&amp;gt; File Transfer –&amp;gt; aria2&lt;/li&gt;
      &lt;li&gt;
        &lt;h1 id=&quot;network--printing--cups-locale-zh&quot;&gt;Network –&amp;gt; Printing –&amp;gt; cups-locale-zh&lt;/h1&gt;
      &lt;/li&gt;
      &lt;li&gt;Network –&amp;gt; VPN –&amp;gt; pptpd&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10 Utilities
    &lt;ul&gt;
      &lt;li&gt;Utilities–&amp;gt;Filesystem–&amp;gt;badblocks#自动挂载工具&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;Filesystem–&amp;gt;mkdosfs&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;Filesystem–&amp;gt;ntfs-3g#ntfs读写&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;disc–&amp;gt;fdisk#分区工具&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;disc–&amp;gt;findfs&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;disc–&amp;gt;hdparm&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;lrzsz #上传下载工具&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;restorefactory#reset键支持(长按5秒以上就可以恢复固件默认设置)&lt;/li&gt;
      &lt;li&gt;Utilities–&amp;gt;wifitoggle #添加一键开关无线(按一下WPS键放开无线就打开或者关闭)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七自己添加的软件注意-package是源码根目录的package&quot;&gt;七、自己添加的软件(注意: package是源码根目录的package)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1、&lt;a href=&quot;https://github.com/aa65535/openwrt-shadowvpn&quot;&gt;ShadowVPN&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/aa65535/openwrt-shadowvpn.git package/shadowvpn&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bug: 不能作为内建(build-in)软件, 否则编译出的固件很多问题，暂时无法解决&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;可以作为生成模块, 即[M]&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2、&lt;a href=&quot;https://github.com/aa65535/openwrt-chinadns&quot;&gt;ChinaDns&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/aa65535/openwrt-chinadns.git package/chinadns&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3、&lt;a href=&quot;https://github.com/aa65535/openwrt-dnsmasq&quot;&gt;dnsmasq&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/aa65535/openwrt-dnsmasq.git package/dnsmasq&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4、&lt;a href=&quot;https://github.com/aa65535/openwrt-redsocks2&quot;&gt;redsocks2&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/aa65535/openwrt-redsocks2.git package/redsocks2&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5、&lt;a href=&quot;https://github.com/shadowsocks/openwrt-shadowsocks&quot;&gt;shadowsocks&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/shadowsocks/openwrt-shadowsocks.git package/shadowsocks-libev&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6、&lt;a href=&quot;https://github.com/aa65535/openwrt-dist-luci&quot;&gt;ShadowVPN ChinaDns dnsmasq redsocks2 shadowsocks的luci&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/aa65535/openwrt-dist-luci.git package/openwrt-dist-luci&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7、&lt;a href=&quot;https://github.com/liuqun/openwrt-clients&quot;&gt;njit-client&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;方法一: 只可以编译软件包，请不要内建，否则编译出错
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone https://github.com/liuqun/openwrt-clients package/openwrt-clients&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;Bug: 编译无法通过，失败&lt;/li&gt;
          &lt;li&gt;但是直接编译包却可以: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make package/openwrt-clients/njit/njit8021xclient/compile V=99&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;(推荐)方法二、在feeds.conf.default中添加
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src-svn njit https://github.com/liuqun/openwrt-clients/trunk/njit&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src-svn hust https://github.com/liuqun/openwrt-clients/trunk/hust&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src-svn gdou https://github.com/liuqun/openwrt-clients/trunk/gdou&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src-svn sysu https://github.com/liuqun/openwrt-clients/trunk/sysu&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;然后 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./scripts/feeds update -a; ./scripts/feeds install -a&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;八从imagebuilder包生成image固件&quot;&gt;八、从ImageBuilder包生成Image(固件)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;File: OpenWrt-ImageBuilder-ramips_rt305x-for-linux-x86_64.tar.bz2&lt;/li&gt;
  &lt;li&gt;解压:
    &lt;ul&gt;
      &lt;li&gt;tar -xvf OpenWrt-ImageBuilder-*&lt;/li&gt;
      &lt;li&gt;cd OpenWrt-ImageBuilder-*&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;生成Image
    &lt;ul&gt;
      &lt;li&gt;make image PROFILE=HG255D # HG255D为路由器名字, 默认只有基础包&lt;/li&gt;
      &lt;li&gt;make image PROFILE=HG255D PACKAGES=”pk1 pk2 pk3 -pk4” # -pk4表示去掉pk4包&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; make image &lt;span class=&quot;nv&quot;&gt;PROFILE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;HG255D &lt;span class=&quot;nv&quot;&gt;PACKAGES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;kmod-tun zlib libopenssl libpthread ip luci luci-i18n-chinese luci-app-firewall curl vsftpd ntfs-3g autossh netcat python pptpd ChinaDNS luci-app-chinadns redsocks2 luci-app-redsocks2 shadowsocks-libev-spec luci-app-shadowsocks-spec transmission-web luci-app-transmission luci-app-upnp luci-app-qos wifidog openssh-keygen sqlite3-cli sudo shadow-common shadow-su shadow-useradd shadow-userdel shadow-usermod&quot;&lt;/span&gt;
 &lt;span class=&quot;c&quot;&gt;# 注意, 不要加入ShadowVPN包，会造成固件很多问题，重启后配置丢失, LED灯不正常, POWER灯一直闪让我以为坏掉，其实是正常的等&lt;/span&gt;
 &lt;span class=&quot;c&quot;&gt;# luci-app-shadowvpn 最好也不要&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;九从sdk编译生成软件包&quot;&gt;九、从SDK编译生成软件包&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;好处:
    &lt;ul&gt;
      &lt;li&gt;如果只要编译某些包，这样简单方便多了&lt;/li&gt;
      &lt;li&gt;只用于编译生成软件包&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;File: OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2&lt;/li&gt;
  &lt;li&gt;解压:
    &lt;ul&gt;
      &lt;li&gt;tar -xvf OpenWrt-SDK-ramips-*&lt;/li&gt;
      &lt;li&gt;cd OpenWrt-SDK-ramips-*&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;编译包: 假定包已经在package/中, 叫njit8021xclient
    &lt;ul&gt;
      &lt;li&gt;make package/njit8021xclient/compile V=99&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;# 栗子一、编译ShadowVPN&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 获取 Makefile&lt;/span&gt;
git clone https://github.com/aa65535/openwrt-shadowvpn.git package/shadowvpn
&lt;span class=&quot;c&quot;&gt;# 选择要编译的包 Network -&amp;gt; ShadowVPN&lt;/span&gt;
make menuconfig
&lt;span class=&quot;c&quot;&gt;# 开始编译&lt;/span&gt;
make package/shadowvpn/compile &lt;span class=&quot;nv&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;99

&lt;span class=&quot;c&quot;&gt;# 栗子二、编译njit8021xclient&lt;/span&gt;
git clone https://github.com/liuqun/openwrt-clients package/openwrt-clients
&lt;span class=&quot;c&quot;&gt;# 选择要编译的包 Network -&amp;gt; njit8021xclient&lt;/span&gt;
make menuconfig
make package/openwrt-clients/njit/njit8021xclient/compile &lt;span class=&quot;nv&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;99
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;十对一些包的修改&quot;&gt;十、对一些包的修改&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 修改shadowsocks, 使其生成ss-server&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;找到
    ss-&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;local&lt;/span&gt;,redir,tunnel&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
修改为
    ss-&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;server,local,redir,tunnel&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 修改shadowvpn, 它的配置好像有问题
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/whatwewant/ShadowVPN/tree/master/samples&quot;&gt;下载client/server配置文件&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;有关client* 和 server*的文件(共留个)&lt;/li&gt;
          &lt;li&gt;client.conf&lt;/li&gt;
          &lt;li&gt;client_up.sh&lt;/li&gt;
          &lt;li&gt;client_down.sh&lt;/li&gt;
          &lt;li&gt;server.conf&lt;/li&gt;
          &lt;li&gt;server_up.sh&lt;/li&gt;
          &lt;li&gt;server_down.sh&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;将client&lt;em&gt;和server&lt;/em&gt;文件(6个文件)移动到 package/ShadowVPN/files下&lt;/li&gt;
      &lt;li&gt;修改Makefile文件，见下文&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 该包有BUG, 不能内建&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;一、如果opkg安装ShdowVPN_*.ipk出错，可能造成很多，命令不能用, 如不能重启(reboot)等，不用惊慌, 只要 opkg remove ShadowVPN即可&lt;/li&gt;
          &lt;li&gt;二、如果安装出错了，请尝试opkg重新安装, 然后/etc/init.d/shadowvpn disable 或者 rm -rf /etc/rc.d/*shadowvpn, 然后关闭电源重启即可&lt;/li&gt;
          &lt;li&gt;三、如果再出错，重复解决方法一, 然后tar -zxvf ShadowVPN&lt;em&gt;, 然后tar -zxvf data.tar.gz -C /, 然后/etc/init.d/shadowvpn 或者 rm -rf /etc/rc.d/&lt;/em&gt;shadowvpn, 然后关闭电源重启即可&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/client_up.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/client_up.sh
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/client_down.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/client_down.sh
修改为
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/client.conf &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/client.conf
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/client_up.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/client_up.sh
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/client_down.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/client_down.sh
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/server.conf &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/server.conf
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/server_up.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/server_up.sh
    &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;INSTALL_DATA&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; ./files/server_down.sh &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;1&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/etc/shadowvpn/server_down.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;十一遇到的问题&quot;&gt;十一、遇到的问题&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1、软件包源码下载问题解决办法
    &lt;ul&gt;
      &lt;li&gt;方法一
        &lt;ul&gt;
          &lt;li&gt;尝试修改DNS慢慢下&lt;/li&gt;
          &lt;li&gt;File: /etc/resolv.conf&lt;/li&gt;
          &lt;li&gt;开头添加: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nameserver 114.114.114.114&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;开头添加: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nameserver 8.8.4.4&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;然后继续下，只能自求多福&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;方法二
        &lt;ul&gt;
          &lt;li&gt;连接VPN&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;方法三
        &lt;ul&gt;
          &lt;li&gt;在VPS上make download, 然后tar压缩下载到本地编译, 当然也可以在服务器上编译，不过性能…&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2、有些包真心下载不了，要么不存在，要么它的服务器出问题，导致编译出错
    &lt;ul&gt;
      &lt;li&gt;例如 mentohust 在 googlecode, apache 好像下不了了&lt;/li&gt;
      &lt;li&gt;解决办法:
        &lt;ul&gt;
          &lt;li&gt;make menuconfig&lt;/li&gt;
          &lt;li&gt;输入 /&lt;/li&gt;
          &lt;li&gt;查找 mentohust, 然后将其删除即可&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3、有些包不知道出什么问题，然后导致整个固件很大问题
    &lt;ul&gt;
      &lt;li&gt;例如: ShadowVPN 导致编译出来的固件
        &lt;ul&gt;
          &lt;li&gt;重启后，配置不能保存&lt;/li&gt;
          &lt;li&gt;df -h 查看 rootfs 30M (肯定是有问题的)&lt;/li&gt;
          &lt;li&gt;reboot 等命令失效&lt;/li&gt;
          &lt;li&gt;LED灯问题: 电源灯(POWER)一直闪烁(让我以为是刷成砖了，其实不是), 其他灯不亮了&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;推测:
        &lt;ul&gt;
          &lt;li&gt;可能是/etc/rc.d/S90shadowvpn 导致的&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;解决办法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;不要将这种包内建[*], 编译成模块[M]即可&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;安装ShadowVPN包的办法: 见 十、对一些包的修改&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4、编译Error(出错)而停止
    &lt;ul&gt;
      &lt;li&gt;不用惊慌，根据前面1、2、3先解决&lt;/li&gt;
      &lt;li&gt;不用make clean, 因为已经编译过的包是没问题的，网上好多资料不准确&lt;/li&gt;
      &lt;li&gt;然后继续 make -j 4 V=99&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make -j 4 V=99&lt;/code&gt;一直出错
    &lt;ul&gt;
      &lt;li&gt;尝试: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make V=99&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6、路由器电源灯不亮 和 无线没有开启
    &lt;ul&gt;
      &lt;li&gt;见&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;五、为HuaWei HG255D修改配置&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;十二某些软件bug&quot;&gt;十二、某些软件BUG&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 编译&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tesseract&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Problem 1:
  *** No rule to make target &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;../src/liblept.la&apos;, needed by &lt;/code&gt;adaptnorm_reg’.  Stop.
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;https://dev.openwrt.org/ticket/18355&quot;&gt;解决办法&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;File: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package/feeds/oldpackages/leptonica/Makefile&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    PKG_NAME:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;leptonica
    PKG_VERSION:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1.71
    PKG_RELEASE:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1
    
    PKG_SOURCE:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;PKG_NAME&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;-&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;PKG_VERSION&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;.tar.gz
    PKG_SOURCE_URL:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;http://www.leptonica.org/source/
    PKG_MD5SUM:&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;790f34d682e6150c12c54bfe4a824f7f
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/09/28/build-openwrt-for-hg255d.html</link>
    <guid>/2015/09/28/build-openwrt-for-hg255d</guid>
    <pubDate>Mon, 28 Sep 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>work track</title>
    <description>
&lt;h3 id=&quot;week-1-20160905---20160911&quot;&gt;Week 1 (2016.09.05 - 2016.09.11)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 Done
    &lt;ul&gt;
      &lt;li&gt;@1 遵循设计风格，使用React重写UI组件，目的是为了规范化、简化以后开发，这是基石;&lt;/li&gt;
      &lt;li&gt;@2 和设计沟通，讨论符合Web开发的设计样式等, 并将其实现&lt;/li&gt;
      &lt;li&gt;@3 和Web API 后端沟通，简要讨论API的设计，希望API设计更加符合前后端对接&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 Todo
    &lt;ul&gt;
      &lt;li&gt;@1 规范
        &lt;ul&gt;
          &lt;li&gt;v1 和Design多沟通，尽早整理出符合前端的设计规范&lt;/li&gt;
          &lt;li&gt;v2 和Backend多沟通，尽早整理出符合前端的后端接口规范&lt;/li&gt;
          &lt;li&gt;v3 整理出前端合作开发规范、代码规范等&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;@2 运用并深入学习
        &lt;ul&gt;
          &lt;li&gt;v1 使用Redux管理数据，(目前数据尚未连接成功，不好管理)&lt;/li&gt;
          &lt;li&gt;v2 Redux + Immutable的学习&lt;/li&gt;
          &lt;li&gt;v3 &lt;a href=&quot;https://css-tricks.com/animate-to-an-inline-style/&quot;&gt;Inline Style无法使用动画&lt;/a&gt;
            &lt;ul&gt;
              &lt;li&gt;考虑 inline style + css modules 实现动画&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;v4 PC端UI vs 移动端UI&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;week-2-20160912---20160917&quot;&gt;Week 2 (2016.09.12 - 2016.09.17)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Done
    &lt;ul&gt;
      &lt;li&gt;用React重构首页和列表页UI&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Todo
    &lt;ul&gt;
      &lt;li&gt;UI微调, 增加Alert/Confirm&lt;/li&gt;
      &lt;li&gt;异步对接数据API(Redux + React-redux + Redux-thunk)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 Willdo
    &lt;ul&gt;
      &lt;li&gt;@1 熟练Redux数据管理&lt;/li&gt;
      &lt;li&gt;@2 React动画探索与实现&lt;/li&gt;
      &lt;li&gt;@3 重构页面(首页 + 详细页面)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/09/11/work-track.html</link>
    <guid>/2015/09/11/work-track</guid>
    <pubDate>Fri, 11 Sep 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux Command: awk</title>
    <description>
&lt;h3 id=&quot;一简介&quot;&gt;一、简介&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk&lt;/code&gt; 是处理文本数据的好工具。&lt;/li&gt;
  &lt;li&gt;相比于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sed&lt;/code&gt;常用于一整行的处理，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk&lt;/code&gt;则倾向于将一行分成数个”字段”来处理.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk&lt;/code&gt;适合处理小型的文本数据.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二语法&quot;&gt;二、语法&lt;/h3&gt;

&lt;h4 id=&quot;awk-条件类型1动作1-条件类型2动作2--filename&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk &apos;条件类型1{动作1} 条件类型2{动作2} ...&apos; filename&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk&lt;/code&gt;主要是处理每一行的字段内的数据，而默认的字段的分隔符为空格或者[tab]键.
    &lt;ul&gt;
      &lt;li&gt;案例: last取出登陆账号和IP
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last -n 5 | awk &apos;{print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;在每一行的每个字段都是有变量名的, 从$1开始, $2, $3, …&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三处理流程&quot;&gt;三、处理流程&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 读入每一行，并将第一行的数据填入变量$0, $1,$2,…中&lt;/li&gt;
  &lt;li&gt;2 依据条件类型的限制, 判断是否需要进行后面动作&lt;/li&gt;
  &lt;li&gt;3 做完所有动作与条件类型&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四内置变量&quot;&gt;四、内置变量&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;注意:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FS&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-F&lt;/code&gt;选项类似&lt;/li&gt;
      &lt;li&gt;区别是:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FS&lt;/code&gt;从第二行开始生效，如果要从第一行开始生效，则要加关键字&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BEGIN&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk &apos;BEGIN {FS=&quot;:&quot;} ...&apos; ...&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-F&lt;/code&gt;选项默认从第一行开始生效&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;栗子:
    &lt;ul&gt;
      &lt;li&gt;运用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NR&lt;/code&gt;选择指定行
        &lt;ul&gt;
          &lt;li&gt;只输出第一行: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last -n 5 | awk &apos;NR==1{print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;只输出第二行: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last -n 5 | awk &apos;NR==2{print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;运用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NF&lt;/code&gt;得出总列数&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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: left&quot;&gt;代表意义&lt;/th&gt;
      &lt;th style=&quot;text-align: left&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;NF&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;每一行($0)拥有的字段总数, 也就是总列数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;显示列数: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last -n 5 | awk &apos;{print &quot;User: &quot; $1 &quot;\t columns: &quot; NF}&apos;&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;NR&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定处理第几行数据, 也就是行号&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;显示所在行数: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last -n 5 | awk &apos;{print &quot;User: &quot; $1 &quot;\t Line: &quot; NR }&apos;&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;FS&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定分隔符，默认是空格&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;分隔符为冒号, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;awk &apos;last -n 5 | awk &apos;{FS:&quot;:&quot;} {print &quot;User: &quot; $1}&apos;&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;五逻辑运算符&quot;&gt;五、逻辑运算符&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;=&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;=&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!=&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;栗子:
    &lt;ul&gt;
      &lt;li&gt;找出/etc/passwd中UID小于10的用户和UID, 其中awk中$1是用户, $3是UID
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat /etc/passwd | awk &apos;{FS=&quot;:&quot;} $3 &amp;lt; 10 {print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;输出有误，不是从第一行开始输出，解决, 关键字&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BEGIN&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat /etc/passwd | awk &apos;BEGIN {FS=&quot;:&quot;} $3&amp;lt;10 {print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat /etc/passwd | awk -F &quot;:&quot; &apos;$3&amp;lt;10 {print $1 &quot;\t&quot; $3}&apos;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六其他高级用法&quot;&gt;六、其他高级用法:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 数字可相加，可用printf格式化&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pay.txt内容
    Name    1st     2st     3st
    VBird   2300    2400    2500
    Cole    1200    1234    1442
    Potter  1111    1122    3333
    ...

&lt;span class=&quot;c&quot;&gt;# 第一行加标题&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 第二行开始计算总和&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;cat &lt;/span&gt;pay.txt &lt;span class=&quot;nb&quot;&gt;awk&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;NR==1{printf &quot;%10s %10s %10s %10s %10s\n&quot;, $1, $2, $3, $4, &quot;Total&quot;} \
    NR&amp;gt;=2{total=$1+$2+$3+$4 printf &quot;%10s %10s %10s %10s %10s\n&quot;, $1, $2, $3, $4, total}&apos;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 注意: &lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   printf格式化字符串\n换行&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#   与bash和shell不同，awk中的自定义变量可以直接使用, 不用加$符号，如total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 支持条件判断&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat pay.txt awk &apos;{ if (NR == 1) printf &quot;%10s %10s %10s %10s %10s\n&quot;, $1, $2, $3, $4, &quot;Total&quot;} \
    NR&amp;gt;=2{total=$1+$2+$3+$4 printf &quot;%10s %10s %10s %10s %10s\n&quot;, $1, $2, $3, $4, total}&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/08/23/linux-command-awk.html</link>
    <guid>/2015/08/23/linux-command-awk</guid>
    <pubDate>Sun, 23 Aug 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>开始用 SASS 代替 CSS</title>
    <description>
&lt;h3 id=&quot;sass教程&quot;&gt;&lt;a href=&quot;http://www.w3cplus.com/sassguide&quot;&gt;SASS教程&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;一文件后缀名&quot;&gt;一、文件后缀名&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.sass&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;使用缩进, 不使用分号和大括号&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.scss&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;和css差不多，可以使用嵌套&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 1 .sass
body
    background: #eee
    font-size: 12px
p
    background: #0982c1

// 2 .scss

body {
    background: #eee;
    font-size: 12px;

    p {
        background: #0982c1;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二导入&quot;&gt;二、导入&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Syntax:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@import &apos;filename.format&apos;;&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;在sass中导入不同文件:
    &lt;ul&gt;
      &lt;li&gt;导入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.scss&lt;/code&gt;文件:
        &lt;ul&gt;
          &lt;li&gt;编译时只生成一个css文件&lt;/li&gt;
          &lt;li&gt;可以忽略后缀名: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@import &apos;a&apos;;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;导入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.css&lt;/code&gt;文件:
        &lt;ul&gt;
          &lt;li&gt;和css导入样式文件一样，导入的css文件不会合并到编译后的文件，而是以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@import&lt;/code&gt;方式存在&lt;/li&gt;
          &lt;li&gt;不能忽略后缀名&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三注释&quot;&gt;三、注释&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;单行注释: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;//&lt;/code&gt;, 不会被转义&lt;/li&gt;
  &lt;li&gt;多行注释: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/* ... */&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四变量&quot;&gt;四、变量&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Syntax:
    &lt;ul&gt;
      &lt;li&gt;sass变量必须以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&lt;/code&gt;开头, 后面紧跟&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;变量名&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;变量名&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;变量值&lt;/code&gt;用冒号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt;分开&lt;/li&gt;
      &lt;li&gt;如果值后面加上&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!default&lt;/code&gt;则表示默认值.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;普通变量&lt;/code&gt;: 定义之后可以在全局范围使用&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************** 
$fontSize: 12px;
body {
    font-size: $fontSize;
}

// css style
// *******************
body {
    font-size: 12px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;默认变量&lt;/code&gt;: sass的默认变量仅需要在后面加上&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!default&lt;/code&gt;即可
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;覆盖默认变量&lt;/code&gt;: 在使用之前重新定义变量即可&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// *********************
$baseLineHeight: 1.5 !default;
body {
    line-height: $baseLineHeight;
}

// css style
// *********************
body {
    line-height: 1.5;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass的默认变量一般是用来设置默认值
//  然后根据需要来覆盖的，覆盖方式很简单
// 只需要在默认变量使用之前重新声明变量
// *******************
// sass style
// *******************
$baseLineHeight: 1.5 !default;
$baseLineHeight: 2;
body {
    line-height: $baseLineHeight;
}

// css style
// **************************
body {
    line-height: 2;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;特殊变量&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;为属性的部分或者特殊情况修啊必须以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#{$variables}&lt;/code&gt;形式使用&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// *******************************
$borderDirection:   top !default;
$baseFontSize:      12px !default;
$baseLineHeight:    1.5 !default;

// 应用于class和属性
.border-#{borderDirection} {
    border-#{borderDirection}: 1px solid #ccc;
}

// 应用于复杂属性值
body {
    font: #{baseFontSize}/#{baseLineHeight};
}


// css style
// ************************
.border-top {
    border-top: 1px; solid #ccc;
}

body {
    font: 12px/1.5;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多值变量&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list类型&lt;/code&gt;: 类似js中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数组&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;定义: 可以用空格，逗号或小括号分隔多值&lt;/li&gt;
          &lt;li&gt;取值: 可用nth($var, $index)取值&lt;/li&gt;
          &lt;li&gt;函数:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length($tist)&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;join($list1, $list2, [$separator])&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append($list, $value, [$separator])&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;http://sass-lang.com/documentation/Sass/Script/Functions.html&quot;&gt;More&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map类型&lt;/code&gt;: 类似js中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;对象&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;map数据以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;key&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt;成对出现，其中value可以是普通值，也可以是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;list&lt;/code&gt;;&lt;/li&gt;
          &lt;li&gt;格式: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$map: (key1: value1, key2: value2, key3:value3)&lt;/code&gt;;&lt;/li&gt;
          &lt;li&gt;获得: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map-get($map, $key);&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;函数:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map-merge($map1, $map2)&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map-keys($map)&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map-values($map)&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;http://sass-lang.com/documentation/Sass/Script/Functions.html&quot;&gt;More&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// List
// 定义
// 一维数组
/ ********************* begin
$px: 5px 10px 20px 30px;

// 二维数组，相当于js中的二维数组
$px: 5px 10px, 20px 30px;
$px: (5px 10px) (20px 30px);
// ******************** end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// List 使用
// sass style
// *******************

$linkColor: #08c #333 !default; // 第一个为默认值，第二个为鼠标划过值
a {
    color: nth($linkColor, 1);

    &amp;amp;:hover {
        color: nth($linkColor, 2);
    }
}

// css style
// *****************************
a {
    color: #08c;
}
a:hover {
    color: #333;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Map 定义
$headings: (h1: 2em, h2:1.5em, h3: 1.2em);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Map 使用
// sass style
// *******************************
$headings: (h1: 2em, h2: 1.5em, h3: 1.2em);
@each $header, $size in $headings {
    #($header) {
        font-size: $size;
    }
}

// css style
// *******************************
h1 {
    font-size: 2em;
}
h2 {
    font-size: 1.5em;
}
h3 {
    font-size: 1.2em;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;全局变量&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;在变量值后面加上&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!global&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;局部变量&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;在选择器里声明的变量&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// **********************
$fontSize: 12px;
body {
    $fontSize: 14px; // 局部变量
    font-size: $fontSize;
}

p {
    font-size: $fontSize;
}

// css style
// **************************
body {
    font-size: 14px;
}
p {
    font-size: 12px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五嵌套nesting&quot;&gt;五、嵌套(Nesting)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;分为选择器嵌套和属性嵌套, 主要指&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;选择器嵌套&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;选择器嵌套&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;表示父元素选择器&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ********************************
#top-nav {
    line-height: 40px;
    text-transform: capitalize;
    background-color: #333;

    li {
        float: left;
    }

    a {
        display: block;
        padding: 0 10px;
        color: #fff;

        &amp;amp;:hover {
            color: #ddd;
        }
    }
}

// css style
// **************************
#top-nav {
    line-height: 40px;
    text-transform: capitalize;
    background-color: #333;
}

#top-nav li {
    float: left;
}

#top-nav a {
    display: block;
    padding: 0 10px;
    color: #fff;
}

#top-nav a:hover {
    color: #ddd;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;属性嵌套&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;指有些属性拥有同一个开始单词, 如border-width, border-color都是以border开头的单词&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************************
.fakeshadow {
    border: {
        style: solid;
        left: {
            width: 4px;
            color: #888;
        }
        right: {
            width: 2px;
            color: #ccc;
        }
    }
}

// css style
// ****************************
.fakeshadow {
    border-style: solid;
    border-left-width: 4px;
    border-left-color: #888;
    border-right-width: 2px;
    border-right-color: #ccc;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六at-root&quot;&gt;六、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@at-root&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;用来跳出选择器嵌套.默认所有的嵌套，继承所有上级选择器，但是有了这个就可以跳出所有上级选择器.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;普通跳出嵌套&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************
// 没有跳出
.parent-1 {
    color: #f00;
    .child {
        width: 100px;
    }
}

// 单个选择器跳出
.parent-2 {
    color: #f00;
    @at-root .child {
        width: 200px;
    }
}

// 多个选择器跳出
.parent-3 {
    background: #f00;
    @at-root {
        .child1 {
            width: 300px;
        }
        .child2 {
            width: 400px;
        }
    }
}

// css style
// ************************
.parent-1 {
    color: #f00;
}
.parent-1 .child {
    width: 100px;
}

.parent-2 {
    color: #f00;
}
.child {
    width: 200px;
}

.parent-3 {
    background: #f00;
}
.child1 {
    width: 300px;
}
.child2 {
    width: 400px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;at-root (with-out: ...)&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;at-root (with: ...)&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;默认@at-root只能跳出选择器嵌套，而不能跳出&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@media&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@support&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;跳出:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@media&lt;/code&gt;:  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@at-root (without: media)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;support&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@at-root (without: support)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;四个值:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;all&lt;/code&gt;: 表示所有&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rule&lt;/code&gt;: 表示常规css, 就是默认情况
            &lt;ul&gt;
              &lt;li&gt;@at-root == @at-root (with: rule)&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;media&lt;/code&gt;: 表示media&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;support&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************************************
// 跳出父级元素嵌套
@media print {
    .parent1 {
        color: #f00;
        @at-root .child1 {
            width: 200px;
        }
    }
}

// 跳出media嵌套，父级有效
@media print {
    .parent2 {
        color: #f00;

        @at-root (widthout: media) {
            .child2 {
                width: 200px;
            }
        }
    }
}

// 跳出media和父级
@media print {
    .parent3 {
        color: #f00;

        @at-root (without: all) {
            .child3 {
                width: 200px;
            }
        }
    }
}


// css style
// *******************************
@meida print {
    .parent1 {
        color: #f00;
    }
    .child1 {
        width: 200px;
    }
}

@media print {
    .parent2 {
        color: #f00;
    }
}

.parent2 .child2 {
    width: 200px;
}

@media print {
    .parent3 {
        color: #f00;
    }
}

.child3 {
    width: 200px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@at-root&lt;/code&gt; 与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;配合使用&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ******************************
.child {
    @at-root .parent &amp;amp; {
        color: #f00;
    }
}

// css style
// ******************************
.parent .child {
    color: #f00;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;应用于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@keyframes&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ******************************
.demo {
    ...
    animation: motion 3s infinite;

    @at-root {
        @keyframes motion {
            ...
        }
    }
}

// css style
// ********************************
.demo {
    ...
    animation: motion 3s infinite;
}

@keyframes motion {
    ...
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;七混合mixin&quot;&gt;七、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;混合(mixin)&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;关于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@mixin&lt;/code&gt;与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@include&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;sass中使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@mixin&lt;/code&gt;声明混合，可以传递参数，参数以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&lt;/code&gt;符号开始，多个参数以逗号分开，也可以给参数设置默认值.&lt;/li&gt;
      &lt;li&gt;声明&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@mixin&lt;/code&gt;通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@include&lt;/code&gt;来调用&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;无参数mixin&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************************
@mixin center-block {
    margin-left: auto;
    margin-right: auto;
}

.demo {
    @include center-block;
}

// css style
// ****************************
.demo {
    margin-left: auto;
    margin-right: auto;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;有参数mixin&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ****************************
@mixin opacity($opacity:50) {
    opacity: $opacity / 100;
    filter: alpha(opacity=$opacity);
}

// sass style
// ****************************
.opacity {
    @include opacity; // 参数使用默认值
}
.opacity-80 {
    @include opacity(80); // 传递参数
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多个参数mixin&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;调用时可直接传入值。如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@include&lt;/code&gt;传入参数的个数小于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@mixin&lt;/code&gt;定义参数的个数，则按照顺序表示，后面不足的使用默认值，如没有默认值。则报错。&lt;/li&gt;
      &lt;li&gt;除此之外还可以选择性的传入参数，使用参数名与值同时传入.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// *******************************
@mixin horizontal-line($border: 1px dashed #ccc, $padding: 10px) {
    border-bottom: $border;
    padding-top: $padding;
    padding-bottom: $padding;
}
.imgtext-h li {
    @include horizontal-line(1px solid #ccc);
}
.imgtext-h--product li {
    @include horizontal-line($padding: 15px);
}

// css style
// *******************************
.imgtext-h li {
    border-bottom: 1px solid #cccccc;
    padding-top: 10px;
    padding-bottom: 10px;
}
.imgtext-h--product li {
    border-bottom: 1px dashed #cccccc;
    padding-top: 15px;
    padding-bottom: 15px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多组值参数mixin&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;如果一个参数可以有多组值。如box-shadow、transition等，那么参数则需要在变量后加三个点表示, 如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$variables...&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ********************************
// box-shadow 可以有多组值，所以在变量参数后面添加...
@mix box-shadow ($shadow...) {
    -webkit-box-shadow:$shadow;
    box-shadow: $shadow;
}
.box {
    border: 1px solid #ccc;
    @include box-shadow(0 2px 2px rgba(0, 0, 0, 3), 0 3px 3px rgba(0, 0, 0, .3), 0 4px 4px rgba(0, 0, 0, .3));
}

// css style
// *********************************
.box {
    border: 1px solid #ccc;
    -webkit-box-shadow: 0 2px 2px rgba(0,0,0,.3),0 3px 3px rgba(0,0,0,.3)0 4px 4px rgba(0,0,0,.3);
    box-shadow: 0 2px 2px rgba(0,0,0,.3),0 3px 3px rgba(0,0,0,.3)0 4px 4px rgba(0,0,0,.3);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@content&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;可以用来解决css3的@media等带来的问题。&lt;/li&gt;
      &lt;li&gt;它可以使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@mixin&lt;/code&gt;接收一整块样式, 接受的样式从&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@content&lt;/code&gt;开始.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ********************************
@mixin max-screen($res) {
    @media only screen and (max-width: $res) {
        @content;
    }
}

@include max-screen(480px) {
    body {
        color: red;
    }
}

// css style
// **********************************
@media only screen and (max-width: 480px) {
    body { color: red; }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;八继承&quot;&gt;八、继承&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;定义:
    &lt;ul&gt;
      &lt;li&gt;sass中，选择器继承可以让选择器继承另一个选择器的所有样式, 并联合声明.&lt;/li&gt;
      &lt;li&gt;使用选择器的继承，要使用关键字&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@extend&lt;/code&gt;，后面紧跟需要继承的选择器.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// **********************************
h1 {
    border: 4px solid #ff9aa9;
}
.speaker {
    @extend h1;
    border-width: 2px;
}

// css style
// **********************************
h1,.speaker {
    border: 4px solid #ff9aa9;
}
.speaker {
    border-width: 2px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;占位选择器&quot;&gt;占位选择器&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;定义:
    &lt;ul&gt;
      &lt;li&gt;优势: 如果不调用则不会有任何多余的css文件,避免了以前在一些基础的文件中定义了很多基础的样式，然后在实际应用中不管是否使用了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@extend&lt;/code&gt;去继承相应的样式，都会解析出来所有的样式.&lt;/li&gt;
      &lt;li&gt;占位选择器以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%&lt;/code&gt;标识定义, 通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@extend&lt;/code&gt;调用.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// **************************
%ir {
    color: transparent;
    text-shadow: none;
    background-color: transparent;
    border: 0px;
}
%clearfix {
    @if $lte 7 {
        *zoom: 1;
    }
    &amp;amp;:before,
    &amp;amp;:after {
        content: &quot;&quot;;
        display: table;
        font: 0/0 a;
    }
    &amp;amp;:after {
        clear: both;
    }
}
#header {
    h1 {
        @extend %ir;
        width: 300px;
    }
}
.ir {
    @extend %ir;
}

// css style
// ******************
#header h1,
.ir {
    color: transparent;
    text-shadow: none;
    background-color: transparent;
    border: 0;
}
.header h1 {
    width: 300px;
}

// ****************
// 
  如上代码，定义了两个占位选择器%ir和%clearfix, 其中%clearfix并没有调用，所以解析出来的css样式也就没有clearfix部分.
  占位选择器的出现，使得css样式跟腱简练可控，没有多余.
  PS: 在@media中暂时不能使用@extend @media外的代码片段, 也就是站为选择器必须定义在@media内部.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;九函数&quot;&gt;九、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;函数&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;定义:
    &lt;ul&gt;
      &lt;li&gt;sass定义了很多函数可供使用，当然也可以自定义函数.&lt;/li&gt;
      &lt;li&gt;以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@function&lt;/code&gt;开始, &lt;a href=&quot;http://sass-lang.com/documentation/Sass/Script/Functions.html&quot;&gt;官方&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;实际项目组，我们使用最多的是颜色函数，二颜色函数中又以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lignten&lt;/code&gt;(减淡)和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;darken&lt;/code&gt;(加深)最为常用.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lighten($color, $amount)&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;darken($color, $amount)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;$color: 颜色值&lt;/li&gt;
          &lt;li&gt;$amount: 百分比&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ************************
$baseFontSize:  10px !default;
$gray:          #ccc !default;

// pixels to rems
@funtion px2Rem($px) {
    @return $px / $baseFontSIze * 1rem;
}

body {
    font-size: $baseFontSIze;
    color: lighten($gray, 10%);
}
.test {
    font-size: px2Rem(16px);
    color: darken($gray, 10%);
}

// css style
// ******************************
body {
    font-size: 10px;
    color: #E6E6E6;
}
.test {
    font-size: 1.6rem;
    color: #B3B3B3;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;十运算&quot;&gt;十、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;运算&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;定义:
    &lt;ul&gt;
      &lt;li&gt;sass具有运算的特性，可以对数值型的Value(数字、颜色、变量等)进行加减乘除四则运算.&lt;/li&gt;
      &lt;li&gt;注意: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;运算符前后请留一个空格，否则报错.&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$baseFontSize:      14px !default;
$baseLineHeight:    1.5 !default;
$baseGap:           $baseFontSize * $baseLineHeight !default;
$halfBaseGap:       $baseGap / 2 !default;
$smallFontSize:     $baseFontSize - 2px !default;

// grid
$_columns:          12 !default;    // Total number of columns
$_column-width:     60px !default;  // Width of a single column
$_gutter:           20px !default;  // Width of the gutter
$_gridsystem-width: $_column * ($_column-width + $_gutter);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;十一条件判断及循环&quot;&gt;十一、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;条件判断及循环&lt;/code&gt;&lt;/h3&gt;

&lt;h4 id=&quot;if判断&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@if判断&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@if&lt;/code&gt;可以一个条件单独使用，也可以和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@else&lt;/code&gt;结合多条件使用&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ************************************
$lte7: true;
$type: monster;
.ib {
    display: inline-block;
    @if $lte7 {
        *display: inline;
        *zoom: 1;
    }
}
p {
    @if $type == ocean {
        color: blue;
    } @else if $type == matador {
        color: red;
    } @else if $type == monster {
        color: green;
    } @else {
        color: black;
    }
}

// css style
// ***********************
.ib {
    display: inline-block;
    *display: inline;
    *zoom: 1;
}
p {
    color: green;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;三目判断&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;三目判断&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Syntax:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if ($condition, $if_true_value, $if_false_value)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;如果$condition为true, 则值为$if_true_value; 否则为$if_false_value&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if(true, 1px, 2px) =&amp;gt; 1px
if(false, 1px, 2px) =&amp;gt; 2px
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;for循环&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for循环&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;两种Syntax:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@for $var from &amp;lt;start&amp;gt; through &amp;lt;end&amp;gt; { ... }&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@for $var from &amp;lt;start&amp;gt; to &amp;lt;end&amp;gt; { ... }&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;$var为变量&lt;/li&gt;
          &lt;li&gt;start为起始值，end为解数值&lt;/li&gt;
          &lt;li&gt;注意: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throught包含end这个数，即&amp;lt;=; to不包含end, 即&amp;lt;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// *************************
@for $i from 1 through 3 {
    .item-#{$i} { width: 2em * $i; }
}

// css style
// *************************
.item-1 {
    width: 2em;
}
.item-2 {
    width: 4em;
}
.item-3 {
    width: 6em;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;each循环&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@each循环&lt;/code&gt;&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Syntax:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@each $var in &amp;lt;list or map&amp;gt; { ... }&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;单个字段list数据循环&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$animal-list: puma, sea-slug;
$each $animal in $animal-list {
    .#{$animal}-icon {
        background-image: url(&apos;/images/#{animal}.png&apos;);
    }
}

// css style
// **************************
.puma-icon {
    background-image: url(&apos;/images/puma.png&apos;);
}
.sea-slug-icon {
    background-image: url(&apos;/images/sea-slug.png&apos;);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;多个字段list数据循环&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// *********************************
$animal-data: (puma, black, default), (sea-slug, blue, pointer);
@each $animal, $color, $cursor in $animal-data {
    .#{$animal}-icon {
        background-image: url(&apos;/images/#{$animal}.png&apos;);
        border: 2px solid $color;
        cursor: $cursor;
    }
}

// css style
// *********************************
.puma-icon {
    background-image: url(&apos;/images/puma.png&apos;);
    border: 2px solid black;
    cursor: default;
}
.sea-slug-icon {
    background-image: url(&apos;/images/sea-slug.png&apos;);
    border: 2px solid blue;
    cursor: pointer;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;多个字段map数据循环&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// sass style
// ********************************
$headings: (h1: 2em, h2:1.5em, h3: 1.2em);
@each $header, $size in $headings {
    #{$header} {
        font-size: $size;
    }
}

// css style
// ********************************
h1 { font-size: 2em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.2em; }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/08/15/sass-getting-started.html</link>
    <guid>/2015/08/15/sass-getting-started</guid>
    <pubDate>Sat, 15 Aug 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>如何通过反向SSH隧道访问NAT后面的Linux服务器</title>
    <description>
&lt;h2 id=&quot;参考整理&quot;&gt;&lt;a href=&quot;https://linux.cn/article-5975-1.html&quot;&gt;参考整理&lt;/a&gt;&lt;/h2&gt;

&lt;h2 id=&quot;基本概念&quot;&gt;基本概念&lt;/h2&gt;

&lt;h3 id=&quot;一反向ssh隧道简介&quot;&gt;一、反向SSH隧道简介&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 是什么:
    &lt;ul&gt;
      &lt;li&gt;隧道协议(Tunneling protocol):
        &lt;ul&gt;
          &lt;li&gt;在当前网络不支持或不提供某种网络服务的情况下，隧道协议允许访问或提供该服务.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;(正向)SSH隧道:
        &lt;ul&gt;
          &lt;li&gt;通过Secure Shell 提供的隧道协议服务&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;反向SSH隧道:
        &lt;ul&gt;
          &lt;li&gt;在本地主机与远程VPS建立SSH隧道的情况下，(通过)远程VPS能够通过它反向访问本地主机.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 前提:
    &lt;ul&gt;
      &lt;li&gt;家庭主机没有或没有固定的公网IP(一般运营商不会给的)&lt;/li&gt;
      &lt;li&gt;一个拥有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;公网IP&lt;/code&gt;的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VPS&lt;/code&gt;(中继主机), OS: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Linux&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 步骤:
    &lt;ul&gt;
      &lt;li&gt;从家里的Linux主机与公网中的VPS(中继主机)建立&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH隧道&lt;/code&gt;;&lt;/li&gt;
      &lt;li&gt;有了这个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;隧道&lt;/code&gt;，就可以从VPS上或通过VPS连接&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;回&lt;/code&gt;家里的Linux主机;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 作用:
    &lt;ul&gt;
      &lt;li&gt;在任何地方，连接上家里的Linux主机&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二设置反向ssh隧道&quot;&gt;二、设置反向SSH隧道&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;预设:
    &lt;ul&gt;
      &lt;li&gt;home: 表示家庭Linux主机&lt;/li&gt;
      &lt;li&gt;vps: 表示拥有公网IP的远程中继主机&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;1 打开一个到中继服务器的SSH连接:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R 10022:localhost:22 vps_user@1.1.1.1&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;10022: 是VPS上没有被占用，被用来反向连接家庭主机的端口, 也就是vps上通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh home_user@127.0.0.1 -p 10022&lt;/code&gt;连接家庭Linux主机&lt;/li&gt;
          &lt;li&gt;localhost: 是绑定远程主机的地址，这项可以当做默认&lt;/li&gt;
          &lt;li&gt;22: 远程vps的ssh端口&lt;/li&gt;
          &lt;li&gt;vps_user: vps的用户&lt;/li&gt;
          &lt;li&gt;1.1.1.1: 远程vps的IP地址&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-R&lt;/code&gt;: 定义一个反向隧道, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-R [vps_ip:]port:host:host_port&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-N&lt;/code&gt;: 不执行远程命令, 这对转发端口是非常有用的.&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-f&lt;/code&gt;: 在成功通过SSH服务器验证时, 在命令执行之前，将ssh请求放到后台运行(守护进程).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 远程VPS状态:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo netstate -nap | grep 10022&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;确认其127.0.0.1:10022绑定到了sshd.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 从VPS连接到家庭主机:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -p 10022 home_user@127.0.0.1&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;home_user是家庭主机的用户，密码自然也是。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三通过反向ssh隧道直接链接到网络地址变换后的服务器&quot;&gt;三、通过反向SSH隧道直接链接到网络地址变换后的服务器&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 问题:
    &lt;ul&gt;
      &lt;li&gt;上面方法允许从VPS访问NAT后面的家庭服务器, 但是需要两次登录: 先登录VPS, 再登录家庭服务器.因为中继服务器(VPS)上SSH隧道的端点绑定到了回环地址(127.0.0.1).现在我想直通过VPS对外开放的端口就可以直接访问家庭服务器(只要一步).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 步骤:
    &lt;ul&gt;
      &lt;li&gt;1 指定VPS上运行的ssh的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GatewayPorts&lt;/code&gt;实现
        &lt;ul&gt;
          &lt;li&gt;将&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GatewayPorts clientspecified&lt;/code&gt; 添加到 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/ssh/sshd_config&lt;/code&gt; (VPS: Ubuntu Server)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 重启sshd服务
        &lt;ul&gt;
          &lt;li&gt;Debian系:
            &lt;ul&gt;
              &lt;li&gt;Upstart: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo service ssh restart&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;Systemd: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo sstemctl restart sshd&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;Red Hat系
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo systemctl restart sshd&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 初始化方向隧道, 记得把之前的kill, 否则端口10022被占用
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R 1.1.1.1:10022:localhost:22 vps_user@1.1.1.1&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;1.1.1.1 是VPS的公网IP地址&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 在VPS上确认是否建立反向ssh隧道:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo netstat -nap | hrep 10022&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;现在可以通过VPS对外开放的端口之间访问家庭服务器&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -p 10022 home_user@1.1.1.1&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四永久反向ssh隧道&quot;&gt;四、永久反向SSH隧道&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 工具:
    &lt;ul&gt;
      &lt;li&gt;借助&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autossh&lt;/code&gt;自动反向SSH隧道&lt;/li&gt;
      &lt;li&gt;在执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;autossh&lt;/code&gt;之前，须将ssh public key上传的VPS
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh-keygen -t rsa&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh-copy-id -i ~/.ssh/id_rsa.pub vps_user@vps_ip&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 安装:
    &lt;ul&gt;
      &lt;li&gt;Debian系:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo apt-get install autossh&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Red Hat系:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo yum install autossh&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;(Fedora) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo dnf install autossh&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 配置&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;autossh &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-M&lt;/span&gt; 10900 &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# 指定VPS服务器上的见识端口，用于交换监视SSH会话的测试数据, 不能被占用&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-fN&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# 后台运行&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;PubkeyAuthentication=yes&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;   &lt;span class=&quot;c&quot;&gt;# 使用秘钥验证，而不是密码验证&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;StrictHostKeyChecking=false&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;c&quot;&gt;# 自动接受SSH主机秘钥&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;PasswordAuthentication=no&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ServerAliveInterval 60&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;     &lt;span class=&quot;c&quot;&gt;# 每60秒交换key-alive消息&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ServerAliveCountMax 3&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;      &lt;span class=&quot;c&quot;&gt;# 没有收到任何响应是最多发送3条keep-alive消息.&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$VPS_IP&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$VPS_ACCESS_PORT&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$FORWARD_IP&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$FORWARD_PORT&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    vps_user@1.1.1.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五socks代理公式&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;五、SOCKS代理公式&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R $VPS_IP:$VPS_ACCESS_PORT:$FORWARD_IP:$FORWARD_PORT $VPS_USER@VPS_IP&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;$VPS_IP: 就是远程服务器地址&lt;/li&gt;
      &lt;li&gt;$VPS_ACCESS_PORT: 之后你访问的就是$VPS_IP和$VPS_ACCESS_PORT&lt;/li&gt;
      &lt;li&gt;$FORWARD_IP: 要被转发的IP地址, 就是外网无法访问的内网IP等,也可以是本地IP, 如127.0.0.1&lt;/li&gt;
      &lt;li&gt;$FORWARD_IP: 要被转发的端口
  # $VPS_USER: VPS的用户，不需要root权限，它就相当于一个代理人而已&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 这里一般使用SSH_PUB_KEY, 公钥验证; 这样在配置autossh时就不会出问题了&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;同样可以应用到autossh&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六端口代理socks代理实际案例&quot;&gt;六、端口代理(socks代理)实际案例&lt;/h3&gt;

&lt;h4 id=&quot;案例1-转发路由器19216811的80端口到远程服务器123123123123的12345端口-远程服务器用户agent&quot;&gt;案例1: 转发路由器(192.168.1.1)的80端口到远程服务器(123.123.123.123)的12345端口, 远程服务器用户agent&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;目的:
    &lt;ul&gt;
      &lt;li&gt;使得直接访问http://123.123.123.123:12345就可以访问路由器Web界面&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;前提:
    &lt;ul&gt;
      &lt;li&gt;远程服务器及其用户有效, 路由器存在&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;实际操作:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R 123.123.123.123:12345:192.168.1.1:80 agent@123.123.123.123&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;现在访问http://123.123.123.123:12345试试&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;案例2-转发本地内网主机127001ssh端口22到远程服务器123123123123的12345端口-本地主机ssh用户local_ssh_user本地能连接sshd服务必须开启-远程服务器用户agent&quot;&gt;案例2: 转发本地内网主机(127.0.0.1)SSH端口(22)到远程服务器(123.123.123.123)的12345端口, 本地主机SSH用户local_ssh_user(本地能连接，sshd服务必须开启), 远程服务器用户agent&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;目的:
    &lt;ul&gt;
      &lt;li&gt;使得在任意主机上使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh local_ssh_user@123.123.123.123 -p 12345&lt;/code&gt;就能连接到本地主机(内网主机)SSH服务&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;前提不在赘述&lt;/li&gt;
  &lt;li&gt;实际操作:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R 123.123.123.123:12345:127.0.0.1:22 agent@123.123.123.123&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;案例3-转发内网主机10111213的1080端口到服务器123123123123的54321端口&quot;&gt;案例3: 转发内网主机(10.11.12.13)的1080端口到服务器(123.123.123.123)的54321端口&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;目的:
    &lt;ul&gt;
      &lt;li&gt;可以通过访问123.123.123.123的54321端口就能访问内网主机10.11.12.13的1080端口, 具体视情况而定&lt;/li&gt;
      &lt;li&gt;具体服务如案例1和案例2&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;实际操作:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh -fN -R 123.123.123.123:54321:10.11.12.13:1080 agent@123.123.123.123&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/08/12/connect-local-server-by-ssh-reverse-tunnel.html</link>
    <guid>/2015/08/12/connect-local-server-by-ssh-reverse-tunnel</guid>
    <pubDate>Wed, 12 Aug 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>CSS 中的居中</title>
    <description>
&lt;h3 id=&quot;一文本字水平居中&quot;&gt;一、文本(字)水平居中&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* Condition: 
    * 文本、图片、或者强制行级元素等`行内(inline, inline-block)元素`
* Object:
    * 给要居中元素的父类元素添加
* Code: 
    * `text-align:center`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二定框块级元素水平居中block-and-width&quot;&gt;二、定框块级元素水平居中:(block and width)&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* Condition:
    * Block 并且 width确定(不论px还是百分比)
* Object:
    * 给要居中的元素本身添加
* Code:
    * `margin: 0 auto;`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三不定宽块状元素水平居中&quot;&gt;三、不定宽块状元素水平居中:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* Code 1 (个人感觉不美观):
    * `postion: relative; left: 50%;`
* Code 2 (转换为第一种情况):
    * `display: inline;`
    * 父元素: `text-align: center`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四文本元素垂直居中&quot;&gt;四、文本元素垂直居中:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* Condition:
    * 父元素高度确定的单行文本
* Object:
    * 容纳文字的元素也可说(DOM)文本元素的父元素
* Code:
    * `height: 100px; line-height: 100px;`
    * `只要设置line-height与height一致`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五块级元素垂直居中&quot;&gt;五、块级元素垂直居中:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* Condition:
    * Block
* Object:
    * 要垂直居中元素的父元素
* Code:
    * `display: table-cell; vertical-align: middle;/*只有display为table-cell时才会激活vertical-align属性*/`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六跑题一下&quot;&gt;六、跑题一下:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* `block` `inline-block` `inline`的区别
    * `inline`: 没有height和width
    * `inline-block`: 有height, 没有width
    * `block`: 有height和width
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/08/04/css-center.html</link>
    <guid>/2015/08/04/css-center</guid>
    <pubDate>Tue, 04 Aug 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Great Photos Wall</title>
    <description>
&lt;h3 id=&quot;一知识点&quot;&gt;一、知识点&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;box-shadow&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;Function: 给元素边框添加阴影效果&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;box-shadow: offset-x offset-y blur-radius [spread-radius] color [inset];&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;offset-x: X轴偏移量&lt;/li&gt;
          &lt;li&gt;offset-y: Y轴偏移量&lt;/li&gt;
          &lt;li&gt;blur-radius: 阴影模糊半径&lt;/li&gt;
          &lt;li&gt;spread-radius: 阴影扩展半径&lt;/li&gt;
          &lt;li&gt;color: 阴影颜色&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;inset&lt;/td&gt;
                  &lt;td&gt;outset: 投影方式, 内阴影&lt;/td&gt;
                  &lt;td&gt;(默认)外阴影&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;position&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;Function: 给元素定位，主要用到绝对定位absolute&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;position: keyword-value;&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;Keyword Values: static(default)&lt;/td&gt;
                  &lt;td&gt;relative&lt;/td&gt;
                  &lt;td&gt;absolute&lt;/td&gt;
                  &lt;td&gt;fixed&lt;/td&gt;
                  &lt;td&gt;sticky&lt;/td&gt;
                  &lt;td&gt;inherit&lt;/td&gt;
                  &lt;td&gt;initial&lt;/td&gt;
                  &lt;td&gt;unset;&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;how-to:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;position:absolute 和 position:relative 配合使用实现相对于包含元素(参照元素)定位&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;z-index&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;Function: 设置元素的上下层显示顺序&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;z-index: INTEGER;&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;INTEGER(整数)越大，显示越上层，可以为负数&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transform&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;Function: 使元素变形的属性, 其配合&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rotate(旋转)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scale(缩放)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skew(扭曲)&lt;/code&gt;等参数一起使用&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transform: rotate(旋转角度);&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transform: scale(缩放倍数);&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transform: rotate(旋转角度) scale(缩放倍数);&lt;/code&gt; // 旋转并缩放&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;Function: 设置元素由样式1变化到样式2的过程所需要的时间&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition: duration;&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二制作步骤&quot;&gt;二、制作步骤&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 每张照片的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;位置&lt;/code&gt;不一样&lt;/li&gt;
  &lt;li&gt;2 每张照片有一定的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;旋转角度(transform:rotate(?deg))&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;3 照片&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;阴影(box-shadow)&lt;/code&gt;及&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;缓慢(transition)旋转(transform:rotate)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;缓慢(transsition)放大(transfrom:scale)&lt;/code&gt;特效制作&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三实现&quot;&gt;三、实现&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.container {
    padding: 0;
    margin: 60px auto;
    width: 960px;
    height: 450px;
    position: relative;
}

/* 公共初始属性 */
img {
    padding: 10px 10px 15px;
    background: #fff;
    border: 1px solid #ddd;
    
    position: absolute; /*绝对定位, left, right, top, bottom*/
   
    /* 兼容性, 从初始状态到鼠标移上状态的时间 */
    -webkit-transition: 500ms;
    -moz-transition: 500ms;
    -ms-transition: 500ms;
    -o-transition: 500ms;
    transition: 500ms;

    width: 200px;
    height: 300px;
}

/* 公共鼠标移上属性 */
img:hover {
    /* 将图片旋转为0度 */
    tranform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -o-transform: rotate(0deg);

    /*将图片缩放为原来的1.2倍 */
    -webkit-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -ms-transform: scale(1.2);
    -o-transform: scale(1.2);
    transform: scale(1.2);

    /* 图片阴影 */
    -webkit-box-shadow: 10px 10px 15px #ccc;
    -moz-box-shadow: 10px 10px 15px #ccc;
    box-shadow: 10px 10px 15px #ccc;
    z-index: 2;
}

/* 图片特性 */
.img-1 {
    /* 绝对定位设置的属性: left, right, top, bottom */
    top: 0px;
    left: 200px;

    /* 初始状态旋转角度 */
    transform: rotate(20deg);
    -webkit-transform: rotate(20deg);
    -moz-transform: rotate(20deg);
    -o-transform: rotate(20deg);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四daemon和源码&quot;&gt;四、Daemon和源码&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/work/photowall&quot;&gt;Daemon&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/whatwewant/PhotoWall&quot;&gt;源码&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/08/01/great-photos-wall.html</link>
    <guid>/2015/08/01/great-photos-wall</guid>
    <pubDate>Sat, 01 Aug 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Hadoop Getting Started</title>
    <description>
&lt;h3 id=&quot;一关于-hadoop&quot;&gt;一、关于 Hadoop&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 Hadoop是什么:
    &lt;ul&gt;
      &lt;li&gt;Hadoop是Apache的开源的分布式存储以及分布式计算平台&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://hadoop.apache.org&quot;&gt;官网&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 Hadoop的两个核心组成:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HDFS&lt;/code&gt;: 分布式文件系统，存储海量的数据&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MapReduce&lt;/code&gt;: 并行处理框架,实现任务分解和调度&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 Hadoop的用途:
    &lt;ul&gt;
      &lt;li&gt;搭建大型数据仓库,PB级数据的存储、处理、分析、统计等业务.
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;搜索引擎&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;日志分析&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;商业智能&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据挖掘&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 Hadoop的优势:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.高扩展&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.低成本&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3.成熟的生态圈(Hadoop Ecosysten)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 Hadoop的生态系统及版本: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HDFS + MapReduce + 开源工具&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.HIVE&lt;/code&gt;: 只需要编写简单的SQL语句, 转化成Hadoop任务&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.HBASE&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;存储结构化数据的分布式数据库.&lt;/li&gt;
          &lt;li&gt;和传统的关系型数据库区别, Hbase放弃失特性，追求更高的扩展&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;和HDFS区别: Hbase提供数据的随机读写和实时访问, 实现对表数据的读写功能.&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3.Zookeeper&lt;/code&gt;: 监控Hadoop集群的状态，管理Hadoop集群的配置…&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二hadoop的安装ubuntu-1404&quot;&gt;二、Hadoop的安装(Ubuntu 14.04)&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Step 1: 准备Linux, 这里用Ubuntu 14.04&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Step 2: 安装JDK, 这里用OpenJDK 1,7
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo apt-get update; sudo apt-get install -y openjdk-7-jdk&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;设置JAVA环境, 编辑 ~/.bashrc或~/.zshrc 在末尾添加
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export JRE_HOME=$JAVA_HOME/jre&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;使JAVA环境生效:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source ~/.bashrc&lt;/code&gt; Or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source ~/.zshrc&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Step 3: 下载Hadoop, 并解压到$HOME目录
    &lt;ul&gt;
      &lt;li&gt;1 下载: &lt;a href=&quot;https://hadoop.apache.org&quot;&gt;官网&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.7.1/hadoop-2.7.1.tar.gz&quot;&gt;2.7.1&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz&quot;&gt;1.2.1&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;COMMAND: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 解压到WORKDIR目录, WORKDIR自己定，最好在$HOME
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tar -zxvf hadoop-1.2.1.tar.gz -C $HOME&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Step 4 配置Hadoop: Hadoop目录: $HOME/hadoop-1.2.1
    &lt;ul&gt;
      &lt;li&gt;四个配置文件, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;配置文件目录: $HOME/hadoop-1.2.1/conf&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;core-site.xml&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hadoop-env.sh&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hdfs-site.xml&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mapred-site.xml&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 1 编辑hadoop-env.sh: `vim hadoop-env.sh`
    * 找到JAVA_HOME, 取消注释(去掉`#`)，修改为刚才设置的JAVA_HOME地址
    * `export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 2 `vim core-site.xml`
    &amp;lt;configuration&amp;gt;
        &amp;lt;property&amp;gt;
            &amp;lt;!-- 这是注释, Hadoop的工作目录 --&amp;gt;
            &amp;lt;!-- 该目录不要手动创建 --&amp;gt;
            &amp;lt;name&amp;gt;hadoop.tmp.dir&amp;lt;/name&amp;gt;
            &amp;lt;value&amp;gt;/home/potter/hadoop&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;

        &amp;lt;property&amp;gt;
            &amp;lt;!-- 元数据目录 --&amp;gt;
            &amp;lt;!-- name 目录不要创建 --&amp;gt;
            &amp;lt;name&amp;gt;dfs.name.dir&amp;lt;/name&amp;gt;
            &amp;lt;value&amp;gt;/home/potter/hadoop/name&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;

        &amp;lt;property&amp;gt;
            &amp;lt;!-- 文件系统的name node --&amp;gt;
            &amp;lt;name&amp;gt;fs.default.name&amp;lt;/name&amp;gt;
            &amp;lt;!-- potter 是 hostname, 9000 是hadoop的端口号 --&amp;gt;
            &amp;lt;value&amp;gt;hdfs://potter:9000&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;
    &amp;lt;/configuration&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 3 vim hdfs-site.xml
&amp;lt;configuration&amp;gt;:
    &amp;lt;property&amp;gt;
        &amp;lt;!-- 文件系统数据的存放目录 --&amp;gt;
        &amp;lt;!-- data 目录不要创建, 否则存在权限问题, 如果出现问题，请查看HADOOP_HOME目录下的logs目录文件 --&amp;gt;
        &amp;lt;name&amp;gt;dfs.data.dir&amp;lt;/name&amp;gt;
        &amp;lt;value&amp;gt;/home/potter/hadoop/data&amp;lt;/value&amp;gt;
    &amp;lt;/property&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 4 vim mapred-site.xml
&amp;lt;configuration&amp;gt;:
    &amp;lt;property&amp;gt;
        &amp;lt;!-- 任务调度去访问路径 --&amp;gt;
        &amp;lt;name&amp;gt;mapred.job.tracker&amp;lt;/name&amp;gt;
        &amp;lt;value&amp;gt;potter:9001&amp;lt;/value&amp;gt;
    &amp;lt;/property&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 5 配置 Hadoop 环境
// vim ~/.bashrc
export HADOOP_HOME=$HOME/hadoop-1.2.1
export PATH=$HADOOP_HOME/bin:$PATH

// 使环境生效
source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 6 基本环境配置好了，现在继续做必要的操作
// 6.1 Hadoop配置成功与否
% hadoop # 显示帮助则说明hadoop配置没问题

// 6.2 对 namenode 进行格式化, 否则无法启动namenode服务
% hadoop namenode -format
# 成功执行后, /home/potter/hadoop目录及子目录dfs被创建

// 6.3 启动服务
% start-all.sh
# 成功执行后, /home/potter/hadoop/data及/home/potter/hadoop/mapred目录被创建
// 6.3.1 停止服务: stop-all.sh

// 6.4 JPS 查看服务
% jps
如果存在 Jps
        JobTracker
        NameNode
        DataNode
        SecondaryNameNode
        TaskTracker
 六个任务，则说明Hadoop配置没问题

// 6.5 常见问题:
 1. NameNode 和 DataNode 启动不成功解决:
    保证前面配置一致, 则可能在start-all.sh之前没有format namenode.
  这时只要stop-all.sh, 再hadoop namenode -format, 然后在start-all.sh即可

 2. DataNode 启动不成功解决:
    data目录不要手动创建，已创建，请删除,重新stop-all.sh &amp;amp;&amp;amp; start-all.sh即可

 3. 其他, 请查看$HADOOP_HOME目录下的logs目录

// 6.6 查看Hadoop的文件命令
% hadoop fs -ls /
% hadoop fs -ls /home
% hadoop fs -ls /home/ubuntu
% hadoop fs -ls /home/ubuntu/hadoop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;hadoop-基本概念-hdfs--mapreduce&quot;&gt;Hadoop 基本概念: HDFS + MapReduce&lt;/h2&gt;

&lt;h3 id=&quot;三hdfs-系统&quot;&gt;三、HDFS 系统&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 块(Block)
    &lt;ul&gt;
      &lt;li&gt;HDFS的文件被分成块(Block)进行存储.&lt;/li&gt;
      &lt;li&gt;HDFS块的默认大小为64MB&lt;/li&gt;
      &lt;li&gt;块是文件存储处理的逻辑单元&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HDFS 中有两类节点NameNode + DataNode&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 NameNode
    &lt;ul&gt;
      &lt;li&gt;是HDFS的管理节点，存放文件元数据
        &lt;ul&gt;
          &lt;li&gt;1 文件与数据块的映射表&lt;/li&gt;
          &lt;li&gt;2 数据块与数据节点的映射表&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;客户通过NameNode找到DataNode, 将多个DataNode拼成一个可用的数据&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 DataNode
    &lt;ul&gt;
      &lt;li&gt;是HDFS的工作节点，存放数据块&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;三-2hdfs中数据管理与容错&quot;&gt;三-2、HDFS中数据管理与容错&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 每个数据块有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3个副本&lt;/code&gt;，分布在两个机架内的三个节点.(一个机架可以存放多个DataNode, 数据块存放在DataNode中.其中两份在一个机架，另一个在另一个机架.)以此来保证容错.&lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;心跳检测&lt;/code&gt;: DataNode定期向NameNode发送心跳消息.&lt;/li&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SecondaryNameNode&lt;/code&gt;: 二级NameNode定期同步元数据镜像文件和修改日志NameNode发生故障时，备胎转正.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;三-3文件读写的流程&quot;&gt;三-3、文件读写的流程&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;HDFS中&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;文件读取&lt;/code&gt;的流程:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 1: 客户端向NameNode发送文件读取请求&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 2: NameNode根据客户端发来的文件路径, 查看元数据&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 3: NameNode会根据元数据，返回客户端这些数据块及其存放的DataNode&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 4: 找到数据块存放的DataNode，读取并组装&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;HDFS中&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;文件写入&lt;/code&gt;的流程:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 1: 客户端文件拆分成块, 每个大小问DataNode的默认大小64MB.&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 2: 客户端发送通知给NameNode&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 3: NameNode 从机架中查找可用的DataNode返回客户端&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 4: 客户端根据NameNode返回的DataNode, 将数据块写入DataNode&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 5: 一个数据块写入DataNode后，进行流水线复制两份到不同机架的DataNode&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 6: 没一个DataNode复制完成后(一个复制两个)，更新元数据&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 7： 写入第二个数据块到DataNode, 重复Step 5...&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;三-4hdfs的特点&quot;&gt;三-4、HDFS的特点&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.数据冗余，硬件容错&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.流式数据访问&lt;/code&gt;: 一次写入，多次读写; 一旦写入，不会被修改&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3.存储大文件&lt;/code&gt;: 如果文件很小，对NameNode的压力很大&lt;/li&gt;
  &lt;li&gt;适用性和局限性:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;适合数据批量读写，吞吐量高.&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;不适合交互式应用，低延迟很难满足&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;适合一次写入多次读写，顺序读写&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;不支持多用户并发写相同文件&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;三-5hdfs命令行操作&quot;&gt;三-5、HDFS命令行操作&lt;/h4&gt;

&lt;div class=&quot;language-bash 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;# hdfs 提供Shell接口, 所以命令和Shell操作很类似&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 直接输入 hadoop fs 可以获得帮助&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 1 查看文件夹&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-ls&lt;/span&gt; /

&lt;span class=&quot;c&quot;&gt;# 2 新建目录&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-mkdir&lt;/span&gt; input 
&lt;span class=&quot;c&quot;&gt;# 该命令会在/usr/potter下创建input目录&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 其中potter为你的hostname&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 用 hadoop fs -ls /usr/potter 查看&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 3 将本地文件提交到hdfs, local_file为本地任意文件&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-put&lt;/span&gt; local_file input/ 
&lt;span class=&quot;c&quot;&gt;# 查看文件&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-ls&lt;/span&gt; /user/potter/input
&lt;span class=&quot;c&quot;&gt;# 查看文件内容&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-cat&lt;/span&gt; /usr/potter/input/local_file

&lt;span class=&quot;c&quot;&gt;# 4 删除文件或目录&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-rm&lt;/span&gt; path/to/file

&lt;span class=&quot;c&quot;&gt;# 5 从HDFS中获取文件到本地&lt;/span&gt;
% hadoop fs &lt;span class=&quot;nt&quot;&gt;-get&lt;/span&gt; input/remote_file local_new_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四mapreduce框架&quot;&gt;四、MapReduce框架&lt;/h3&gt;

&lt;h4 id=&quot;四-1-mapreduce-原理&quot;&gt;四-1. MapReduce 原理&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;分而治之&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一个大任务分成多个小的子任务(map), 并行执行后，合并结果(reduce)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;栗子: 老师让多个组长一起发作业(map), 老师收作业(reduce)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map: 大变小加上并行执行, reduce: 小变大, 但是map和reduce并不是相反的过程&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;实际栗子:
    &lt;ul&gt;
      &lt;li&gt;1 从100GB的网站访问日志文件中找出访问次数最多的IP地址.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;四-2-mapreduce-运行流程&quot;&gt;四-2. MapReduce 运行流程&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;基本概念:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Job &amp;amp; Task&lt;/code&gt;: 一个Job被分成多个Task, Task又分为MapTask和ReduceTask&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JobTracker&lt;/code&gt;: 客户端提交Job(任务)来, JobTracker将Job分为MapJob和ReduceJob, MapJob 和 ReduceJob又将任务交给Map TaskTracker 和 Reduce TaskTracker
        &lt;ul&gt;
          &lt;li&gt;1 作业调度&lt;/li&gt;
          &lt;li&gt;2 分配任务、监控任务执行进度&lt;/li&gt;
          &lt;li&gt;3 监控TaskTracker的状态&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TaskTracker&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;1 执行任务&lt;/li&gt;
          &lt;li&gt;2 向JobTracker汇报任务状态&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;执行流程:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.输入数据或者数据也来自HDFS&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2.将输入数据分片，执行Map任务(Job), 交给Map端的TaskTracker&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3.中间结果: Key-Value&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4.执行Recude任务(Job), 交给Reduce端的TaskTracker&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5.将输出结果写回到HDFS&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;MapReduce的容错机制
    &lt;ul&gt;
      &lt;li&gt;1 重复执行(4次失败后放弃)&lt;/li&gt;
      &lt;li&gt;2 推测执行&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五mapreduce的应用案例&quot;&gt;五、MapReduce的应用案例&lt;/h3&gt;

&lt;h4 id=&quot;案例一wordcount单词计数&quot;&gt;案例一、WordCount单词计数&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;问题: 计算文件中出现每个单词的頻数, 输出结果按照字母顺序进行排序.&lt;/li&gt;
  &lt;li&gt;思路:
    &lt;ul&gt;
      &lt;li&gt;将文件按行进行切分，每行执行Map操作, 计算每个结果, 然后再Reduce合并&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/07/30/hadoop-getting-started.html</link>
    <guid>/2015/07/30/hadoop-getting-started</guid>
    <pubDate>Thu, 30 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Java Web (三) 过滤器(Filter)</title>
    <description>
&lt;h3 id=&quot;一过滤器简介&quot;&gt;一、过滤器简介&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 含义:
    &lt;ul&gt;
      &lt;li&gt;Web过滤器: (过滤源 + 过滤规则 + 过滤结果) 是一个服务器端的组件，它可以截取用户端的请求与响应信息,并对这些信息过滤.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二过滤器的工作原理和生命周期&quot;&gt;二、过滤器的工作原理和生命周期&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 工作原理:
    &lt;ul&gt;
      &lt;li&gt;过程: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;用户请求 &amp;lt;-&amp;gt; 过滤器 &amp;lt;-&amp;gt; Web资源&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 生命周期:
    &lt;ul&gt;
      &lt;li&gt;过程:
        &lt;ul&gt;
          &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;实例化 -&amp;gt; Web.xml&lt;/code&gt; : 只一次&lt;/li&gt;
          &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;实例化 -&amp;gt; 初始化 -&amp;gt; init()&lt;/code&gt; : 只一次&lt;/li&gt;
          &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;初始化 -&amp;gt; 过滤   -&amp;gt; doFilter()&lt;/code&gt; : 每次都做&lt;/li&gt;
          &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;过滤   -&amp;gt; 销毁   -&amp;gt; destroy()&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 函数:
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init()&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;这是过滤器的初始化方法，Web容器创建过滤器实例后将调用这个方法。这个方法中的FilterConfig类型参数可以读取web.xml文件中过滤器的参数.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;doFilter()&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;这个方法完成时间操作。这个方法是过滤器的核心方法.当用户请求访问与过滤器关联的URL时，Web容器将先调用过滤器的doFilter方法.&lt;/li&gt;
          &lt;li&gt;FilterChain参数可以调用chain.doFilter方法，将请求传给下一个过滤器(或目标资源)，或利用转发、重定向将请求转发给其他资源.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;destroy()&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;销毁实例，释放资源&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 经典问题:
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;过滤器能改变用户请求的Web资源，即能改变用户的请求路径.&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;比如，没有登入，不符合要求，就直接改变请求路径.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;过滤器不能直接返回数据，不能直接处理用户请求&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 1. 在web.xml中注册Filter
    &amp;lt;filter&amp;gt;
        &amp;lt;!-- Filter Name 任意取--&amp;gt;
        &amp;lt;filter-name&amp;gt;LoginFilter&amp;lt;/filter-name&amp;gt;
        
        &amp;lt;!-- 过滤器的全路径: 包名 + 类名 --&amp;gt;
        &amp;lt;filter-class&amp;gt;com.cole.filter.LoginFilter&amp;lt;/filter-class&amp;gt;

        &amp;lt;!-- Filter 初始化参数, 可以省略, 也可以是零对或多 --&amp;gt;
        &amp;lt;init-param&amp;gt;
            &amp;lt;!-- Filter 描述, 可以省略 --&amp;gt;
            &amp;lt;description&amp;gt;&amp;lt;/description&amp;gt;
            &amp;lt;param-name&amp;gt;username&amp;lt;/param-name&amp;gt;
            &amp;lt;param-value&amp;gt;password&amp;lt;/param-value&amp;gt;
        &amp;lt;/init-param&amp;gt;
    &amp;lt;/filter&amp;gt;

    &amp;lt;!-- Filter Mapping 可以多个，多个URL地址可以匹配到一个Filter里 --&amp;gt;
    &amp;lt;filter-mapping&amp;gt;

        &amp;lt;!-- Filter Name 必须与filter中的相同 --&amp;gt;
        &amp;lt;filter-name&amp;gt;LoginFilter&amp;lt;/filter-name&amp;gt;

        &amp;lt;!-- 当用户请求的URL和指定的URL匹配时，将触发过滤器--&amp;gt;
        &amp;lt;!-- URL: /* 代表任意值 --&amp;gt;
        &amp;lt;url-pattern&amp;gt;/login.jsp&amp;lt;/url-pattern&amp;gt;

        &amp;lt;!-- 要过滤的类型, 可以省略, 可以是零对或多对，值为: REQUEST | INCLUDE | FORWARD | ERROR, 默认为REQUEST--&amp;gt;
        &amp;lt;dispatcher&amp;gt;REQUEST&amp;lt;/dispatcher&amp;gt;
    &amp;lt;/filter-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 2. Filter类, src -&amp;gt; 右键new -&amp;gt; Filter 或者 新建Class继承Filter (javax.servlet.filter)
public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println(&quot;服务器启动时就初始化 Filter&quot;);
        System.out.println(&quot;Filter Init&quot;);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        // 先匹配web.xml中的URL并执行filter, 
        System.out.println(&quot;Filter Start ... doFilter&quot;);

        // 再执行下一条语句，也就是访问实际URL
        filterChain.doFilter(servletRequest, servletResponse);

        // 过滤结束
        System.out.println(&quot;Filter End ... doFilter&quot;);
    }

    @Override
    public void destroy() {
        System.out.println(&quot;Filter Destroy&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;三过滤器链多个过滤器&quot;&gt;三、过滤器链(多个过滤器)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多个过滤器的实现&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;误解:
        &lt;ul&gt;
          &lt;li&gt;多个过滤器一般指(web.xml): 1.多个filter, 2.一个filter中多个url-pattern(错误认为)&lt;/li&gt;
          &lt;li&gt;这里是指多个filter，每个 url-pattern 一样&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;过程(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;url-pattern&lt;/code&gt;一样):
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;用户请求 -&amp;gt; 过滤器1 -&amp;gt; 过滤器2 -&amp;gt; 过滤器3 -&amp;gt; Web资源&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多个过滤器的执行路径/顺序&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;服务器会按照web.xml中过滤器定义的先后顺序组装成一条链&lt;/li&gt;
      &lt;li&gt;具体:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;用户请求 -&amp;gt; 过滤器1(先filter开始，在chain.doFilter, 这里不执行filter结束, 而是执行第二个过滤器) -&amp;gt; 过滤器2(...) -&amp;gt; ... -&amp;gt; Servlet的Service方法 -&amp;gt; 过滤器n的end方法 -&amp;gt; ... -&amp;gt; 过滤器1的end方法 -&amp;gt; 响应用户请求&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 1 在web.xml中注册第二个filter
    &amp;lt;filter&amp;gt;
        &amp;lt;filter-name&amp;gt;Second&amp;lt;/filter-name&amp;gt;
        &amp;lt;filter-class&amp;gt;com.cole.filter.SecondFilter&amp;lt;/filter-class&amp;gt;
    &amp;lt;/filter&amp;gt;
    &amp;lt;filter-mapping&amp;gt;
        &amp;lt;filter-name&amp;gt;Second&amp;lt;/filter-name&amp;gt;
        &amp;lt;url-pattern&amp;gt;/login.jsp&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/filter-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 2 第二个过滤器
public class SecondFilter implements Filter {
    public void destroy() {
        System.out.println(&quot;SecondFilter destroy .... &quot;);
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        System.out.println(&quot;SecondFilter Start ... doFilter&quot; + new Date());
        chain.doFilter(req, resp);
        System.out.println(&quot;SecondFilter End ... doFilter&quot;);
    }

    public void init(FilterConfig config) throws ServletException {
        System.out.println(&quot;SecondFilter init .&quot;);
    }

}

/* 结果
Filter Init
SecondFilter init .

Filter Start ... doFilterTue Jul 21 09:54:59 CST 2015
SecondFilter Start ... doFilterTue Jul 21 09:54:59 CST 2015
SecondFilter End ... doFilter
Filter End ... doFilter
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;四-过滤器分类dispacther3类&quot;&gt;四-过滤器分类(Dispacther)(3类)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 四类(Servlet 2.x) / 五类(Servlet 3.x): 默认REQUEST
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REQUEST&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;用户直接访问页面或服务器response.sendRedirect时，Web容器将会调用过滤器&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FORWARD&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;服务器request.getRequestDispatcher(“URL”).forward(request, response);&lt;/li&gt;
          &lt;li&gt;目标资源通过RequestDespatcher的forward访问时，该过滤器将被调用.&lt;/li&gt;
          &lt;li&gt;jsp页面&lt;jsp:forward page=&quot;URL&quot;&gt;&lt;/jsp:forward&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INCLUDE&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;目标资源是通过RequestDispatcher的include方法调用时&lt;/li&gt;
          &lt;li&gt;jsp页面: &lt;jsp:include&gt;&lt;/jsp:include&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ERROR&lt;/code&gt;  :
        &lt;ul&gt;
          &lt;li&gt;目标资源是通过声明式异常处理机制调用时，过滤器将被调用&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(Servlet 3.x) ASYNC&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;支持异步处理&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ERROR&lt;/code&gt; 实例:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 过滤 404 错误自动到 Page Not Found
// 1. web.xml 注册错误页面和过滤器
    &amp;lt;!-- 自动跳转404 --&amp;gt;
    &amp;lt;error-page&amp;gt;
        &amp;lt;error-code&amp;gt;404&amp;lt;/error-code&amp;gt;
        &amp;lt;!-- 404.html 已经存在于 web-content 目录 --&amp;gt;
        &amp;lt;location&amp;gt;/404.html&amp;lt;/location&amp;gt;
    &amp;lt;/error-page&amp;gt;

    &amp;lt;!-- 捕捉 404 错误， 进行操作 --&amp;gt; 
    &amp;lt;filter&amp;gt;
        &amp;lt;filter-name&amp;gt;Error404&amp;lt;/filter-name&amp;gt;
        &amp;lt;filter-class&amp;gt;com.cole.filter.ErrorFilter&amp;lt;/filter-class&amp;gt;
    &amp;lt;/filter&amp;gt;
    &amp;lt;filter-mapping&amp;gt;
        &amp;lt;filter-name&amp;gt;Error404&amp;lt;/filter-name&amp;gt;
        &amp;lt;!-- 所有的页面的404错误都会自动到 /404.html --&amp;gt;
        &amp;lt;!-- 只需要捕捉 /404.html 页面即可 --&amp;gt;
        &amp;lt;url-pattern&amp;gt;/404.html&amp;lt;/url-pattern&amp;gt;
        &amp;lt;!-- 必须指定 dispatcher 包含 ERROR, 默认为REQUEST, 否则无法捕捉 --&amp;gt;
        &amp;lt;dispatcher&amp;gt;ERROR&amp;lt;/dispatcher&amp;gt;
    &amp;lt;/filter-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 2. Filter Class: com.cole.servlet.ErrorFilter.java
// 创建Filter的两种方法:
//      1. 右键new -&amp;gt; Filter (IDE大多类似)
//      2. 新建Java Class -&amp;gt; 继承 Filter -&amp;gt; 实现init doFilter destroy方法

public class ErrorFilter implements Filter {
    public void destroy () {
        System.out.println(&quot;销毁 Filter&quot;);
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        // 将 req 强制转换为 request 之后就可以用 request的很多方法 ..
        // 比如 response.sendRedirect, 
        // 比如 request.getResquestDispatcher(&quot;URL&quot;).forward(request, response);
        // HttpServletRequest request = (HttpServletRequest) req;
        // HttpServletResponse response = (HttpServletResponse) resp;
        System.out.println(&quot;开始 doFilter&quot;);
        // chain.doFilter是放行，显示 404 页面
        chain.doFilter(req, resp);
        System.out.println(&quot;结束 doFilter&quot;);
    }

    public void init(FilterConfig config) throws ServletException {
        System.out.println(&quot;初始化 Filter&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;3 Servlet 3.0 新Filter: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@WebFilter&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;1 定义: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注解(@)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;@WebFilter 用于将一个类声明为过滤器，该注解将会在部署时被容器处理，容器根据具体的属性配置将相应的类部署为过滤器.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 @WebFilter 常用属性&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;属性名&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;类型&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;描述&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;filterName&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定过滤器的name属性, 等价于 &lt;filter-name&gt;&lt;/filter-name&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;value&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String []&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;该属性等价于urlPatterns属性, 但是两者不应该同时使用 (value的优先级大于 urlPatterns)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;urlPatterns&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String []&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定一组过滤器的URL匹配模式, 等价于&lt;url-pattern&gt; 标签&lt;/url-pattern&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;servletNames&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String []&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定过滤器将用于哪些Servlet.取值是@WebFilter中的name属性的取值，或者是web.xml中&lt;servlet-name&gt;的取值&lt;/servlet-name&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;dispatcherTypes&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;DispatcherType&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定过滤器的转发模式. 具体取值包括 ASYNC ERROR FORWARD INCLUDE REQUEST&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;initParams&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;WebInitParam[]&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;指定一组初始化参数，等价于 &lt;init-param&gt;&lt;/init-param&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;asyncSupport&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;boolean&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;声明过滤器是否支持异步操作模式,等价于&lt;async-support&gt;标签&lt;/async-support&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;description&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;过滤器的描述信息, 等价于 &lt;description&gt;&lt;/description&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;displayName&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;该过滤器的现实名，通常配合工具使用，等价于&lt;display-name&gt;&lt;/display-name&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;@WebFilter (servletNames = {&quot;ErrorServlet&quot;}, filterName = &quot;Error404&quot;)

等价于

&amp;lt;filter&amp;gt;
    &amp;lt;filter-name&amp;gt;Error404&amp;lt;/filter-name&amp;gt;
    &amp;lt;filter-class&amp;gt;...&amp;lt;/filter-class&amp;gt;
&amp;lt;/filter&amp;gt;
&amp;lt;filter-mapping&amp;gt;
    &amp;lt;filter-name&amp;gt;Error404&amp;lt;/filter-name&amp;gt;
    &amp;lt;servlet-class&amp;gt;ErrorServlet&amp;lt;/servlet-class&amp;gt;
&amp;lt;/filter-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// WebFilter 实例
@WebFilter(filterName=&quot;MyAsyncFilter&quot;, value={&quot;/404.html&quot;}, 
    dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.ERROR, DispatcherType.ASYNC})
public class AsyncFilter implement Filter 
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;五案例&quot;&gt;五、案例&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;过滤器在实际项目中的应用场景
    &lt;ul&gt;
      &lt;li&gt;1 对用户请求进行统一认证&lt;/li&gt;
      &lt;li&gt;2 编码转换&lt;/li&gt;
      &lt;li&gt;3 对用户发送的数据进行过滤替换&lt;/li&gt;
      &lt;li&gt;4 转换图像格式&lt;/li&gt;
      &lt;li&gt;5 对响应的内容进行压缩&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;案例一-过滤编码&quot;&gt;案例一 过滤编码&lt;/h4&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 1. Servlet 2.x/3.x web.xml
&amp;lt;filter&amp;gt;
    &amp;lt;filter-name&amp;gt;EncodingFilter&amp;lt;/filter-name&amp;gt;
    &amp;lt;filter-class&amp;gt;com.cole.filter.EncodingFilter&amp;lt;/filter-class&amp;gt;
&amp;lt;/filter&amp;gt;
&amp;lt;filter-mapping&amp;gt;
    &amp;lt;filter-name&amp;gt;EncodingFilter&amp;lt;/filter-name&amp;gt;
    &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;
&amp;lt;/filter-mapping&amp;gt;

// 2. com.cole.filter.EncodingFilter.java
public class EncodingFilter implement Filter {
    public void destroy () {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        // 将request编码和response编码设置为urt-8，防止乱码
        req.setCharacterEncoding(&quot;utf-8&quot;);
        resp.setContentType(&quot;text/html;charset=utf-8&quot;);
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&quot;案例二-对用户请求进行统一认证&quot;&gt;案例二: 对用户请求进行统一认证&lt;/h4&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 1. Servlet 2.x/3.x web.xml
&amp;lt;filter&amp;gt;
    &amp;lt;filter-name&amp;gt;LoginFilter&amp;lt;/filter-name&amp;gt;
    &amp;lt;filter-class&amp;gt;com.cole.filter.LoginFilter&amp;lt;/filter-class&amp;gt;
&amp;lt;/filter&amp;gt;
&amp;lt;filter-mapping&amp;gt;
    &amp;lt;filter-name&amp;gt;LoginFilter&amp;lt;/filter-name&amp;gt;
        // 将request编码和response编码设置为urt-8，防止乱码
    &amp;lt;!-- 所有管理界面必须管理员登陆 --&amp;gt;
    &amp;lt;url-pattern&amp;gt;/admin/*&amp;lt;/url-pattern&amp;gt;
&amp;lt;/filter-mapping&amp;gt;

// 2. com.cole.filter.LoginFilter.java
public class LoginFilter implement Filter {
    public void destroy () {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        if (request.getSession().getAttribute(&quot;username&quot;) == null) {
            response.getWriter().println(&quot;&amp;lt;script&amp;gt;alert(&apos;请先登陆&apos;);window.location.href=&apos;/sign_in&apos;;&amp;lt;/script&amp;gt;&quot;);
            return ;
        }
 
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
    }
}
&lt;/code&gt;&lt;/pre&gt;

</description>
    <link>/2015/07/21/java-web-3-filter.html</link>
    <guid>/2015/07/21/java-web-3---filter</guid>
    <pubDate>Tue, 21 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Java Web (二) Servlet 基础</title>
    <description>
&lt;h3 id=&quot;一什么是servlet&quot;&gt;一、什么是Servlet&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1.1 定义
    &lt;ul&gt;
      &lt;li&gt;Servlet是在服务器上运行的小程序。一个Servlet就是一个Java类，并且可以通过”请求-响应”编程模型来访问这个主流在服务器内存里的Servlet程序.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二tomcat-容器等级&quot;&gt;二、Tomcat 容器等级&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;2.1 Tomcat的容器分为四个等级，Servlet的容器管理Context容器，一个Context对应一个Web工程.&lt;/li&gt;
  &lt;li&gt;2.2 等级:
    &lt;ul&gt;
      &lt;li&gt;1 Tomcat – 最外层
        &lt;ul&gt;
          &lt;li&gt;2 Container 容器
            &lt;ul&gt;
              &lt;li&gt;3 Engine
                &lt;ul&gt;
                  &lt;li&gt;4 HOST
                    &lt;ul&gt;
                      &lt;li&gt;5 Servlet容器
                        &lt;ul&gt;
                          &lt;li&gt;6 Context 1 + Context 2 + …&lt;/li&gt;
                        &lt;/ul&gt;
                      &lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三编写servlet&quot;&gt;三、编写Servlet&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;3.1 继承HttpServlet
    &lt;ul&gt;
      &lt;li&gt;1 Servlet(Interface): 三个方法: Init() service() destroy()&lt;/li&gt;
      &lt;li&gt;2 GenericServlet(Abstract Class): 与协议无关的Servlet&lt;/li&gt;
      &lt;li&gt;3 HttpServlet(Abstract Class): 实现Http协议的Servlet&lt;/li&gt;
      &lt;li&gt;4 自定义Servlet: 一般重写(覆盖) doGet、doPost方法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;3.2 重写doGet()或者doPost()方法&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;3.3 在web.xml中注册Servlet&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 1. 在src目录下新建包com.cole.servlet, 在servlet包下新建类HelloServlet.java
import javax.servlet.http.Servlet;
public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(&quot;处理Get请求&quot;);
        // 获取浏览器输出对象
        PrintWriter out = response.getWriter();
        // 要使下一句的html标签起作用
        response.setContentType(&quot;text/html;charset=utf-8&quot;);
        // 向浏览器输出
        out.println(&quot;&amp;lt;font color=&apos;red&apos;&amp;gt;Hello Servlet.&amp;lt;/font&amp;gt;&quot;);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(&quot;处理Post请求&quot;);
        // 获取浏览器输出对象
        PrintWriter out = response.getWriter();
        // 要使下一句的html标签起作用
        response.setContentType(&quot;text/html;charset=utf-8&quot;);
        // 想浏览器输出
        out.println(&quot;&amp;lt;font color=&apos;blue&apos;&amp;gt;Hello Servlet.&amp;lt;/font&amp;gt;&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 2 在web.xml中注册Servlet
    &amp;lt;servlet&amp;gt;
        &amp;lt;!-- servlet-name的名字可以任意取, 当然也可以是类名 --&amp;gt;
        &amp;lt;servlet-name&amp;gt;HelloServlet&amp;lt;/servlet-name&amp;gt;
        &amp;lt;!-- servlet-class的值必须是处理请求的Servlet的全路径 --&amp;gt;
        &amp;lt;servlet-class&amp;gt;com.cole.servlet.HelloServlet&amp;lt;/servlet-class&amp;gt;
    &amp;lt;/servlet&amp;gt;
    &amp;lt;servlet-mapping&amp;gt;
        &amp;lt;!-- servlet-name的名字必须和上面servlet中的servlet-name一样 --&amp;gt;
        &amp;lt;servlet-name&amp;gt;HelloServlet&amp;lt;/servlet-name&amp;gt;
        &amp;lt;!-- 访问Servlet的路径 --&amp;gt;
        &amp;lt;url-pattern&amp;gt;/helloservlet&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/servlet-mapping&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 3. index.jsp页面
&amp;lt;a href=&quot;/helloservlet&quot;&amp;gt;Get方式请求Servlet&amp;lt;/a&amp;gt;

&amp;lt;form action=&quot;/helloservlet&quot; method=&quot;post&quot;&amp;gt;
    &amp;lt;input type=&quot;submit&quot; value=&quot;Post方式请求Servlet&quot; /&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;三2ide编写servlet&quot;&gt;三、(2)IDE编写Servlet&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 src -&amp;gt; new -&amp;gt; Servlet&lt;/li&gt;
  &lt;li&gt;2 重写doGet()或者doPost()方法&lt;/li&gt;
  &lt;li&gt;3 部署servlet并运行&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四servlet生命周期&quot;&gt;四、Servlet生命周期&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;4.1 Servlet执行流程:
    &lt;ul&gt;
      &lt;li&gt;1 Get方式请求HelloServlet&lt;/li&gt;
      &lt;li&gt;2 在web.xml中的servlet-mapping寻找url-pattern -&amp;gt; servel-name&lt;/li&gt;
      &lt;li&gt;3 在web.xml中寻找servlet-name -&amp;gt; servlet-class&lt;/li&gt;
      &lt;li&gt;4 找到HelloServlet类&lt;/li&gt;
      &lt;li&gt;5 doGet方法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4.2 Servlet生命周期:
    &lt;ul&gt;
      &lt;li&gt;1 初始化阶段,执行init(ServletConfig)方法&lt;/li&gt;
      &lt;li&gt;2 响应客户端请求，调用service(Servlet Request Servlet Response)方法
        &lt;ul&gt;
          &lt;li&gt;由service根据提交方法选择doGet或doPost方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 关闭服务器，调用Destroy()方法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4.3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tomcat装载Servlet的三种情况&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;1 Servlet容器启动时自动装载某些Servlet, 实现它只需要web.xml文件中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;servlet&amp;gt;&amp;lt;/servlet&amp;gt;&lt;/code&gt;之间(的最后)添加如下代码&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;&lt;/code&gt;, 数字越小表示优先级越高.&lt;/li&gt;
      &lt;li&gt;2 在Servlet容器启动后，客户端首次向Servlet发送请求.&lt;/li&gt;
      &lt;li&gt;3 Servlet类文件被更新后，重新装载Servlet.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五servlet获取九大内置对象&quot;&gt;五、Servlet获取九大内置对象&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;5.1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;out&lt;/code&gt;: PrintWriter类型，由response.getWriter()获得&lt;/li&gt;
  &lt;li&gt;5.2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reequest&lt;/code&gt;: service方法中的req参数&lt;/li&gt;
  &lt;li&gt;5.3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;response&lt;/code&gt;: service方法中的resp参数&lt;/li&gt;
  &lt;li&gt;5.4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt;: req.getSession()获得&lt;/li&gt;
  &lt;li&gt;5.5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;application&lt;/code&gt;: getServletContext()函数&lt;/li&gt;
  &lt;li&gt;5.6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exception&lt;/code&gt;: Throwable&lt;/li&gt;
  &lt;li&gt;5.7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;page&lt;/code&gt;: this&lt;/li&gt;
  &lt;li&gt;5.8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pageContext&lt;/code&gt;: PageContext&lt;/li&gt;
  &lt;li&gt;5.9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Config&lt;/code&gt;: getServletCOnfig()函数&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六servlet与表单&quot;&gt;六、Servlet与表单&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;request
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getParameter()&lt;/code&gt;方法: 返回唯一值&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getParameterValues()&lt;/code&gt;: 返回数组&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date&lt;/code&gt;: new SimpleDateFormat(String pattern):
    &lt;ul&gt;
      &lt;li&gt;String format(Date d): 日期格式化成字符串&lt;/li&gt;
      &lt;li&gt;Date parse(String pattern): 字符串解析成日期
        &lt;ul&gt;
          &lt;li&gt;pattern必须与new SimpleDateFormat()中的pattern一致，否则异常&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七servlet路径跳转&quot;&gt;七、Servlet路径跳转&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;request.getRequestParameter(“URL”).forward(request, response);
    &lt;ul&gt;
      &lt;li&gt;“URL”中的”/”为项目根目录&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;response.sendRedirect(“URL”);
    &lt;ul&gt;
      &lt;li&gt;“URL”中的”/”为当前Servlet路径&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;1 绝对路径
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;request.getContextPath()&lt;/code&gt;: 获得上下文路径，项目的根目录&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 相对路径
    &lt;ul&gt;
      &lt;li&gt;response.sendRedirect(request.getContextPath() + “/test.jsp”);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;八项目实践&quot;&gt;八、项目实践&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 DBHelper&lt;/li&gt;
  &lt;li&gt;2 Entity&lt;/li&gt;
  &lt;li&gt;3 DAO&lt;/li&gt;
  &lt;li&gt;4 Servlet&lt;/li&gt;
&lt;/ul&gt;

</description>
    <link>/2015/07/19/java-servlet.html</link>
    <guid>/2015/07/19/java-servlet</guid>
    <pubDate>Sun, 19 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Java Web (一) JSP 基础</title>
    <description>
&lt;h3 id=&quot;四jsp内置对象&quot;&gt;四、JSP内置对象&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;4.4 Session的生命周期
    &lt;ul&gt;
      &lt;li&gt;1 创建:
        &lt;ul&gt;
          &lt;li&gt;当客户端第一次访问某个jsp或者Servlet时候，服务器会为当前会话创建一个SessionID, 每次客户端向服务器发送请求是，都会将SessionId携带过去，服务端会对此SessionID进行校验.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 活动:
        &lt;ul&gt;
          &lt;li&gt;a. 某次会话当中通过超链接打开的新页面属于同一次会话.&lt;/li&gt;
          &lt;li&gt;b. 只要当前会话页面没有全部关闭，重新打开新的浏览器窗口访问同一个项目资源属于同一次会话.&lt;/li&gt;
          &lt;li&gt;c. 除非本次会话的所有页面都关闭后，再重新访问某个JSP或者Servlet将会创建新的会话.
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 原有的会话依然存在，只是这个旧的SessionID仍然存在于服务端，只不过再也没有客户端携带它然后交予服务端校验。直到超时.&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 销毁: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Session的三种销毁方式&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;a. 调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session.invalidate()&lt;/code&gt;方法&lt;/li&gt;
          &lt;li&gt;b. Session过期(超时)&lt;/li&gt;
          &lt;li&gt;c. 服务器重启&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// JSP 页面 Session
&amp;lt;%
SimpleDateFormat sdf = new SimpleDateFormat();
// 设置session属性，在多个页面使用
session.setAttribute(&apos;username&apos;, &apos;admin&apos;);
session.setAttribute(&apos;password&apos;, &apos;123456&apos;);
session.setAttribute(&apos;age&apos;, 20);

// 设置当前session最大期限，单位是秒
session.setMaxInactiveInterval(10); // 10秒钟
%&amp;gt;

// getCreationTime() 默认返回1970到现在的秒数
Session的创建时间: &amp;lt;%=sdf.format(new Date(session.getCreationTime())) %&amp;gt;
Session最后访问时间: &amp;lt;%=sdf.format(new Date(session.getLastAccessedTime())) %&amp;gt;
Session TTL: &amp;lt;%=sdf.format(new Date(session.getMaxInactiveInterval())) %&amp;gt;
Session的ID: &amp;lt;%=session.getId() %&amp;gt;
从Session中获取用户名: &amp;lt;%=session.getAttribute(&quot;username&quot;) %&amp;gt;

&amp;lt;% session.invalidate(); // 销毁当前session %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;4.4.1 Session对象
    &lt;ul&gt;
      &lt;li&gt;Tomcat默认的session超时时间&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TTL&lt;/code&gt;为30分钟&lt;/li&gt;
      &lt;li&gt;设置超时时间有两种:
        &lt;ul&gt;
          &lt;li&gt;a. session.setMaxInactiveInterval(时间); // 单位是秒&lt;/li&gt;
          &lt;li&gt;b. 在web.xml配置&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 在web.xml中设置超时时间
&amp;lt;session-config&amp;gt;
    &amp;lt;!-- 单位是分钟,设置会话十分钟后超时 --&amp;gt;
    &amp;lt;session-timeout&amp;gt;10&amp;lt;/session-timeout&amp;gt;
&amp;lt;/session-config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;4.5 Application对象
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;特点&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;1 application对象实现了用户间数据的共享，可存放全局变量.&lt;/li&gt;
          &lt;li&gt;2 application开始于服务器启动，终止于服务器关闭.&lt;/li&gt;
          &lt;li&gt;3 在用户的前后连接或不同用户之间的连接中，可以对application对象的同一属性进行操作.&lt;/li&gt;
          &lt;li&gt;4 在任何地方对application对象属性的操作，都将影响到其他用户对此的访问&lt;/li&gt;
          &lt;li&gt;5 服务器的启动和关闭决定application对象的生命&lt;/li&gt;
          &lt;li&gt;6 application对象是ServletContext类的实例.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;常用方法&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public void setAttribute(String name, Object value)&lt;/code&gt;使用指定名称将对象绑定到此会话&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public Object getAttribute(String name)&lt;/code&gt;返回与此会话中的指定名称绑定在一起的对象; 如果没有对象绑定在该名称下，则返回null&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enumeration getAttributeNames()&lt;/code&gt;: 返回所有可用属性名的枚举&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String getServerInfo()&lt;/code&gt;: 返回JSP(SERVLET)引擎名及版本号&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;application中的属性有: &amp;lt;%
      Enumeration attributes = application.getAttributeNames();
      while (attributes.hasMoreElements()) {
        out.println(attributes.nextElement() + &quot;&amp;amp;nbsp;&amp;amp;nbsp;&quot;);
      }
    %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;4.6 Page对象
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;定义&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;Page对象是指当前JSP页面本身，有点像类中的this指针，它是java.lang.Object类的实例&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;常用方法&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class getClass()&lt;/code&gt;: 返回此Object的类&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int hashCode()&lt;/code&gt;: 返回此Object的hash码&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;boolean equals(Object obj)&lt;/code&gt;: 判断是否相等&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void copy(Object obj)&lt;/code&gt;: 将此Object拷贝到指定的Object对象中&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object clone()&lt;/code&gt;: 克隆此Object对象&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String toString()&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void notify()&lt;/code&gt;: 唤醒一个等待的线程&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void notifyAll()&lt;/code&gt;: 唤醒所有等待的线程&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void wait(int timeout)&lt;/code&gt;: 使一个线程处于等待知道timeout结束或被唤醒&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void wait()&lt;/code&gt;: 使一个线程等待直到被唤醒&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4.7 pageContext对象
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;特点&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;pageContext对象提供了对JSP页面内所有的对象及名字空间的访问&lt;/li&gt;
          &lt;li&gt;pageContext对象可以访问到本页所在的session, 也可以取本页面所在application的某一属性值&lt;/li&gt;
          &lt;li&gt;pageContext对象相当于页面中所有功能的集大成者&lt;/li&gt;
          &lt;li&gt;pageContext对象的本类名也叫pageContext&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;常用方法&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JspWriter getOut()&lt;/code&gt;: 返回当前客户端响应被使用的JspWriter流(out)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HttpSession getSession()&lt;/code&gt;: 返回当前页中的HttpSession对象(session)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object getPage()&lt;/code&gt;: 返回当前页的Page对象(page)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServletRequest getRequest()&lt;/code&gt;: 返回当前页的ServletRequest对象(request)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServletResponse getResponse()&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void setAttribute(String name, Object attribute)&lt;/code&gt;: 设置属性和值&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object getAttribute(String name, int scope)&lt;/code&gt;: 在指定范围内取属性的值&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int getAttributeScope(String name)&lt;/code&gt;: 返回某个属性的作用范围&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void forward(String relativeUrlPath)&lt;/code&gt;: 使当前页面重导到另一个页面&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void include(String relativeUrlPath)&lt;/code&gt;: 在当前位置包含另一文件&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4.8 Config对象
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;定义&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;config对象是在一个Servlet初始化时，JSP引擎向它传递信息用的，此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一个ServletContext对象), 常用方法如下:&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;常用方法&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServletContext getServletContext()&lt;/code&gt;: 返回含有服务器相关信息的ServletContext对象&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String getInitParameter(String name)&lt;/code&gt;: 返回初始化参数的值&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enumeration getInitParameterNames()&lt;/code&gt;: 返回Servlet初始化所需要参数的枚举&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4.9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Exception&lt;/code&gt; 对象
    &lt;ul&gt;
      &lt;li&gt;定义:
        &lt;ul&gt;
          &lt;li&gt;exception对象是一个异常对象,当一个页面在运行过程中发生了异常，就产生这个对象。如果一个JSP页面要应用此对象，就必须把isErrorPage设为true,否则无法编译。它实际上是java.lang.Throwable的对象.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;常用方法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String getMessage()&lt;/code&gt;: 返回描述异常的信息&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String toString()&lt;/code&gt;: 返回关于异常的简短描述信息&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;void printStackTrace()&lt;/code&gt;: 显示异常及其栈轨迹&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Throwable FillInStackTrace()&lt;/code&gt;: 重写异常的执行栈轨迹&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// 异常对象Exception
// Page 1. 当异常发生后，交给exception.jsp页面处理, 及跳转到exception.jsp页面
&amp;lt;%@ page ... errorPage=&quot;exception.jsp&quot; %&amp;gt;

&amp;lt;% 
    System.out.println(100/0); // 抛出运行时异常,算数异常
%&amp;gt;


// Page 2. exception.jsp页面
&amp;lt;%@page ... isErrorPage=&quot;true&quot; %&amp;gt;
异常消息: &amp;lt;%=exception.getMessage() %&amp;gt; &amp;lt;br&amp;gt;
简短消息: &amp;lt;%=exception.toString() %&amp;gt; &amp;lt;br&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;4.10 练习登陆:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;request.setCharacterEncoding(&quot;utf-8&quot;);&lt;/code&gt; : 防止中文乱码&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;request.getRequestDispatcher(&quot;login_success.jsp&quot;).forward(request, response)&lt;/code&gt;: 请求转发到login_success.jsp页面&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;response.sendRedirect(&quot;login_failure.jsp&quot;)&lt;/code&gt;: 请求重定向&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session.setAttribute(&quot;user&quot;, username)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五javabeans&quot;&gt;五、JavaBeans&lt;/h3&gt;

&lt;h3 id=&quot;六jsp状态管理&quot;&gt;六、JSP状态管理&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;6.1 HTTP协议无状态性
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;无状态&lt;/code&gt;是指，当浏览器发送请求给服务器的时候，服务器响应客户端请求。但是当同一个浏览器再次发送请求给服务器的时候，服务器并不知道它就是刚才哪个浏览器.即&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;服务器不会记住浏览器&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6.2 保存用户状态的两大机制
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Session&lt;/code&gt;机制&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cookie&lt;/code&gt;机制&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6.3 Cookie简介
    &lt;ul&gt;
      &lt;li&gt;是Web服务器保存在客户端的一系列文本信息.&lt;/li&gt;
      &lt;li&gt;典型应用:
        &lt;ul&gt;
          &lt;li&gt;判断用户是否登陆&lt;/li&gt;
          &lt;li&gt;“购物车”处理&lt;/li&gt;
          &lt;li&gt;是否记住密码&lt;/li&gt;
          &lt;li&gt;浏览记录&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;作用:
        &lt;ul&gt;
          &lt;li&gt;对特定对象的追踪&lt;/li&gt;
          &lt;li&gt;保存用户网页浏览记录与习惯&lt;/li&gt;
          &lt;li&gt;简化登录&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;缺点:
        &lt;ul&gt;
          &lt;li&gt;容易泄露用户信息&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6.4 Cookie的创建与使用
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建Cookie对象&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;Cookie newCookie = new Cookie(String key, Object value);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;写入Cookie对象&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;response.addCookie(newCookie);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;读取Cookie对象&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;Cookie[] cookies = request.getCookies();&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;常用方法:&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;方法名称&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;说明&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;void setMaxAge(int expiry)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;设置cookie的有效期，以秒问单位&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;void setValue(String value)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;在cookie创建后，对cookie进行赋值&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String getName()&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;获取cookie的名称&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;String getValue()&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;获取cookie的值&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;int getMaxAge()&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;获取cookie的有效时间,以秒为单位&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;    // JSP中使用Cookie实现记住用户名和密码功能
    // 设置请求编码
    request.setCharacterEncoding(&apos;utf-8&apos;);
    // 首页判断用户是否选择了记住登录密码
    String[] isUseCookies = request.getParameterValues(&quot;isUseCookie&quot;);
    if (isUseCookie != null &amp;amp;&amp;amp; isUseCookie.length &amp;gt; 0) {
        // 把用户名和密码保存在Cookie对象里面
        String username = request.getParameter(&quot;username&quot;);
        String password = request.getParameter(&quot;password&quot;);

        // 使用URLEncoder解决无法在Cookie中无法保存中文, java.net.*;
        // 相应的读取Cookie时要decode(attribute, charset);
        username = URLEncoder.encode(username, &apos;utf-8&apos;);
        password = URLEncoder.encode(password, &apos;utf-8&apos;);

        // 创建Cookie
        Cookie usernameCookie = new Cookie(&quot;username&quot;, username);
        Cookie passwordCookie = new Cookie(&quot;password&quot;, password);
        // 设置Cookie过期时间
        usernameCookie.setMaxAge(864000); // 10天
        passwordCookie.setMaxAge(864000);
        // 写入Cookie对象
        response.addCookie(usernameCookie);
        response.addCookie(passwordCookie);
    } else {
        // 获得Cookie对象
        Cookie[] cookies = request.getCookies();
        if (cookies != null &amp;amp;&amp;amp; cookies.length &amp;gt; 0) {
            for (Cookie c : cookies) {
                if (c.getName().equals(&quot;username&quot;) || 
                    c.getName().equals(&quot;password&quot;)) {
                    // 设置Cookie过期失效
                    c.setMaxAge(0);    
                    // 还必须添加到response, 重新保存
                    response.addCookie(c);
                }
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;6.5 Session与Cookie的对比&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Session&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Cookie&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;服务器&lt;/code&gt;端内存保存用户信息&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;客户端&lt;/code&gt;保存用户信息&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Session中保存的是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Object&lt;/code&gt;类型&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Cookie保存的是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;类型&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;随会话的结束二将其存储的数据销毁&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Cookie可以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;长期&lt;/code&gt;保存在客户端&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;保存&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;重要&lt;/code&gt;信息&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;保存&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;不重要&lt;/code&gt;信息&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;七指令与动作&quot;&gt;七、指令与动作&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;7.1 include指令: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSP三大指令: Page Include TagLib&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;语法: &amp;lt;%@ include file=”URL” %&amp;gt;
        &lt;ul&gt;
          &lt;li&gt;file属性: 包含要包含的页面&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7.2 include动作: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;动作标签&amp;lt;jsp:... /&amp;gt;&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;语法: &lt;jsp:include page=&quot;URL&quot; flush=&quot;true|false&quot;&gt;&lt;/jsp:include&gt;
        &lt;ul&gt;
          &lt;li&gt;page: 要包含的页面&lt;/li&gt;
          &lt;li&gt;flush: 被包含的页面是否从缓冲区读取&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7.3 include指令与include动作的区别&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;include 指令&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;jsp:include 动作&lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;语法格式&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;lt;%@ include file=”URL” %&amp;gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;lt;jsp:include page=”URL” flush=”true&lt;/td&gt;
      &lt;td&gt;false”/&amp;gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;发生作用的时间&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;页面转换期间&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;请求期间&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;包含的内容&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;文件的实际内容&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;页面的输出&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;转换成的Servlet&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;主页面和包页面转换为一个Servlet&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;主页面和包页面转换为独立的Servlet&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;编译时间&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;较慢–资源必须被解析&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;较快&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;执行时间&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;稍快&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;较慢–每次资源必须被解析&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;7.4 &lt;jsp:forward&gt; 动作
&lt;/jsp:forward&gt;    &lt;ul&gt;
      &lt;li&gt;语法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;jsp:forward page=&quot;URL&quot; /&amp;gt;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;等同于: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;request.getRequestDispatcher(&quot;/url&quot;).forward(request, response);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;解决request.getParameter乱码&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;request.setCharacterEncoding(&quot;utf-8&quot;);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7.5 &lt;jsp:param&gt; 动作
&lt;/jsp:param&gt;    &lt;ul&gt;
      &lt;li&gt;语法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;jsp:param name=&quot;参数名&quot; value=&quot;参数值&quot; /&amp;gt;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;常与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;jsp:forward ... &amp;gt;...&amp;lt;/jsp:forward&amp;gt;&lt;/code&gt;一起使用，作为其子标签&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;作用:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;设置键值，然多页面获取&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;修改其他页面传过来的键值&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&quot;language-Java&quot;&gt;// &amp;lt;jsp:param &amp;gt;
    &amp;lt;jsp:forward page=&quot;user.jsp&quot;&amp;gt;
        &amp;lt;jsp:param name=&quot;email&quot; value=&quot;admin@126.com&quot; /&amp;gt;
    &amp;lt;/jsp:forward&amp;gt;
// 其他页面可以用
// request.getParamter获取
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
  &lt;li&gt;7.6 &lt;jsp:plugin&gt; 动作&lt;/jsp:plugin&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;八实际案例&quot;&gt;八、实际案例:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;实现DBHelper类(util包)&lt;/code&gt;: 只做数据库静态连接与断开&lt;/li&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建实体类(entity包)&lt;/code&gt;: 起名规则:表名, 所有实体类符合JavaBeans思想&lt;/li&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建业务逻辑类(DAO)(dao包)&lt;/code&gt;: 起名规则: entity名+”DAO”&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/07/17/jsp-getting-started.html</link>
    <guid>/2015/07/17/jsp-getting-started</guid>
    <pubDate>Fri, 17 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux NetWok Bridge(创建网桥)</title>
    <description>
&lt;h2 id=&quot;wiki&quot;&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Network_bridge&quot;&gt;Wiki&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;一通过iproute2ip创建网桥-bridge_name&quot;&gt;一、通过iproute2/ip创建网桥 bridge_name&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 网桥创建／删除:
    &lt;ul&gt;
      &lt;li&gt;创建:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip link add name bridge_name type bridge&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;删除:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip link delete bridge_name type bridge&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 IP网段:
    &lt;ul&gt;
      &lt;li&gt;设置:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip addr add 172.20.1.1/80 dev bridge_name&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;删除:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip addr del 172.20.1.1/80 dev bridge_name&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 启动/关闭网桥:
    &lt;ul&gt;
      &lt;li&gt;启动: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip link set bridge_name up&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;关闭: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip link set bridge_name down&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二实际案例-虚拟机vbox中ubuntuserver1410桥接新建的网桥bridge_name&quot;&gt;二、实际案例: 虚拟机Vbox中UbuntuServer14.10桥接新建的网桥bridge_name&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 虚拟机网络选择适配器(Adapter):
    &lt;ul&gt;
      &lt;li&gt;Bridged Adapter(桥接) -&amp;gt; bridge_name -&amp;gt; Cable Connected&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 Ubuntu 设置:
    &lt;ul&gt;
      &lt;li&gt;临时配置
        &lt;ul&gt;
          &lt;li&gt;IP: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ifconfig eth0 172.20.1.2 netmask 255.255.255.0&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;Gateway: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;route add default gw 172.20.1.1&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 现在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;主机可以通过172.10.1.1访问UbuntuServer&lt;/code&gt;了&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三网桥联网&quot;&gt;三、网桥联网&lt;/h3&gt;
</description>
    <link>/2015/07/11/linux-netwok-bridge.html</link>
    <guid>/2015/07/11/linux-netwok-bridge</guid>
    <pubDate>Sat, 11 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Java Getting Started</title>
    <description>
&lt;h3 id=&quot;一基础&quot;&gt;一、基础&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 八个基本数据类型
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;boolean&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;char&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;byte&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;short&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;int&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;long&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;float&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;double&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 数据类型:
    &lt;ul&gt;
      &lt;li&gt;float a = 3.14f; // 必须声明为3.14f, 否则3.14为double类型, 出错&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三面向对象基础&quot;&gt;三、面向对象基础:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;默认、abstract、interface、final、static
    &lt;ul&gt;
      &lt;li&gt;抽象类 = 抽象方法public abstract + 普通方法 (抽象方法必须实现，普通方法不必)&lt;/li&gt;
      &lt;li&gt;接口 (特殊的抽象类，即抽象类的方法全为抽象方法)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;单继承　多实现&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 方法:
    &lt;ul&gt;
      &lt;li&gt;1 值传递和址传递
        &lt;ul&gt;
          &lt;li&gt;值传递: 传变量, 只是传变量值的拷贝&lt;/li&gt;
          &lt;li&gt;址传递: 传对象, 先在栈区创建引用类型的变量，然后再在堆区创建对象属性.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 构造方法 注意:
        &lt;ul&gt;
          &lt;li&gt;系统默认创建一个无参的构造方法； 但是如果你手动创建一个有参的构造方法，则系统不会默认创建无参的构造方法，即不能使用无参的构造方法; 若仍想使用，必须显示创建无参构造方法.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 方法重载:
        &lt;ul&gt;
          &lt;li&gt;原则(3):
            &lt;ul&gt;
              &lt;li&gt;在同一个类中&lt;/li&gt;
              &lt;li&gt;方法名相同&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;参数列表必须不同, 返回类型可以相同，即参数个数、或对应位置数据类型不同&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 参数相同但返回值类型不同不是重载&lt;/code&gt;
                &lt;ul&gt;
                  &lt;li&gt;继承: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;是覆盖&lt;/code&gt;&lt;/li&gt;
                  &lt;li&gt;没有继承: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;是BUG&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 可变参数:
        &lt;ul&gt;
          &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DataType ...variable&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;Usage: 可变参数相当于一个数组&lt;/li&gt;
          &lt;li&gt;栗子&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&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;a&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;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;b&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&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;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&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;sum&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;ul&gt;
  &lt;li&gt;4 封装和访问控制
    &lt;ul&gt;
      &lt;li&gt;1 概念:
        &lt;ul&gt;
          &lt;li&gt;Java引入包(package)的机制，提供了类的多层命名空间，解决了类的命名冲突、类文件管理等问题.&lt;/li&gt;
          &lt;li&gt;借助于包，可以将自己定义的类与其他类库中的类分开管理.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 定义包:
        &lt;ul&gt;
          &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package pk_name;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;1 package语句必须作为Java原文件的第一条非注释性语句;&lt;/li&gt;
              &lt;li&gt;2 一个Java源文件只能指定一个包，即只有一条package语句;&lt;/li&gt;
              &lt;li&gt;3 定义包之后，Java源文件中可以定义多个类，这些类将全部位于包内&lt;/li&gt;
              &lt;li&gt;4 多个Java源文件可以定义相同的包&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意2&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;1 在物理组织上，包的表现形式为目录&lt;/li&gt;
              &lt;li&gt;2 但并不等同与手工创建目录后将类拷贝过去就行，必须保证类中代码声明包含包名与目录一直才行&lt;/li&gt;
              &lt;li&gt;3 包名规范性: 公司域名反写.项目名.模块名, com.cole.proj.calendar.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 导入包 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;总结&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;1 * 指明导入当前包的所有类, 但不能使用’java.&lt;em&gt;’ 或者 ‘java.&lt;/em&gt;.*‘这种语句来导入以java为前缀的所有包的所有类.&lt;/li&gt;
          &lt;li&gt;2 一个Java源文件只能有一条package语句&lt;/li&gt;
          &lt;li&gt;3 但可以有多条import语句，且package语句在import之前&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 封装
        &lt;ul&gt;
          &lt;li&gt;1 概念:
            &lt;ul&gt;
              &lt;li&gt;封装是面向对象的特性之一，它实际上通过访问控制符来实现访问控制&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;2 访问控制符(4):
            &lt;ul&gt;
              &lt;li&gt;private: 私有&lt;/li&gt;
              &lt;li&gt;缺省: 可以被同一个包中的所有类访问&lt;/li&gt;
              &lt;li&gt;protected: 继承&lt;/li&gt;
              &lt;li&gt;public: 公开&lt;/li&gt;
              &lt;li&gt;实例:
                &lt;ul&gt;
                  &lt;li&gt;类名只能用不修饰(本包可见), public, abstract, static, final来控制访问权限&lt;/li&gt;
                  &lt;li&gt;文档注释: /** … */&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 静态成员
    &lt;ul&gt;
      &lt;li&gt;定义:
        &lt;ul&gt;
          &lt;li&gt;Java中可以使用static关键字修饰类的成员变量和方法, 这些被static关键字修饰的成员也称为静态成员&lt;/li&gt;
          &lt;li&gt;静态成员的限制级别是”类相关”的&lt;/li&gt;
          &lt;li&gt;与类相关的静态成员被成员类变量或类方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;调用:
        &lt;ul&gt;
          &lt;li&gt;静态方法可以被类名直接调用: ClassName.StaticMember&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;总结:
        &lt;ul&gt;
          &lt;li&gt;1 公用静态变量: 一个类的静态成员会被该类所有实例对象共同使用&lt;/li&gt;
          &lt;li&gt;2 类的静态变量和静态方法，在内存中只有一份，工所有对象共用，起到全局的作用.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6 对象数组
    &lt;ul&gt;
      &lt;li&gt;1 基本数组的定义:
        &lt;ul&gt;
          &lt;li&gt;int [] a = new int[2]; a[0]=2; a[1]=3;&lt;/li&gt;
          &lt;li&gt;int [] a = new int[]{2, 3};&lt;/li&gt;
          &lt;li&gt;int [] a = {2, 3};&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 对象数组: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ClassName[] var = new ClassName[count]&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;3 对象数组在内存中的存储:
        &lt;ul&gt;
          &lt;li&gt;声明对象数组变量时，在栈区为数组的每个元素都开辟一个引用的空间, 对象数组变量也在栈区&lt;/li&gt;
          &lt;li&gt;然后在堆内存为每个元素初始化对应的元素对象&lt;/li&gt;
          &lt;li&gt;再把元素对象在堆内存的地址赋给栈区的每个元素&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s1&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;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s1&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;o&quot;&gt;]&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;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;1&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&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;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;2&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s2&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;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&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;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;1&apos;&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;nf&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;2&apos;&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;nc&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s3&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;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;1&apos;&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;nf&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sc&quot;&gt;&apos;2&apos;&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;h3 id=&quot;四核心类&quot;&gt;四、核心类&lt;/h3&gt;
&lt;h4 id=&quot;1-基本类型的封装类&quot;&gt;1 基本类型的封装类&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 封装类的概念
    &lt;ul&gt;
      &lt;li&gt;Java语言: 完全面向对象&lt;/li&gt;
      &lt;li&gt;8个基本数据类型也具备对应对象.&lt;/li&gt;
      &lt;li&gt;通过封装类可以把基本类型封装成对象使用.&lt;/li&gt;
      &lt;li&gt;从JDK1.5开始，Java允许将基本类型的值直接赋值给对应的封装类对象&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;// 封装类(引用类, Reference types)转换为基本类型(Primitive types)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//      封装类型名.xxxValue() 来取得基础类型值&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//          xxx指的是基本类型(Primitive Types)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;Integer&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;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&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;c1&quot;&gt;// 自动转换&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&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;na&quot;&gt;intValue&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;kt&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&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;na&quot;&gt;floatValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// boolean Boolean &lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// char   Character // *&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// byte   Byte&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// short  Short&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// int    Integer // *&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// long   Long&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// float  Float&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// double Double&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 封装类的作用
    &lt;ul&gt;
      &lt;li&gt;1 将字符串的值转换为基本类型
        &lt;ul&gt;
          &lt;li&gt;a.直接调用封装类的构造方法, 即Xxx(String s)&lt;/li&gt;
          &lt;li&gt;b.调用封装类提供的parseXxx(String s)静态方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 将基本类型转换为字符:
        &lt;ul&gt;
          &lt;li&gt;a.直接使用空字符串链接, ““+123&lt;/li&gt;
          &lt;li&gt;b.调用封装类提供的toString()静态方法, Integer.toString(123);&lt;/li&gt;
          &lt;li&gt;c.调用String类提供的valueOf()方法, String.valueOf(123);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 1 字符串转为基本类型
int num1 = new Integer(&quot;10&quot;);
int num2 = Integer.parseInt(&quot;10&quot;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-装箱和拆箱&quot;&gt;2 装箱和拆箱&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 定义:
    &lt;ul&gt;
      &lt;li&gt;装箱: 是指将基本数据类型值转换为对应的封装类对象，即将栈中的数据封装成对象存到堆中的过程.&lt;/li&gt;
      &lt;li&gt;拆箱: 装箱的反过程&lt;/li&gt;
      &lt;li&gt;基本数据类型与其对应封装类之间能够自由进行转换，七本质是Java的自动装箱和拆箱过程.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 目的:
    &lt;ul&gt;
      &lt;li&gt;实现基本数据类型和其对应封装类之间的自动转换&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 装箱
Integer obj = 10;
// 装箱的隐藏过程: obj = new Integer(10);

// 拆箱
int a = obj;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;3-object-类&quot;&gt;3 Object 类&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 介绍
    &lt;ul&gt;
      &lt;li&gt;Java基础类库：Object, String, Math等&lt;/li&gt;
      &lt;li&gt;Object对象类定义在java.lang包中, 是所有类的顶级父类&lt;/li&gt;
      &lt;li&gt;在Java体系中，所有类直接或间接的继承了Object类.&lt;/li&gt;
      &lt;li&gt;因此，任何Java对象都可以调用Object类中的方法，而且任何类型的对象都可以赋给Object类型的变量.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 JDL文档和关联src源码
    &lt;ul&gt;
      &lt;li&gt;Ctrl + 鼠标左键 -&amp;gt; 对类名&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 Object类的常用方法
    &lt;ul&gt;
      &lt;li&gt;1 equals()方法:
        &lt;ul&gt;
          &lt;li&gt;对基本类型: == 比较两个变量值相等&lt;/li&gt;
          &lt;li&gt;对(引用类型的)对象
            &lt;ul&gt;
              &lt;li&gt;== 标胶两个对象地址是否相等，即引用同一个对象&lt;/li&gt;
              &lt;li&gt;equals通常可以用于比较两个对象的内容是否相同&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 由于==比较是对象的地址，所以两个对象永远不会相等, equal是比较内容，则只要内容相等即可相等&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;查看equals方法, Ctrl+鼠标左键&lt;/li&gt;
          &lt;li&gt;自定义类，需要重写equals方法，否则用的是Object.equals&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 toString()方法:
        &lt;ul&gt;
          &lt;li&gt;在没有重写toString()方法之前
            &lt;ul&gt;
              &lt;li&gt;System.out.print(obj) 输出的是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;对象名@hashCode&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;System.out.print(obj.toString()) 输出的是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;对象名@hashCode&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;Object.toString 源码
                &lt;ul&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return this.getClass().getName() + &quot;@&quot; + Integer.toHexString(this.hashCode());&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;重写toString()方法后, 以上情况都是toString()方法的内容&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;protected Object clone()&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;public boolean equals(Object)&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;protected void finalize()&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;public final Class&amp;lt;?&amp;gt; getClass()&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;public int hashCode()&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;public String toString()&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;h4 id=&quot;4-string-stringbuffer-stringbuilder&quot;&gt;4 String StringBuffer StringBuilder&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 运算顺序: 从左到右, 最后都要转换为字符串
    &lt;ul&gt;
      &lt;li&gt;“str” + 10 + 20 ==&amp;gt; “str1020” // 直接与字符串拼接&lt;/li&gt;
      &lt;li&gt;10 + 20 + “str” ==&amp;gt; “30str” // 先其他类型相加，在与字符串拼接&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;length()&lt;/li&gt;
      &lt;li&gt;subString(int begin Index [, int endIndex])&lt;/li&gt;
      &lt;li&gt;lastIndexOf(String str [[, formIndex] …])&lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;toLowerCase()&lt;/td&gt;
              &lt;td&gt;toUpperCase()&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;String([char[] value&lt;/td&gt;
              &lt;td&gt;String s&lt;/td&gt;
              &lt;td&gt;StringBuffer bs&lt;/td&gt;
              &lt;td&gt;STringBuilder sb])&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;char charAt(int index)&lt;/li&gt;
      &lt;li&gt;int compareTo(String s): == return 0&lt;/li&gt;
      &lt;li&gt;boolean endsWith(String s)&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;更多: Ctrl + &amp;lt;- ==&amp;gt; String&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 StringBuffer 类
    &lt;ul&gt;
      &lt;li&gt;1 StringBuffer用来创建和操作字符串对象，和String区别:
        &lt;ul&gt;
          &lt;li&gt;1 String创建的字符串是不可变的，如果改变字符串，是在内存中创建一个新的字符串，字符串变量将引用新创建的字符串地址，而原来的字符串在内存中依然存在且内容不变，直到Java的垃圾回收系统对七进行销毁.&lt;/li&gt;
          &lt;li&gt;2 StringBuffer创建的字符串是可变的,当使用StringBuffer创建一个字符串后，该字符串内容可以通过append(),insert,setCharAt()等方法改变，而字符串变量所引用的地址一直不变，最终调用它的toString()方法转换成一个String对象.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 常用方法:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;StringBuffer(&lt;/td&gt;
                  &lt;td&gt;String&lt;/td&gt;
                  &lt;td&gt;int capacity&lt;/td&gt;
                  &lt;td&gt;CharSequence seq)&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
          &lt;li&gt;length()&lt;/li&gt;
          &lt;li&gt;capacity() // 容量&lt;/li&gt;
          &lt;li&gt;append(String)&lt;/li&gt;
          &lt;li&gt;insert(int index, String)&lt;/li&gt;
          &lt;li&gt;replace(int start, int end, String str)&lt;/li&gt;
          &lt;li&gt;int delete(int start, int end)&lt;/li&gt;
          &lt;li&gt;StringBuffer reverse();&lt;/li&gt;
          &lt;li&gt;void setLength(int newLength)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;More Ctrl + &amp;lt;- == &amp;gt; StringBuffer Or JDK Doc&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 StringBuilder
    &lt;ul&gt;
      &lt;li&gt;和StringBuffer类似&lt;/li&gt;
      &lt;li&gt;但是, StringBuffer是线程安全(即线程同步, synchronized)，StringBuilder没有实现线程安全&lt;/li&gt;
      &lt;li&gt;因此, StringBuilder性能较好&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;5-scanner类&quot;&gt;5 Scanner类&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 构造方法:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Scanner(InputStream source [, String charsetName])&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;栗子:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Scanner scanner = new Scanner(System.in);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;next()&lt;/li&gt;
      &lt;li&gt;nextInt()&lt;/li&gt;
      &lt;li&gt;nextFloat()&lt;/li&gt;
      &lt;li&gt;nextDouble()&lt;/li&gt;
      &lt;li&gt;hasNext&lt;a href=&quot;&quot;&gt;Xxx&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;useDelimiter(String): 设置分隔符，否则遇到空格就结束提取字符串&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;More: Ctrl + &amp;lt;- ==&amp;gt; Scanner&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;6-math-and-date-class&quot;&gt;6 Math and Date Class&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 Math提供的方法是静态的，可以直接调用Math.method()
    &lt;ul&gt;
      &lt;li&gt;abs(double a)&lt;/li&gt;
      &lt;li&gt;ceil(double a): 上界&lt;/li&gt;
      &lt;li&gt;floor(double a): 下界&lt;/li&gt;
      &lt;li&gt;round(double a):&lt;/li&gt;
      &lt;li&gt;max(doubale a, double b) &amp;lt;==&amp;gt; min&lt;/li&gt;
      &lt;li&gt;random(): 0-1 随机数
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UUID.randomUUID()&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;More: C-Left Or Doc&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 Date
    &lt;ul&gt;
      &lt;li&gt;1 构造方法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date()&lt;/code&gt; : Today&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date(long milliSeconds)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date(int year, int month, int date)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date(int year, int month, int date, int hrs, int min [, int sec])&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date(String s)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 常用方法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;boolean after(Date when)&lt;/code&gt;: return getMillisOf(this) &amp;gt; getMillisOf(when);&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;boolean before(Date when)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;7-simpledateformat&quot;&gt;7 SimpleDateFormat&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 构造函数
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public SimpleDateFormat()&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public SimpleDateFormat(String pattern)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public SimpleDateFormat(String patternm Locale local)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;public final String format(Date date)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 SimpleDateFormat日期-时间格式模式参数&lt;/li&gt;
&lt;/ul&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: left&quot;&gt;日期或时间元素&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;表示&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;示例&lt;/th&gt;
      &lt;th&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;G&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Era&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;标志符&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Text&lt;/td&gt;
      &lt;td&gt;AD&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;y&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;年&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Year&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;1996, 96&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;M&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;年中的月份&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Month&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;July; Jul; 07&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;d&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;月中的天数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;10&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;H&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;一天中的小时数(0-23)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;h&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;am/pm中的小时数(1-12)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;12&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;m&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;小时中的分钟数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;30&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;s&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;分钟中的秒数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;55&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;S&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;毫秒数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;978&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;w&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;年中的周数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;27&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;W&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;月中的周数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;D&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;年中的天数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;189&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;F&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;月中的星期&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;2&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;E&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;星期的天数&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Text&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Tuesday; Tue&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;a&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Am/Pm标记&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Text&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;PM&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;k&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;一天中的小数数(24-1-23)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;24&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;K&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;am/pm中的小时数(1-11-0)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Number&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;0&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;z&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;时区&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;General&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;time zone&lt;/td&gt;
      &lt;td&gt;Pacific Standard Time; PST; GMT-08:00&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Z&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;时区&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;RFC 822&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;time zone&lt;/td&gt;
      &lt;td&gt;-0800&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;4 SimpleDateFormat Example&lt;/li&gt;
&lt;/ul&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;nc&quot;&gt;Date&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&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;nc&quot;&gt;Date&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;// yyyy/MM/dd HH:mm:ss ==&amp;gt; 2015/07/13 14:02:15&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// yyyy/MM/dd          ==&amp;gt; 2015/07/13&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// HH:mm:ss            ==&amp;gt; 14:02:15&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// yy-MM-dd            ==&amp;gt; 15-07-13&lt;/span&gt;

&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;datePattern&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;yyyy/MM/dd HH:mm:ss&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;SimpleDateFormat&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sdf&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;nc&quot;&gt;SimpleDateFormat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;datePattern&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nc&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;sdf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Result: 2015/07/13 14:02:15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;8-system&quot;&gt;8 System&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 构造方法:
    &lt;ul&gt;
      &lt;li&gt;由于该类的构造方法是private的，所以无法创建该类的对象(实例化), 其内部的成员变量和成员方法都是static的，方法可以有类直接调用.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 成员变量和方法:
    &lt;ul&gt;
      &lt;li&gt;属性:
        &lt;ul&gt;
          &lt;li&gt;in 标准输入&lt;/li&gt;
          &lt;li&gt;out 标准输出&lt;/li&gt;
          &lt;li&gt;err 标准出错&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;方法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;// System类方法&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 1. arraycopy : 该方法的作用是数组拷贝，也就是将一个数组中的内容复制到另外一个数组中的指定位置，由于该方法是native方法，所以性能上比使用循环高效。&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  Syntax: public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  Example:&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&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;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&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;mi&quot;&gt;4&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;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&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;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// b = {0, 0, 0, 0, 0}&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;arraycopy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&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;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// b = {0, 0, 0, 2, 3};&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;// 2. currentTimeMillis: 长整型, 返回当前计算机时间&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//      应用: 计算程序运行时间&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&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;i&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;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000000000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&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;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&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;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;currentTimeMillis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;start&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;// 3. exit: 用于退出程序&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  Syntax: public static void exit(int status);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//      statue: 0 表示正常退出; 否则异常退出&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 4. gc方法: 请求系统进行垃圾回收，至于系统是否立刻回收，则取决于系统中垃圾回收算法的实现以及系统执行时的情况。&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  Syntax: public static void gc();&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;// 5 getProperty方法: 获得系统属性名为key的属性对应的值&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  Syntax: public static String getProperty(String key);&lt;/span&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;c1&quot;&gt;// java.version     Java版本&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// java.home        Java安装目录&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// os.name          操作系统名称&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// os.version       操作系统(内核)版本&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// user.name        用户账户名称&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// user.home        家目录&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// user.dir         用户当前工作目录&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Example:&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;osName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;os.name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nc&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;Java Version: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;java.version&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;Java Home: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;java.home&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;OS name: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;os.name&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;OS Version: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;os.version&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;User Name: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user.name&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;User Home: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user.home&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;s&quot;&gt;&quot;\n&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;User Dir: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getProperty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user.dir&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;9-runtime&quot;&gt;9 Runtime&lt;/h4&gt;

&lt;h3 id=&quot;四核心类二-collection-集合&quot;&gt;四、核心类(二) Collection 集合&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;树形家族Collection
    &lt;ul&gt;
      &lt;li&gt;Set
        &lt;ul&gt;
          &lt;li&gt;HashSet&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Queue
        &lt;ul&gt;
          &lt;li&gt;Deque&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;List
        &lt;ul&gt;
          &lt;li&gt;ArrayList&lt;/li&gt;
          &lt;li&gt;Vector&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Map
        &lt;ul&gt;
          &lt;li&gt;HashMap&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;421-hashset-是基于hashmap的key保存的hashset元素&quot;&gt;4.2.1 HashSet: 是基于HashMap的key保存的HashSet元素&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;特点: 无序、不重复&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;1 构造函数:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashSet();&lt;/code&gt;: Set&lt;String&gt; = new HashSet&lt;String&gt;();&lt;/String&gt;&lt;/String&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashSet(Collection&amp;lt;? extends E&amp;gt; c);&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashSet(int initialCapacity [, float loadFactor]);&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;boolean add(DataType variable);&lt;/li&gt;
      &lt;li&gt;Iterator &lt;E&gt; iterator(): 返回对此 set 中元素进行迭代的迭代器。返回元素的顺序并不是特定的。&lt;/E&gt;&lt;/li&gt;
      &lt;li&gt;int size()&lt;/li&gt;
      &lt;li&gt;void clear();&lt;/li&gt;
      &lt;li&gt;boolean isEmpty()&lt;/li&gt;
      &lt;li&gt;boolean contains(Object o)&lt;/li&gt;
      &lt;li&gt;boolean remove(Object o)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;// 1 创建String类型的HashSet并添加元素&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hSet&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;nc&quot;&gt;HashSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h2&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h3&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h2&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h1&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 2 迭代输出Set的值&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;Iterator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;iterator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;hasNext&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;nc&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;it&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;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;422-arraylist-vector&quot;&gt;4.2.2 ArrayList Vector&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;特点: 有序、可重复&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;1 构造函数
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayList()&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayList(Collection&amp;lt;? extends E&amp;gt; c);&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArrayList(int initialCapacity);&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;boolean add([int index, ] E element);&lt;/li&gt;
      &lt;li&gt;void addAll(Collection&amp;lt;? extends E&amp;gt; c);&lt;/li&gt;
      &lt;li&gt;void clear();&lt;/li&gt;
      &lt;li&gt;boolean contains(Object o);&lt;/li&gt;
      &lt;li&gt;E get(int index);&lt;/li&gt;
      &lt;li&gt;int indexOf(Object o);&lt;/li&gt;
      &lt;li&gt;int lastIndexOf(Object o);&lt;/li&gt;
      &lt;li&gt;boolean isEmpty();&lt;/li&gt;
      &lt;li&gt;E remove(int index);&lt;/li&gt;
      &lt;li&gt;boolean remove(Object o);&lt;/li&gt;
      &lt;li&gt;protected removeRange(int fromIndex, int toIndex);&lt;/li&gt;
      &lt;li&gt;int size();&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&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;// 1 创建ArrayList并添加元素&lt;/span&gt;
    &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;aList&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;aList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;123&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;aList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;456&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;aList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;456&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&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;i&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;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&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;i&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;nc&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;aList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&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;h4 id=&quot;423-hashmap&quot;&gt;4.2.3 HashMap&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 构造函数
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashMap()&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashMap(int initialCapacity [, float loadFactor])&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HashMap(Map&amp;lt;? extends K, ? extends V&amp;gt; m)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 常用方法:
    &lt;ul&gt;
      &lt;li&gt;V put(K key, V value);&lt;/li&gt;
      &lt;li&gt;void putAll(Map&amp;lt;? extends K, ? extends V&amp;gt; m);&lt;/li&gt;
      &lt;li&gt;int size();&lt;/li&gt;
      &lt;li&gt;V get(Object key);&lt;/li&gt;
      &lt;li&gt;boolean isEmpty();&lt;/li&gt;
      &lt;li&gt;V remove(Object key);&lt;/li&gt;
      &lt;li&gt;Set&lt;K&gt; keySet(); // 获得键集合&lt;/K&gt;&lt;/li&gt;
      &lt;li&gt;Collection&lt;V&gt; values(); // 返回此映射所包含的值&lt;/V&gt;&lt;/li&gt;
      &lt;li&gt;boolean containsKey(Object key);&lt;/li&gt;
      &lt;li&gt;boolean containsValue(Object value);&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// HashMap Sample
Map&amp;lt;Object, Object&amp;gt; map = new HashMap&amp;lt;Object, Object&amp;gt;();
        map.put(&quot;username&quot;, &quot;gardom&quot;);
        map.put(&quot;password&quot;, &quot;123456&quot;);
        map.put(&quot;administer&quot;, &quot;0&quot;);

        Iterator&amp;lt;Object&amp;gt; it = map.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            System.out.println(key + &quot;: &quot; +map.get(key));
        }
        
        System.out.println(map.keySet());
        System.out.println(map.values());
        System.out.println(map.size());
        System.out.println(map.hashCode());
        System.out.println(map.containsKey(&quot;username&quot;));
        System.out.println(map.containsValue(&quot;123456&quot;));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五类之间的关系&quot;&gt;五、类之间的关系&lt;/h3&gt;

&lt;h4 id=&quot;1-继承与多态&quot;&gt;1 继承与多态&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;1 继承(inheritance): extends
    &lt;ul&gt;
      &lt;li&gt;1 父类与子类:
        &lt;ul&gt;
          &lt;li&gt;被继承的类, 称为基类(base class)，父类(parent class)或超类(super class)&lt;/li&gt;
          &lt;li&gt;继承者, 称为子类(child class 或 subclass) 或者 派生类(derived class)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 单继承:　子类只有一个父类，一个父类可以有多个子类&lt;/li&gt;
      &lt;li&gt;3 语法: [访问符] [修饰符] class 子类 extends 父类 { … }&lt;/li&gt;
      &lt;li&gt;4 构造函数调用:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;先调用父类构造函数，在调用子类构造函数，再调用其他&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 多态(polymorphism)
    &lt;ul&gt;
      &lt;li&gt;1 定义：
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;上转型对象&lt;/code&gt;: 多态通常体现在具有继承关系和实现关系的类之间，一个父类具有多个子类，可以将子类对象直接赋值给一个父类引用变量，无需任何类型转换.&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;方法重写Override&lt;/code&gt;: 子类重写父类的方法也是Java多态性的一种体现.当子类继承父类时，如果父类的方法无法满足子类的需要，子类可以对父类中的方法进行改造.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;方法重写Override　条件&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;1 方法名和参数列表必须完全相同&lt;/li&gt;
          &lt;li&gt;2 子类方法的返回值类型与父类保持一致，或是父类方法返回值类型的子类&lt;/li&gt;
          &lt;li&gt;3 子类方法声明的异常与父类保持一直，或是父类方法声明的异常的子类;&lt;/li&gt;
          &lt;li&gt;4 父类中的私有方法不能被子类重写, 如果在子类中定义了父类重名的私有方法，则该方法是子类的一个新方法, 与父类中的私有方法无关;&lt;/li&gt;
          &lt;li&gt;5 子类方法的可访问性必须与父类方法的可访问性保持一致，或者更加公开.若父类方法可访问性为protected, 子类方法只能为protected或public, 不能为private或缺省;&lt;/li&gt;
          &lt;li&gt;6 不能重写静态方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Super 关键字&lt;/code&gt; : 构造方法
        &lt;ul&gt;
          &lt;li&gt;1 主要用途:
            &lt;ul&gt;
              &lt;li&gt;1 在子类的构造方法中调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;父类的构造方法super()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super代表父类&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;2 在子类方法中访问父类的属性或方法, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;常用于子类重写方法Override&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super不能访问父类私有属性和方法&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;2 关于子类:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;子类构造方法默认隐式调用父类构造方法, 相当于无参的构造方法第一句添加super()&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;这就是为什么先调用父类构造方法的情况&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;实际上都是从子类构造方法入口&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;如果父类没有无参的构造方法, 子类的构造方法必须显示调用父类的有参构造方法super(args...)&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;子类重写调用父类的方法时，不必在第一句，所以先调用子类覆盖方法，再调用父类方法&lt;/code&gt;
                &lt;ul&gt;
                  &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;super.method();&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Final 关键字&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;1 含义: final关键字是一个修饰符，表示不可改变的、最终的, 用于修饰属性、方法和类;
            &lt;ul&gt;
              &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;修饰变量Attribute: 表示该变量不可改变, 即常量;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;修饰方法Method: 表示方法不可被子类重写，即最终方法;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;修饰类Class: 表示该类不可被继承，即最终类&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 多态: 父类引用指向子类对象
//  作用: 动态调用重写方法
// 父类A, 子类B,C均继承A
A obj1 = new B();
A obj2 = new C();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 父类
public class Base {
    public void print() {
        System.out.println(&quot;父类&quot;);
    }
}

// 子类B
public class B extends Base {
    public void print() {
        System.out.println(&quot;子类B&quot;);
    }
}

// 子类C
public class C extends Base {
    public void print() {
        System.out.println(&quot;子类C&quot;);
    }
}

// Demo
public class OverrideDemo {
    public static void main (String[] args) {
        // 多态
        // obj 指向自己
        Base obj = new Base();
        obj.print();
        
        // obj指向子类B对象
        obj - new B();
        obj.print();

        // obj指向子类C对象
        obj = new C();
        obj.print();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;2-其他关系&quot;&gt;2 其他关系&lt;/h4&gt;
</description>
    <link>/2015/07/10/java-getting-started.html</link>
    <guid>/2015/07/10/java-getting-started</guid>
    <pubDate>Fri, 10 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>IntelliJ Idea 快捷键(KeyMaps)</title>
    <description>
&lt;h3 id=&quot;一相关文件&quot;&gt;一、相关文件&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.jetbrains.com/idea/docs/IntelliJIDEA_ReferenceCard.pdf&quot;&gt;官方，快捷键全&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二必须记住&quot;&gt;二、必须记住&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+ShiftSpace&lt;/code&gt; 自动补全代码&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift+Enter&lt;/code&gt;: 创建新行并跳到下一行&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift+F10&lt;/code&gt;: Run, (我喜欢改成Ctrl+R)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+J&lt;/code&gt;: 常用的有fori/sout/psvm+Tab即可生成循环、System.out、main方法等boilerplate样板代码，用Ctrl+J可以查看所有模板&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Alt+O&lt;/code&gt; 优化导入的类和包&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+X&lt;/code&gt; 删除行&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+D&lt;/code&gt; 复制行&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+/&lt;/code&gt; 或 Ctrl+Shift+/  注释（// 或者/&lt;em&gt;…&lt;/em&gt;/ ）&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Alt+Insert&lt;/code&gt; 生成代码(如get,set方法,构造函数等)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Alt+ Up/Down&lt;/code&gt; 在方法间快速移动定位&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Shift+Up/Down&lt;/code&gt; 代码向上/下移动。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Q&lt;/code&gt; 显示注释文档&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三常用快捷键&quot;&gt;三、常用快捷键&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;lt+回车 导入包,自动修正&lt;/li&gt;
  &lt;li&gt;Ctrl+N   查找类&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+N 查找文件&lt;/li&gt;
  &lt;li&gt;Ctrl+Alt+L  格式化代码&lt;/li&gt;
  &lt;li&gt;Ctrl+E或者Alt+Shift+C  最近更改的代码&lt;/li&gt;
  &lt;li&gt;Ctrl+R 替换文本&lt;/li&gt;
  &lt;li&gt;Ctrl+F 查找文本&lt;/li&gt;
  &lt;li&gt;Ctrl+空格 代码提示&lt;/li&gt;
  &lt;li&gt;Ctrl+Alt+Space 类名或接口名提示&lt;/li&gt;
  &lt;li&gt;Ctrl+P 方法参数提示&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+Alt+N 查找类中的方法或变量&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Alt+Shift+C 对比最近修改的代码&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Shift+F6  重构-重命名&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+先上键&lt;/li&gt;
  &lt;li&gt;Ctrl+J  自动代码&lt;/li&gt;
  &lt;li&gt;Ctrl+E 最近打开的文件&lt;/li&gt;
  &lt;li&gt;Ctrl+H 显示类结构图&lt;/li&gt;
  &lt;li&gt;Alt+F1 查找代码所在位置&lt;/li&gt;
  &lt;li&gt;Alt+1 快速打开或隐藏工程面板&lt;/li&gt;
  &lt;li&gt;Ctrl+Alt+ left/right 返回至上次浏览的位置&lt;/li&gt;
  &lt;li&gt;Alt+ left/right 切换代码视图&lt;/li&gt;
  &lt;li&gt;F2 或Shift+F2 高亮错误或警告快速定位&lt;/li&gt;
  &lt;li&gt;&lt;/li&gt;
  &lt;li&gt;代码标签输入完成后，按Tab，生成代码。&lt;/li&gt;
  &lt;li&gt;选中文本，按Ctrl+Shift+F7 ，高亮显示所有该文本，按Esc高亮消失。&lt;/li&gt;
  &lt;li&gt;Ctrl+W 选中代码，连续按会有其他效果&lt;/li&gt;
  &lt;li&gt;选中文本，按Alt+F3 ，逐个往下查找相同文本，并高亮显示。&lt;/li&gt;
  &lt;li&gt;Ctrl+Up/Down 光标跳转到第一行或最后一行下&lt;/li&gt;
  &lt;li&gt;Ctrl+B 快速打开光标处的类或方法&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/07/10/intellij-idea-keymaps.html</link>
    <guid>/2015/07/10/intellij-idea-keymaps</guid>
    <pubDate>Fri, 10 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Eclipse KeyMaps</title>
    <description>
&lt;h2 id=&quot;资源来自网友整理&quot;&gt;&lt;a href=&quot;http://rongmayisheng.com/post/eclipse%E6%9C%80%E6%9C%89%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE%E6%95%B4%E7%90%86&quot;&gt;资源来自网友整理&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;一快捷键修改&quot;&gt;一、快捷键修改:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;菜单栏中Window–&amp;gt;Preferences–&amp;gt;General–&amp;gt;Keys来查看和修改快捷键绑定。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二编辑&quot;&gt;二、编辑&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Ctrl+1 快速修复（最经典的快捷键,就不用多说了，可以解决很多问题，比如import类、try catch包围等）&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+F 格式化当前代码&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+M 添加类的import导入&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+O 组织类的import导入（既有Ctrl+Shift+M的作用，又可以帮你去除没用的导入，很有用）&lt;/li&gt;
  &lt;li&gt;Ctrl+Y 重做（与撤销Ctrl+Z相反）&lt;/li&gt;
  &lt;li&gt;Alt+/ 内容辅助（帮你省了多少次键盘敲打，太常用了）&lt;/li&gt;
  &lt;li&gt;Ctrl+D 删除当前行或者多行&lt;/li&gt;
  &lt;li&gt;Alt+↓ 当前行和下面一行交互位置（特别实用,可以省去先剪切,再粘贴了）&lt;/li&gt;
  &lt;li&gt;Alt+↑ 当前行和上面一行交互位置（同上）&lt;/li&gt;
  &lt;li&gt;Ctrl+Alt+↓ 复制当前行到下一行（复制增加）&lt;/li&gt;
  &lt;li&gt;Ctrl+Alt+↑ 复制当前行到上一行（复制增加）&lt;/li&gt;
  &lt;li&gt;Shift+Enter 在当前行的下一行插入空行（这时鼠标可以在当前行的任一位置,不一定是最后）&lt;/li&gt;
  &lt;li&gt;Ctrl+/ 注释当前行,再按则取消注释&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三选择&quot;&gt;三、选择&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Alt+Shift+↑ 选择封装元素&lt;/li&gt;
  &lt;li&gt;Alt+Shift+← 选择上一个元素&lt;/li&gt;
  &lt;li&gt;Alt+Shift+→ 选择下一个元素&lt;/li&gt;
  &lt;li&gt;Shift+← 从光标处开始往左选择字符&lt;/li&gt;
  &lt;li&gt;Shift+→ 从光标处开始往右选择字符&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+← 选中光标左边的单词&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+→ 选中光标又边的单词&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;四移动&quot;&gt;四、移动&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Ctrl+← 光标移到左边单词的开头，相当于vim的b&lt;/li&gt;
  &lt;li&gt;Ctrl+→ 光标移到右边单词的末尾，相当于vim的e&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五搜索&quot;&gt;五、搜索&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Ctrl+K 参照选中的Word快速定位到下一个（如果没有选中word，则搜索上一次使用搜索的word）&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+K 参照选中的Word快速定位到上一个&lt;/li&gt;
  &lt;li&gt;Ctrl+J 正向增量查找（按下Ctrl+J后,你所输入的每个字母编辑器都提供快速匹配定位到某个单词,如果没有,则在状态栏中显示没有找到了,查一个单词时,特别实用,要退出这个模式，按escape建）&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+J 反向增量查找（和上条相同,只不过是从后往前查）&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+U 列出所有包含字符串的行&lt;/li&gt;
  &lt;li&gt;Ctrl+H 打开搜索对话框&lt;/li&gt;
  &lt;li&gt;Ctrl+G 工作区中的声明&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+G 工作区中的引用&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;六导航&quot;&gt;六、导航&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Ctrl+Shift+T 搜索类（包括工程和关联的第三jar包）&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+R 搜索工程中的文件&lt;/li&gt;
  &lt;li&gt;Ctrl+E 快速显示当前Editer的下拉列表（如果当前页面没有显示的用黑体表示）&lt;/li&gt;
  &lt;li&gt;F4 打开类型层次结构&lt;/li&gt;
  &lt;li&gt;F3 跳转到声明处&lt;/li&gt;
  &lt;li&gt;Alt+← 前一个编辑的页面&lt;/li&gt;
  &lt;li&gt;Alt+→ 下一个编辑的页面（当然是针对上面那条来说了）&lt;/li&gt;
  &lt;li&gt;Ctrl+PageUp/PageDown 在编辑器中，切换已经打开的文件&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;七调试&quot;&gt;七、调试&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;F5 单步跳入&lt;/li&gt;
  &lt;li&gt;F6 单步跳过&lt;/li&gt;
  &lt;li&gt;F7 单步返回&lt;/li&gt;
  &lt;li&gt;F8 继续&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+D 显示变量的值&lt;/li&gt;
  &lt;li&gt;Ctrl+Shift+B 在当前行设置或者去掉断点&lt;/li&gt;
  &lt;li&gt;Ctrl+R 运行至行(超好用，可以节省好多的断点)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;八重构&quot;&gt;八、重构&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;（一般重构的快捷键都是Alt+Shift开头的了）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+R 重命名方法名、属性或者变量名 （是我自己最爱用的一个了,尤其是变量和类的Rename,比手工方法能节省很多劳动力）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+M 把一段函数内的代码抽取成方法 （这是重构里面最常用的方法之一了,尤其是对一大堆泥团代码有用）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+C 修改函数结构（比较实用,有N个函数调用了这个方法,修改一次搞定）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+L 抽取本地变量（ 可以直接把一些魔法数字和字符串抽取成一个变量,尤其是多处调用的时候）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+F 把Class中的local变量变为field变量 （比较实用的功能）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+I 合并变量（可能这样说有点不妥Inline）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+V 移动函数和变量（不怎么常用）&lt;/li&gt;
  &lt;li&gt;Alt+Shift+Z 重构的后悔药（Undo）&lt;/li&gt;
  &lt;li&gt;
    &lt;h3 id=&quot;九其他&quot;&gt;九、其他&lt;/h3&gt;
  &lt;/li&gt;
  &lt;li&gt;Alt+Enter 显示当前选择资源的属性，windows下的查看文件的属性就是这个快捷键，通常用来查看文件在windows中的实际路径&lt;/li&gt;
  &lt;li&gt;Ctrl+↑ 文本编辑器 上滚行&lt;/li&gt;
  &lt;li&gt;Ctrl+↓ 文本编辑器 下滚行&lt;/li&gt;
  &lt;li&gt;Ctrl+M 最大化当前的Edit或View （再按则反之）&lt;/li&gt;
  &lt;li&gt;Ctrl+O 快速显示 OutLine（不开Outline窗口的同学，这个快捷键是必不可少的）&lt;/li&gt;
  &lt;li&gt;Ctrl+T 快速显示当前类的继承结构&lt;/li&gt;
  &lt;li&gt;Ctrl+W 关闭当前Editer（windows下关闭打开的对话框也是这个，还有qq、旺旺、浏览器等都是）&lt;/li&gt;
  &lt;li&gt;Ctrl+L 文本编辑器 转至行&lt;/li&gt;
  &lt;li&gt;F2 显示工具提示描述&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/07/10/eclipse-keymaps.html</link>
    <guid>/2015/07/10/eclipse-keymaps</guid>
    <pubDate>Fri, 10 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>CSS 布局解决浮动问题</title>
    <description>
&lt;h3 id=&quot;一问题question&quot;&gt;一、问题(Question):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;浮动脱离文档流，导致无法撑开DIV解决:&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二解决办法solution&quot;&gt;二、解决办法(Solution):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;在父DIV中加入
    &lt;ul&gt;
      &lt;li&gt;1 声明该DIV的伪类选择器divName::after (divName只是标识，泛指能找到DIV的选择器名)&lt;/li&gt;
      &lt;li&gt;2 必须是block&lt;/li&gt;
      &lt;li&gt;3 高度必须为0&lt;/li&gt;
      &lt;li&gt;4 内容随意，但必须有&lt;/li&gt;
      &lt;li&gt;5 清楚两边浮动: clear: both&lt;/li&gt;
      &lt;li&gt;6 overflow: hidden;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三css实现代码implement-code&quot;&gt;三、CSS　实现代码(Implement Code)&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    divName::after `{
        display: block;
        height: 0;
        content: &quot;0&quot;;
        clear: both;
        overflow: hidden;
    }`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/07/09/css-layout-clear-float-method.html</link>
    <guid>/2015/07/09/css-layout-clear-float-method</guid>
    <pubDate>Thu, 09 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Oracle Database</title>
    <description>
&lt;h3 id=&quot;一orcle-database-数据库客户端的安装&quot;&gt;一、Orcle Database 数据库客户端的安装&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;安装&lt;/li&gt;
  &lt;li&gt;概述
    &lt;ul&gt;
      &lt;li&gt;数据库 &amp;lt;-1—–n-&amp;gt; 表空间&lt;/li&gt;
      &lt;li&gt;表空间 &amp;lt;-1—–n-&amp;gt; 表+索引+视图等&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二表空间tablespace及用户管理grantrevoke&quot;&gt;二、表空间(tablespace)及用户管理(grant/revoke)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 TableSpace&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. Create TableSpace
    CREATE TABLESPACE tablespace_name
    DATAFILE &apos;path/to/database_file&apos;
    SIZE size;

    -- Ex
        CREATE TABLESPACE jsp_20150708
        DATAFILE &apos;/home/potter/jsp_20150708.oradb&apos;
        SIZE 100M;

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

&lt;ul&gt;
  &lt;li&gt;2 管理用户
    &lt;ul&gt;
      &lt;li&gt;默认用户
        &lt;ul&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SYS&lt;/code&gt; : 超级用户,具有最高权限&lt;/td&gt;
                  &lt;td&gt;sysdba角色权限&lt;/td&gt;
                  &lt;td&gt;create database权限&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
            &lt;ul&gt;
              &lt;li&gt;主要用来维护系统信息和管理实例&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SYSTEM&lt;/code&gt; : 操作管理员, 权限: sysoper角色&lt;/td&gt;
                  &lt;td&gt;没有create database权限&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
            &lt;ul&gt;
              &lt;li&gt;管理数据库用户、权限和存储等&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SCOTT&lt;/code&gt; : 普通用户&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- CREATE USER 语法:

    -- CREATE USER username
       IDENTIFIED BY password
       [DEFAULT TABLESPACE tablespace_name];

    -- Ex
        -- CREATE USER gardom
           IDENTIFIED BY 123456
           DEFAULT TABLESPACE jsp_20150708.oradb;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 用户权限与角色
    &lt;ul&gt;
      &lt;li&gt;权限: 创建用户后必须赋予权限才可以登陆，权限是指执行特定类型sql命令或访问其他方案对象的权利
        &lt;ul&gt;
          &lt;li&gt;Ex: CREATE SESSION # 连接数据库权限;
        CREATE TABLE   # 创建表的权限等&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;角色:
        &lt;ul&gt;
          &lt;li&gt;含义: 相关权限的命令集合，使用角色的目的是简化权限的管理
            &lt;ul&gt;
              &lt;li&gt;Ex: CONNECT, RESOURCE&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 授权语法: 权限或角色
    &lt;ul&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRANT privilege_name or role TO user&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Ex:
        &lt;ul&gt;
          &lt;li&gt;1 GRANT CREATE SESSION TO gardom; – 单行注释&lt;/li&gt;
          &lt;li&gt;2 GRANT CREATE RESOURCE, CONNECT TO /&lt;em&gt;多行注释&lt;/em&gt;/&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三对表操作-就是普通sql语句&quot;&gt;三、对表操作: 就是普通SQL语句。。&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 添加表CREATE TABLE&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    CREATE TABLE tbl_name (
        column_name1 data_type [constraint_type],
        column_name2 data_type [constraint_type],
        column_name3 data_type [constraint_type],
        ....
    );

Ex:
    CREATE TABLE tb_user (
        id NUMBER(5) PRIMARY KEY,
        user_name NVARCHAR2(20) NOT NULL,
        user_password NVARCHAR2(30) NOT NULL
    );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;1.1 五大约束: 普通SQL, 这里就不再赘述了
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NOT NULL&lt;/code&gt;: – 命名规范: nn_name&lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UNIQUE&lt;/code&gt; – 命名规范: uk_name (uk –&amp;gt; unique key)&lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PRIMARY KEY&lt;/code&gt; – 命名规范: pk_name (pk –&amp;gt; primary key)&lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FOREIGN KEY tbl_name(column_name)&lt;/code&gt; – 命名规范: fk_name&lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CHECK(condition_expression)&lt;/code&gt; – 命名规范: ck_name&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 修改表ALTER TABLE:
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALTER TABLE table_name ADD (列名 数据类型 [约束]); -- 添加列，多列用逗号隔开&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALTER TABLE tb_name MODIFY (column_name data_type [约束]); -- 修改列属性&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALTER TABLE tb_name ADD CONSTRAINT constraint_name PRIMARY KEY(column_name); -- 添加约束，这里是主键&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DESC tb_name; -- 查看表结构&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 删除表DROP TABLE:
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DROP TABLE tbl_name; -- 删除表&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 注释：
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMMENT ON TABLE tbl_name IS &apos;tbl_comments&apos;; -- 为表添加注释语句&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMMENT ON COLUMN column_name IS &apos;col_comments&apos;; -- 为列&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Ex:
        &lt;ul&gt;
          &lt;li&gt;COMMENT ON TABLE tb_user IS ‘User Table’;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 解释:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SQL&lt;/code&gt; 含义:
  *Structure Query Language, 结构化查询语句,针对数据库的&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SQL 分类&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据控制语言(DCL)&lt;/code&gt;: 提取权限控制命令
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRANT&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REVOKE&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据定义语言(DDL)&lt;/code&gt;: 用于改变数据库结构
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CREATE&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ALTER&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DROP&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据操纵语言(DML)&lt;/code&gt;: 用于检索修改和插入数据
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INSERT&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DELETE&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;事物控制语言(TPL)&lt;/code&gt;: 保证事务的执行
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMMIT&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ROLLBACK&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SAVEPOINT&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PL/SQL&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;含义: 是Oracle对SQL的扩展语言&lt;/li&gt;
          &lt;li&gt;功能: SQL的基础上，可以使用变量和逻辑控制语句编写功能模块，完成复杂要求.&lt;/li&gt;
          &lt;li&gt;栗子&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    SET serveroutput ON; -- 打开输出选项
    DECLARE
        -- 定义字符串变量
        v_ename VARCHAR2(10);
    BEGIN
        -- 执行部分
        -- &amp;amp; 表示要接收从控制台输入的变量
        SELECT ename INTO v_name FROM emp WHER empno=&amp;amp;empno;
        dbms_output.put_line(&apos;雇员名:&apos; || v_name); -- 在控制台显示雇员名
    END;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;完整表demo&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    CREATE TABLE tb_user (
        id NUMBER(5) primary key,
        user_name NVARCHAR2(20) NOT NULL,
        user_password NVARCHAR2(30) NOT NULL
        );
    COMMENT ON COLUMN tb_user.id IS &apos;标识&apos;;
    COMMENT ON COLUMN tb_user.user_name IS &apos;用户名&apos;;
    COMMENT ON COLUMN tb_user.user_password IS &apos;密码&apos;;

    CREATE TABLE tb_type 
    (
        id NUMBER(5) PRIMARY KEY,
        type_sign NUMBER(10) UNIQUE,
        type_name NVARCHAR2(20) NOT NULL,
        type_intro NVARCHAR2(100) 
    );
    COMMENT ON COLUMN tb_type.id IS &apos;序号&apos;;
    COMMENT ON COLUMN tb_type.type_sign IS &apos;标识&apos;;
    COMMENT ON COLUMN tb_type.type_name IS &apos;类型名&apos;;
    COMMENT ON COLUMN tb_type.type_intro IS &apos;信息类别&apos;;

    CREATE TABLE tb_info 
    (
        id NUMBER PRIMARY KEY,
        info_type NUMBER NOT NULL,
        info_title NVARCHAR2(80) NOT NULL,
        info_linkman NVARCHAR2(50) NOT NULL,
        info_phone NUMBER,
        info_date DATE,
        info_state NVARCHAR2(10),
        info_content NVARCHAR2(1000),
        info_email NVARCHAR2(30),
        info_payfor NVARCHAR2(20),
        FOREIGN KEY (info_type) REFERENCES tb_type(type_sign)
    );
    COMMENT ON COLUMN tb_info.id IS &apos;序号&apos;;
    COMMENT ON COLUMN tb_info.info_type IS &apos;类型&apos;;
    COMMENT ON COLUMN tb_info.info_title IS &apos;标题&apos;;
    COMMENT ON COLUMN tb_info.info_linkman IS &apos;联系人&apos;;
    COMMENT ON COLUMN tb_info.info_phone IS &apos;电话&apos;;
    COMMENT ON COLUMN tb_info.info_date IS &apos;日期&apos;;
    COMMENT ON COLUMN tb_info.info_state IS &apos;审核状态&apos;;
    COMMENT ON COLUMN tb_info.info_content IS &apos;内容&apos;;
    COMMENT ON COLUMN tb_info.info_email IS &apos;邮箱&apos;;
    COMMENT ON COLUMN tb_info.info_payfor IS &apos;付费状态&apos;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四管理数据-insert-update-delete&quot;&gt;四、管理数据: INSERT UPDATE DELETE&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 添加/插入数据&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    INSERT INTO tbl_name[(column1, column2...)] VALUES (value1, value2 ...)

Example:
    INSERT INTO tb_user(id, user_name, user_password) VALUES (2015, &apos;Gardom&apos;, &apos;123456&apos;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 使用序列&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1 创建序列:
    -- Syntax:
        CREATE SEQUENCE squence_name
            START WITH 1    -- 从1开始
            INCREMENT BY 1  -- 每次加1
            MAXVALUE 2000   -- 最大值2000
            MINVALUE        -- 最小值
            NOCYCLE         -- 不循环
            NOCACHE;        -- 不缓存

    -- Example:
        CREATE SEQUENCE user_seq
            START WITH 1
            INCREMENT BY 1;

-- 2 序列操作:
    -- Syntax:
        -- 访问序列的值
            - NEXTVALUE : 返回系列的下一个值
            - CURRVAL   : 返回序列的当前值(第一次NEXTVAL初始化后才能用CURRVAL)
            -- 栗子:
                SELECT user_seq.CURRVAL FROM dual;

            -- Tips:
                dual是Oracle中的虚拟表，可用于查看当前用户，当前系统时间等，序列值.

        -- 更改序列
            -- 栗子
                ALTER SEQUENCE user_seq MAXVALUE 5000; -- 更改序列
                DROP SEQUENCE user_seq;

        -- 运用
            -- 栗子
                INSERT INTO tb_user (id, user_name, user_password)
                    VALUES (user_seq.nextval, &apos;gardon&apos;, &apos;123456&apos;);
            
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 修改数据
    &lt;ul&gt;
      &lt;li&gt;提交(COMMIT)和回滚(ROLLBACK):　这里所说的都是对Oracle DB, 其他不一定
        &lt;ul&gt;
          &lt;li&gt;提交(COMMIT):
            &lt;ul&gt;
              &lt;li&gt;DML语言，需要commit:
                &lt;ul&gt;
                  &lt;li&gt;比如update, delete, insert等修改表中数据&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;其他，如DDL语言，不需要回滚
                &lt;ul&gt;
                  &lt;li&gt;比如create, drop等改变表结构的，因为内部隐藏了commit&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;回滚(ROLLBACK)
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;必须在没有提交之前才可以回滚；提交后只能查看日志&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;修改数据UPDATE&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;UPDATE Syntax:
    UPDATE tbl_name
        SET column_name = new_value
            [, column_name2 = new_value2 ...]
        [WHERE condition_expression];
    COMMIT; -- Oracle DB need commit.

UPDATE Example:
    -- 根据ID修改用户密码
        UPDATE tb_user 
            SET user_password = &apos;654321&apos; 
            WHERE id= &apos;1&apos;;
        COMMIT;

    -- 更新所有数据，即不要WHERE条件语句, 注意安全
        UPDATE tb_user
            SET user_password = &apos;654321&apos;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;4 删除数据&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    DELETE FROM tb_user
        [WHERE condition_expression];

Example:
    -- 根据ID删除用户
        DELETE FROM tb_user
            WHERE id = &apos;1&apos;;
        COMMIT;

    -- 删除整个表, Carefully
        DELETE FROM tb_user;
        COMMIT;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五查询数据&quot;&gt;五、查询数据&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 基础SELECT
    &lt;ul&gt;
      &lt;li&gt;含义: 查询(SELECT)语句用于从表中选取数据,结果存储在一个虚拟的结果表中.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    SELECT column_name [, column_name2 ...]
        FROM tbl_name
        [WHERE condition_expression]
        [ORDER BY column_name [ASC | DESC]];

Example:
    SELECT id, user_name
        FROM tbl_user
        WHERE user_name=&apos;gardom&apos; and user_password=&apos;123456&apos;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 模糊SELECT: LIKE, _&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    -- % : 代表零个或多个字符
    -- _ : 只能代表一个字符
        WHERE column_name LIKE &apos;%str%&apos;;
        WHERE column_name LIKE &apos;%str&apos;;
        WHERE column_name LIKE &apos;str%&apos;;
        WHERE column_name LIKE &apos;_str&apos;;
        WHERE column_name LIKE &apos;str_&apos;;
        WHERE column_name LIKE &apos;_str_&apos;;
        WHERE column_name LIKE &apos;str1_str2&apos;; 
        WHERE column_name LIKE &apos;_str%&apos;; .....
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 多表SELECT
    &lt;ul&gt;
      &lt;li&gt;1 等值连接: 返回多个表中所有能匹配的记录
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT t.*, i.* FROM tb_type t, tb_info i WHERE t.type_sign = i.info_type;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-- t, i为表的别名;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 左连接  : 以左表为基础,即使右表中没有匹配，也从左表返回所有行
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LEFT JOIN&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT t.*, i.* FROM tb_type t LEFT JOIN tb_info i ON t.type_sign = i.info_type;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 右连接  : 以右表为基础, …
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RIGHT JOIN&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 全关联  : 只要其中一个表中存在匹配，就返回所有行
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FULL JOIN&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 Oracle伪列
    &lt;ul&gt;
      &lt;li&gt;伪列: 就想一个表列，但是它并没有存储在表中;&lt;/li&gt;
      &lt;li&gt;伪列可以在表中查询，但不能插入、更新和删除;&lt;/li&gt;
      &lt;li&gt;常用伪列:
        &lt;ul&gt;
          &lt;li&gt;ROWID 是表中行的存储地址;
            &lt;ul&gt;
              &lt;li&gt;该地址可以唯一表示数据库中的一行;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;ROWNUM 是查询返回的结果中行的序号
            &lt;ul&gt;
              &lt;li&gt;可以使用它来限制查询返回的行数&lt;/li&gt;
              &lt;li&gt;通常用来分页.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;5 子查询和分页SQL
    &lt;ul&gt;
      &lt;li&gt;子查询: 嵌套查询&lt;/li&gt;
      &lt;li&gt;分页:&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 分页:
    SELECT * 
        FROM (
            SELECT a.*, ROWNUM rn 
                FROM (
                    SELECT * FROM tb_info ORDER BY info_date DESC
                    ) a
                WHERE ROWNUM &amp;lt;= 5 -- 注意，子查询不用写分号
        ) 
        WHERE rn &amp;gt;= 2;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/07/08/oracle-database.html</link>
    <guid>/2015/07/08/oracle-database</guid>
    <pubDate>Wed, 08 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>恢复 Grub 引导</title>
    <description>
&lt;h3 id=&quot;问题描述&quot;&gt;问题描述:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;原本多系统(Win + Linuxs)，但windows坏了，要重装，但想保留Ubuntu等&lt;/li&gt;
  &lt;li&gt;安装完Win8后, Grub没了，想要恢复Grub引导&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;方法推荐-livecd-进入大部分linux发行版都行&quot;&gt;方法(推荐): LiveCD 进入(大部分Linux发行版都行)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;步骤:
    &lt;ul&gt;
      &lt;li&gt;1 查看系统分区(一般是sda, 由于多系统, 找到其中一个linux根目录所在的分区/sda/sdaX)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo fdisk -l&lt;/code&gt; :&lt;/li&gt;
          &lt;li&gt;这里假设: Ubuntu 分区为 /dev/sda6&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 将根分区/dev/sd6挂载到/mnt
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount /mnt /dev/sda6&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 如果没给/boot单独分区，不需要挂载
  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount /mnt/boot /dev/sda5&lt;/code&gt;:&lt;/li&gt;
      &lt;li&gt;4 安装Grub引导到/dev/sda &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: /dev/sda是这整个磁盘, 不是某个分区&lt;/code&gt;
  *&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;grub-install --root-directory=/mnt /dev/sda&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 绑定LiveCD的一些东西:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount --bind /proc /mnt/proc&lt;/code&gt;:&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount --bind /dev /mnt/dev&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount --bind /sys /mnt/sys&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;6 用Chroot方式进入原系统, 并更新grub, 是grub引导生效:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chroot /mnt /bin/bash&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;update-grub&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;提示&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;现在是以root方式进入原系统，忘记密码可以以这种方式修改密码.&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;7 退出Chroot, 重启系统即可:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit&lt;/code&gt; Or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + D&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;谨慎点, 卸载刚才绑定的分区:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;umount /dev/sys&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;umount /dev/dev&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;umount /dev/proc&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reboot&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;8 恭喜，修复Grub&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;懒人脚本-开包即用-单机下载&quot;&gt;&lt;a href=&quot;/scripts/recover_grub.sh&quot;&gt;懒人脚本, 开包即用, 单机下载&lt;/a&gt;&lt;/h3&gt;
</description>
    <link>/2015/07/07/recover-grub.html</link>
    <guid>/2015/07/07/recover-grub</guid>
    <pubDate>Tue, 07 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Html CSS 基础</title>
    <description>&lt;p&gt;`
`&lt;/p&gt;

&lt;h2 id=&quot;第三章-html表格应用和布局&quot;&gt;第三章 html表格应用和布局&lt;/h2&gt;

&lt;h3 id=&quot;table&quot;&gt;table&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;标签
    &lt;ul&gt;
      &lt;li&gt;tr td th&lt;/li&gt;
      &lt;li&gt;thead tbody tfoot (逻辑分类)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;属性
    &lt;ul&gt;
      &lt;li&gt;填充
        &lt;ul&gt;
          &lt;li&gt;cellspacing: 单元格与边框、单元格与单元格, cellspacing=”5”&lt;/li&gt;
          &lt;li&gt;cellpadding: 单元格内边框与内容 cellpadding=”10”;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;跨行列(td)
        &lt;ul&gt;
          &lt;li&gt;colspan: 跨X列, colspan=”2”&lt;/li&gt;
          &lt;li&gt;rowspan: 跨Y行&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;第四章-html框架&quot;&gt;第四章 html框架&lt;/h2&gt;
&lt;h3 id=&quot;常用属性&quot;&gt;常用属性&lt;/h3&gt;
&lt;h4 id=&quot;a&quot;&gt;a&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;属性
    &lt;ul&gt;
      &lt;li&gt;target:
        &lt;ul&gt;
          &lt;li&gt;Usage: target=”值”&lt;/li&gt;
          &lt;li&gt;值 :
            &lt;ul&gt;
              &lt;li&gt;_blank : (当前浏览器)在新窗口打开&lt;/li&gt;
              &lt;li&gt;_self: 默认，覆盖当前页, 在相同的框架中打开链接文档&lt;/li&gt;
              &lt;li&gt;_parent: 在父框中打开 (相对iframe)&lt;/li&gt;
              &lt;li&gt;_top: 在整个窗口中打开被链接文档 (相对iframe)&lt;/li&gt;
              &lt;li&gt;framename: 在指定的框架中打开链接文档
                &lt;h4 id=&quot;iframe&quot;&gt;iframe&lt;/h4&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;语法
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;iframe src=&quot;引用页地址&quot; name=&quot;框架表示名&quot; frameborder=&quot;边框&quot; scrolling=&quot;no&quot;&amp;gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;属性
    &lt;ul&gt;
      &lt;li&gt;src : url或相对url&lt;/li&gt;
      &lt;li&gt;name&lt;/li&gt;
      &lt;li&gt;frameborder: 类似border-size&lt;/li&gt;
      &lt;li&gt;scrolling&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;第五章-css-cascading-style-sheets层叠样式&quot;&gt;第五章 CSS: Cascading Style Sheets(层叠样式)&lt;/h2&gt;
&lt;h3 id=&quot;50-选择器&quot;&gt;5.0 选择器&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;标签选择器: div, p, hX, img, span, ul, li, ol, a …&lt;/li&gt;
  &lt;li&gt;类选择器: class&lt;/li&gt;
  &lt;li&gt;ID选择器: id&lt;/li&gt;
  &lt;li&gt;复杂选择器
    &lt;ul&gt;
      &lt;li&gt;群组选择器: div,p,#id,.c &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{color:red;}&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;后代选择器 (只对后代起作用):
        &lt;ul&gt;
          &lt;li&gt;直接后代选择器(间接不起作用): div&amp;gt;p &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{ color:red; }&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;全部后代选择器: div p &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{color:red; }&lt;/code&gt; /&lt;em&gt;只对div内的p标签作用&lt;/em&gt;/&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;501-单位-px---em&quot;&gt;5.0.1 单位: px &amp;lt;-&amp;gt; em&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;px: 普通像素单位&lt;/li&gt;
  &lt;li&gt;em: 相对于字体大小的倍数
    &lt;ul&gt;
      &lt;li&gt;2em: 当font-size:12px时, 2em = 24px&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;502-选择器优先级&quot;&gt;5.0.2 选择器优先级&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;优先级: id &amp;gt; class &amp;gt; 标签, (…与顺序无关)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;51-文本属性&quot;&gt;5.1 文本属性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;字体、字号属性（font）
    &lt;ul&gt;
      &lt;li&gt;font&lt;/li&gt;
      &lt;li&gt;color: RGB Or Name&lt;/li&gt;
      &lt;li&gt;font-weight: 粗细(bold)&lt;/li&gt;
      &lt;li&gt;font-size: 字体大小&lt;/li&gt;
      &lt;li&gt;font-family: 字体家族
        &lt;ul&gt;
          &lt;li&gt;Value: ..&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;行距、对齐等:
    &lt;ul&gt;
      &lt;li&gt;line-height: 行高
        &lt;ul&gt;
          &lt;li&gt;案例:
            &lt;ul&gt;
              &lt;li&gt;居中: center &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{ line-height: ...}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;letter-spacing: 字符间距&lt;/li&gt;
      &lt;li&gt;text-align: 文本对齐
        &lt;ul&gt;
          &lt;li&gt;Value:
            &lt;ul&gt;
              &lt;li&gt;center&lt;/li&gt;
              &lt;li&gt;left&lt;/li&gt;
              &lt;li&gt;right&lt;/li&gt;
              &lt;li&gt;justify&lt;/li&gt;
              &lt;li&gt;inherit&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;案例:
            &lt;ul&gt;
              &lt;li&gt;li标签左对齐: li &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{ text-align: left; /*默认左对齐*/}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;text-decoration: 文本修饰, 下划线等
        &lt;ul&gt;
          &lt;li&gt;Value:
            &lt;ul&gt;
              &lt;li&gt;none&lt;/li&gt;
              &lt;li&gt;underline&lt;/li&gt;
              &lt;li&gt;overline&lt;/li&gt;
              &lt;li&gt;line-through&lt;/li&gt;
              &lt;li&gt;inherit&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;white-space: 空白处理, 不换行(nowrap)&lt;/li&gt;
      &lt;li&gt;text-transform: 字母大小写&lt;/li&gt;
      &lt;li&gt;text-indent: 缩进, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{ text-indent: 2em;}&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;direction: 规定文本方向,书写方向&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;52-背景属性&quot;&gt;5.2 背景属性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;background:
    &lt;ul&gt;
      &lt;li&gt;background
        &lt;ul&gt;
          &lt;li&gt;background: url(images/bg.jpg) no-repeat;&lt;/li&gt;
          &lt;li&gt;background: yelow url(img/bg.png) no-repeat;&lt;/li&gt;
          &lt;li&gt;background: yelow url(img/bg.png) no-repeat fixed;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;background-color: #ccc;&lt;/li&gt;
      &lt;li&gt;background-image: url(…);&lt;/li&gt;
      &lt;li&gt;background-repeat: 重复背景图片
        &lt;ul&gt;
          &lt;li&gt;no-repeat&lt;/li&gt;
          &lt;li&gt;repeat&lt;/li&gt;
          &lt;li&gt;repeat-x&lt;/li&gt;
          &lt;li&gt;repeat-y&lt;/li&gt;
          &lt;li&gt;round&lt;/li&gt;
          &lt;li&gt;space&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;background-position: 位置坐标、偏移量
        &lt;ul&gt;
          &lt;li&gt;Value: top / bottom / center / left / right&lt;/li&gt;
          &lt;li&gt;Syntax:
            &lt;ul&gt;
              &lt;li&gt;background-position: 水平size 垂直size;
                &lt;ul&gt;
                  &lt;li&gt;坐标轴: x正向右, y正向下&lt;/li&gt;
                  &lt;li&gt;background-position-x&lt;/li&gt;
                  &lt;li&gt;background-position-y&lt;/li&gt;
                  &lt;li&gt;水平size:
                    &lt;ul&gt;
                      &lt;li&gt;正数: 图片右移size&lt;/li&gt;
                      &lt;li&gt;负数: 图片左移size&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                  &lt;li&gt;垂直size:
                    &lt;ul&gt;
                      &lt;li&gt;正数: 图片下移size&lt;/li&gt;
                      &lt;li&gt;负数: 图片上移size&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;应用:
                &lt;ul&gt;
                  &lt;li&gt;右下角: background-position: bottom right;&lt;/li&gt;
                  &lt;li&gt;图标截取-背景便宜: background-position + width + height&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;53-列表li属性&quot;&gt;5.3 列表(li)属性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;list-style (用在导航菜单去掉圆点: list-style:none;)
    &lt;ul&gt;
      &lt;li&gt;Value:
        &lt;ul&gt;
          &lt;li&gt;none : 去掉原点&lt;/li&gt;
          &lt;li&gt;disc : 实心圆&lt;/li&gt;
          &lt;li&gt;circle : 空心圆&lt;/li&gt;
          &lt;li&gt;sqare : 实心正方形&lt;/li&gt;
          &lt;li&gt;decimal : 数字, ol默认类型&lt;/li&gt;
          &lt;li&gt;url()&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;属性:
        &lt;ul&gt;
          &lt;li&gt;list-style-position : 圆圈在内或外
            &lt;ul&gt;
              &lt;li&gt;outside: 默认&lt;/li&gt;
              &lt;li&gt;inside&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;第六章-盒模型&quot;&gt;第六章 盒模型&lt;/h2&gt;
&lt;h3 id=&quot;61-立体盒模型上至下&quot;&gt;6.1 立体盒模型(上至下)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 内容&lt;/li&gt;
  &lt;li&gt;2 内边距/填充 padding&lt;/li&gt;
  &lt;li&gt;3 边框 border
    &lt;ul&gt;
      &lt;li&gt;border
        &lt;ul&gt;
          &lt;li&gt;border-top&lt;/li&gt;
          &lt;li&gt;border-right&lt;/li&gt;
          &lt;li&gt;border-bottom&lt;/li&gt;
          &lt;li&gt;border-left&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;border-color&lt;/li&gt;
      &lt;li&gt;border-width&lt;/li&gt;
      &lt;li&gt;border-style
        &lt;ul&gt;
          &lt;li&gt;Value: none / solid / dotted / dashed ;
            &lt;ul&gt;
              &lt;li&gt;double : 双虚线&lt;/li&gt;
              &lt;li&gt;hidden&lt;/li&gt;
              &lt;li&gt;groove / ridge / inset / outset : 凹&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;例子:
        &lt;ul&gt;
          &lt;li&gt;border: 1px solid red;&lt;/li&gt;
          &lt;li&gt;border-right: 5px dotted blue;&lt;/li&gt;
          &lt;li&gt;border-style: none;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4 background-image&lt;/li&gt;
  &lt;li&gt;5 background-color&lt;/li&gt;
  &lt;li&gt;6 外边距/便捷 margin
    &lt;ul&gt;
      &lt;li&gt;margin&lt;/li&gt;
      &lt;li&gt;margin-top&lt;/li&gt;
      &lt;li&gt;margin-right&lt;/li&gt;
      &lt;li&gt;margin-bottom&lt;/li&gt;
      &lt;li&gt;margin-left&lt;/li&gt;
      &lt;li&gt;例子
        &lt;ul&gt;
          &lt;li&gt;margin: 1px 2px 3px 4px&lt;/li&gt;
          &lt;li&gt;margin: 1px 2px;&lt;/li&gt;
          &lt;li&gt;margin: 0 auto; /&lt;em&gt;水平居中&lt;/em&gt;/&lt;/li&gt;
          &lt;li&gt;margin-left: 10px;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;62-元素的宽度及实际占位&quot;&gt;6.2 元素的宽度及实际占位&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;公式
    &lt;ul&gt;
      &lt;li&gt;盒子实际宽度/高度 = height/width + padding + border、、&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;63-浮动-float&quot;&gt;6.3 浮动 float&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;浮动float
    &lt;ul&gt;
      &lt;li&gt;效果: 脱离文档流&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;清除浮动 clear
    &lt;ul&gt;
      &lt;li&gt;作用:
        &lt;ul&gt;
          &lt;li&gt;如果前一个元素存在左浮动或右浮动，则换行以区隔&lt;/li&gt;
          &lt;li&gt;只对块级元素有效&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;取值
        &lt;ul&gt;
          &lt;li&gt;right / left / both / none&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;浮动脱离文档流，导致无法撑开DIV解决:
    &lt;ul&gt;
      &lt;li&gt;在父DIV中加入
        &lt;ul&gt;
          &lt;li&gt;1 声明该DIV的伪类选择器divName::after (divName只是标识，泛指能找到DIV的选择器名)&lt;/li&gt;
          &lt;li&gt;2 必须是block&lt;/li&gt;
          &lt;li&gt;3 高度必须为0&lt;/li&gt;
          &lt;li&gt;4 内容随意，但必须有&lt;/li&gt;
          &lt;li&gt;5 清楚两边浮动: clear: both&lt;/li&gt;
          &lt;li&gt;6 overflow: hidden;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript 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;nx&quot;&gt;divName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`{
        display: block;
        height: 0;
        content: &quot;0&quot;;
        clear: both;
        overflow: hidden;
    }`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;64-定位-position&quot;&gt;6.4 定位 Position&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Value
    &lt;ul&gt;
      &lt;li&gt;static: Default&lt;/li&gt;
      &lt;li&gt;absolute: 相对于浏览器最左上角位置偏移&lt;/li&gt;
      &lt;li&gt;fixed: 保留位置,不随鼠标移动&lt;/li&gt;
      &lt;li&gt;relative: 相对于自身原来位置偏移&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Position + z-index: z-index值大的显示在上层(表面)
    &lt;ul&gt;
      &lt;li&gt;z-index: 整数值&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;65-overflow-内容超出范围height-width&quot;&gt;6.5 Overflow: 内容超出范围(height, width)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Value
    &lt;ul&gt;
      &lt;li&gt;visiable&lt;/li&gt;
      &lt;li&gt;auto&lt;/li&gt;
      &lt;li&gt;hidden&lt;/li&gt;
      &lt;li&gt;scroll&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;66-display&quot;&gt;6.6 Display&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Value:
    &lt;ul&gt;
      &lt;li&gt;block&lt;/li&gt;
      &lt;li&gt;inline-block&lt;/li&gt;
      &lt;li&gt;inline&lt;/li&gt;
      &lt;li&gt;none&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;第七章-css二&quot;&gt;第七章 CSS二&lt;/h2&gt;

&lt;h3 id=&quot;71-超链接-a&quot;&gt;7.1 超链接 a&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;四种状态
    &lt;ul&gt;
      &lt;li&gt;a:link : 未访问过&lt;/li&gt;
      &lt;li&gt;a:visited : 已访问&lt;/li&gt;
      &lt;li&gt;a:hover : 鼠标移上状态&lt;/li&gt;
      &lt;li&gt;a:active : 激活选定状态&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;属性:
    &lt;ul&gt;
      &lt;li&gt;color&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;72-box-shadow&quot;&gt;7.2 box-shadow&lt;/h3&gt;

</description>
    <link>/2015/07/05/html-css-basic-1.html</link>
    <guid>/2015/07/05/html-css-basic-1</guid>
    <pubDate>Sun, 05 Jul 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>MySQL (五) 函数和操作符</title>
    <description>
&lt;h2 id=&quot;导航&quot;&gt;导航&lt;/h2&gt;

&lt;h3 id=&quot;一操作符&quot;&gt;一、操作符&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 操作符优先级&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&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: left&quot;&gt;BINARY, COLLATE&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;15&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;!&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;14&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-(一元减号), ~(一元比特取反)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;13&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;^&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;12&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;*, /, DIV, %, MOD&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;11&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;-, +&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;10&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;«, »&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;9&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;amp;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;8&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;|&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;7&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;=, &amp;lt;=&amp;gt;, &amp;gt;=, &amp;gt;, &amp;lt;=, &amp;lt;, &amp;lt;&amp;gt;, !=, IS, LIKE, REGEXP, IN&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;6&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;BETWEEN, CASE,WHEN,THEN,ELSE&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;NOT&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;4&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&amp;amp;&amp;amp;, AND&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;||, OR, XOR&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;:=&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;1.2 圆括号 (…):
    &lt;ul&gt;
      &lt;li&gt;select 1+2*3; # 7&lt;/li&gt;
      &lt;li&gt;select (1+2)*3; # 9&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;1.3 比较函数和操作符:
    &lt;ul&gt;
      &lt;li&gt;1 比较函数的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;结果&lt;/code&gt;: 1(TRUE), 0(FALSE), NULL;&lt;/li&gt;
      &lt;li&gt;2 将字符串转换为数字:
        &lt;ul&gt;
          &lt;li&gt;select 1 &amp;gt; ‘6x’; # 0&lt;/li&gt;
          &lt;li&gt;select 7 &amp;gt; ‘6x’; # 1&lt;/li&gt;
          &lt;li&gt;select 0 &amp;gt; ‘x6’; # 0&lt;/li&gt;
          &lt;li&gt;select 0 = ‘x6’; # 1, 任何非数字字符串转为数字时, 值为0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;= 等于&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;select 1 = 0;         # 0&lt;/li&gt;
          &lt;li&gt;select ‘0’ = 0;       # 1&lt;/li&gt;
          &lt;li&gt;select ‘0.0’ = 0;     # 1&lt;/li&gt;
          &lt;li&gt;select ‘0.01’ = 0;    # 0&lt;/li&gt;
          &lt;li&gt;select ‘.01’ = 0.01;  # 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;=&amp;gt; NULL-safe equal&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;解释: 这个操作符和=操作符执行相同的比较操作，不过在两个操作码均为NULL时，其所得值为1而不为NULL，而当一个操作码为NULL时，其所得值为0而不为NULL.&lt;/li&gt;
          &lt;li&gt;select 1&amp;lt;=&amp;gt;1, NULL&amp;lt;=&amp;gt;NULL, 1&amp;lt;=&amp;gt;NULL; # 1, 1, 0&lt;/li&gt;
          &lt;li&gt;select 1 = 1, NULL = NULL, 1 = NULL; # 1, NULL, NULL&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&amp;gt; != 不等于&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;select ‘.01’ &amp;lt;&amp;gt; ‘0.01’; # 1&lt;/li&gt;
          &lt;li&gt;select .01 &amp;lt;&amp;gt; ‘0.01’;   # 0&lt;/li&gt;
          &lt;li&gt;select ‘zapp’ &amp;lt;&amp;gt; ‘zappp’; # 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt; &amp;lt;= &amp;gt; &amp;gt;=&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IS boolean_value&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IS NOT boolean_value&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;这里布尔值: TRUE、FALSE、UNKNOWN&lt;/li&gt;
          &lt;li&gt;select 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN; # 1, 1, 1&lt;/li&gt;
          &lt;li&gt;select 1 IS NOT UNKNOWN, 0 IS NOT UNKNOWN, NULL IS NOT UNKNOWN; # 1, 1, 0&lt;/li&gt;
          &lt;li&gt;select ‘a’ is true, ‘a’ is false, ‘a’ is unknown; # 0, 1, 0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expr BETWEEN min AND max&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expr NOT BETWEEN min AND max&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;注意: min &amp;lt;= expr and expr &amp;lt;= max&lt;/li&gt;
          &lt;li&gt;select 1 BETWEEN 2 AND 3;         # 0&lt;/li&gt;
          &lt;li&gt;select ‘b’ BETWEEN ‘a’ AND ‘c’;   # 1&lt;/li&gt;
          &lt;li&gt;select 2 BETWEEN 2 AND ‘3’;       # 1&lt;/li&gt;
          &lt;li&gt;select 2 BETWEEN 2 AND ‘x-3’;     # 0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COALESCE(value, ...)&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;返回值: 为列表当中的第一个非NULL值; 在没有非NULL值是返回NULL;&lt;/li&gt;
          &lt;li&gt;select COALESCE(NULL, 1), COALESCE(NULL, NULL, NULL); # 1, NULL&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;10 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GREATEST(value1, value2, ...)&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LEAST(value1, ...)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;解释: GREATEST当有2个以上参数时，返回最大的参数;&lt;/li&gt;
          &lt;li&gt;slect GREATEST(2, 0, 1), GREATEST(‘B’, ‘A’, ‘C’); # 2, ‘C’&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;11 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expr IN (value, ...)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;若expr 为IN列表中的任意一个值，则其返回值为 1 , 否则返回值为0。假如所有的值都是常数，则其计算和分类根据 expr 的类型进行。这时，使用二分搜索来搜索信息。如IN值列表全部由常数组成，则意味着IN 的速度非常之快。如expr 是一个区分大小写的字符串表达式，则字符串比较也按照区分大小写的方式进行。&lt;/li&gt;
          &lt;li&gt;select 2 IN (0, 3, 5, ‘wef’);  # 0&lt;/li&gt;
          &lt;li&gt;select ‘wef’ IN (0, 3, ‘wef’); # 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;12 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ISNULL(expr)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;select ISNULL(1+1), ISNULL(1/0); # 0, 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;13 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INTERVAL(N, N1, N2, ...)&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;假如N &amp;lt; N1，则返回值为0；假如N &amp;lt; N2 等等，则返回值为1；假如N 为NULL，则返回值为 -1 。所有的参数均按照整数处理。为了这个函数的正确运行，必须满足 N1 &amp;lt; N2 &amp;lt; N3 &amp;lt; ……&amp;lt; Nn 。其原因是使用了二分查找(极快速)。&lt;/li&gt;
          &lt;li&gt;select INTERVAL(23, 1, 15, 17, 30, 44);   # 3&lt;/li&gt;
          &lt;li&gt;select INTERVAL(10, 1, 10, 100, 1000);    # 2&lt;/li&gt;
          &lt;li&gt;select INTERVAL(22, 23, 30, 44, 200);     # 0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;1.4 逻辑操作符:
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NOT !&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;select NOT 10, NOT 0, !(1+1), ! 1+1; # 0, 1, 0, 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AND &amp;amp;&amp;amp;&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;select 1&amp;amp;&amp;amp;1, 1&amp;amp;&amp;amp;0, 1&amp;amp;&amp;amp;NULL, 0&amp;amp;&amp;amp;NULL, NULL&amp;amp;&amp;amp;0; # 1, 0, NULL, 0, 0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OR ||&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;select 1&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;1, 1&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;0, 0&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;0, 0&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;NULL, 1&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;NULL;  # 1, 1, 0, NULL, 1&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XOR&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;当任意一个操作数为 NULL时，返回值为NULL。对于非 NULL 的操作数，假如一个奇数操作数为非零值，则计算所得结果为 1 ，否则为 0 。&lt;/li&gt;
          &lt;li&gt;select 1 XOR 1, 1 XOR 0;  # 0, 1&lt;/li&gt;
          &lt;li&gt;select 1 XOR NULL;        # NULL&lt;/li&gt;
          &lt;li&gt;select 1 XOR 1 XOR 1;     # 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二控制流程函数&quot;&gt;二、控制流程函数&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CASE WHEN THEN ELSE END&lt;/code&gt; 语句&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    CASE value
        WHEN [compare-value] THEN result
        [ WHEN [compare-value] THEN result ] ...
        [ ELSE result]
    END

    -- 在第一个方案的返回结果中， value=compare-value。而第二个方案的返回结果是第一种情况的真实结果。如果没有匹配的结果值，则返回结果为ELSE后的结果，如果没有ELSE 部分，则返回值为 NULL。

    -- 栗子1
    select 
      case 1 
        when 1 then &apos;one&apos;
        when 2 then &apos;two&apos;
        else &apos;more&apos;
      end; # &apos;one&apos;

    -- 栗子2
    select
      case
        when 1&amp;gt;0 then &apos;true&apos;
        else &apos;false&apos;
      end; # &apos;true&apos;
    
    -- 栗子3
    select
      case BINARY &apos;B&apos;
        when &apos;a&apos; then 1
        when &apos;b&apos; then 2
      end;

    -- 栗子4
    update movie_table
    set category = 
      case 
        when drama = &apos;T&apos; then &apos;drama&apos;
        when comedy = &apos;T&apos; then &apos;comedy&apos;
        when cartoon = &apos;T&apos; and rating = &apos;G&apos; then &apos;family&apos;
        else &apos;mise&apos;
      end;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IF&lt;/code&gt; 语句&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    IF (expr1, expr2, expr3) 
    -- 如果expr1是TRUE(expr1&amp;lt;&amp;gt;0 and expr1&amp;lt;&amp;gt;NULL), 返回expr2; 否则返回expr3
    -- IF()的返回值为数字之或字符串值。。。

    -- 栗子: select IF (1&amp;gt;2, 2, 3); # 3
    -- 栗子: select IF (1&amp;lt;2, &apos;yes&apos;, &apos;no&apos;); # &apos;yes&apos;
    -- 栗子: select IF (STRCMP(&apos;test&apos;, &apos;test1&apos;), &apos;no&apos;, &apos;yes&apos;); # &apos;no&apos;

    注意:
    -- 栗子: select IF (&apos;a&apos;, true, false); # false
    -- 栗子: select IF (&apos;123&apos;, true, false); # true
    -- 栗子: select IF (123, true, false); # true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IFNILL&lt;/code&gt; 语句&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    IFNULL(expr1, expr2)
    --  假如expr1 不为 NULL，则 IFNULL() 的返回值为 expr1; 否则其返回值为 expr2。IFNULL()的返回值是数字或是字符串，
    
    -- 栗子
    1. select IFNULL(1, 0); # 1
    2. select IFNULL(NULL, 10); -- 10
    3. select IFNULL(1/0, 10);  -- 10
    4. select IFNULL(1/0, &apos;yes&apos;); -- &apos;yes&apos;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULLIF&lt;/code&gt; 语句&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    NULLIF(expr1, expr2)
    -- 如果expr1 = expr2 成立，那么返回值为NULL，否则返回值为 expr1。这和CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END相同。

    -- 栗子
    1. select NULLIF(1, 1), NULLIF(2, 3); # NULL, 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三字符串函数&quot;&gt;三、字符串函数&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ASCII(str)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    ASCII(str)
    -- 返回值为字符串str 的最左字符的数值。假如str为空字符串，则返回值为 0 。假如str 为NULL，则返回值为 NULL。 ASCII()用于带有从 0到255的数值的字符

    -- 栗子
    1. SELECT ASCII(&apos;2&apos;), ASCII(2), ASCII(&apos;dx&apos;); # 50, 50, 100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BIN(N)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    BIN(N)
    --  返回值为N的二进制值的字符串表示，其中 N 为一个longlong (BIGINT) 数字。这等同于 CONV(N,10,2)。假如N 为NULL，则返回值为 NULL。

    -- 栗子
    1. select BIN(12); # &apos;1100&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BIT_LENGTH(str)&lt;/code&gt;   # 二进制的字符串的长度&lt;/li&gt;
  &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LENGTH(str)&lt;/code&gt;       # 字符串长度&lt;/li&gt;
  &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CHAR(N1, N2... [USING charset])&lt;/code&gt; – 将每个参数N理解为一个证书，返回整数的字符
    &lt;ul&gt;
      &lt;li&gt;select CHAR(77, 121, 83, 81, ‘76’), CHAR(77, 77.3, ‘77.3’); # ‘MYSQL’, ‘MMM’&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HEX&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;select HEX(255), HEX(‘abc’), 0x616263; – ‘FF’, 616263, ‘abc’&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONCAT(str1, str2, ...)&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;select CONCAT(‘My’, ‘S’, ‘QL’); – ‘MySQL’&lt;/li&gt;
      &lt;li&gt;select CONCAT(‘My’, NULL, ‘QL’); – NULL&lt;/li&gt;
      &lt;li&gt;select CONCAT(14.3); – 14.3&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONV&lt;/code&gt; 禁止转换&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    CONV(N, from_base, to_base);
    -- 不同数基间转换数字。返回值为数字的N字符串表示，由from_base基转化为 to_base 基。如有任意一个参数为NULL，则返回值为 NULL。自变量 N 被理解为一个整数，但是可以被指定为一个整数或字符串。最小基数为 2 ，而最大基数则为 36。 If to_base 是一个负数，则 N 被看作一个带符号数。否则， N 被看作无符号数。 CONV() 的运行精确度为 64比特。

    -- 栗子
    -- 1. 二进制 -&amp;gt; 十进制
    select conv(1010, 2, 10), conv(&apos;1010&apos;, 2, 10); # 10, 10

    -- 2. 十进制 -&amp;gt; 二进制
    select conv(10, 10, 2); # 1010

    -- 3 十六进制 -&amp;gt; 二进制
    select conv(&apos;a&apos;, 16, 2); # &apos;1010&apos;

    -- 4 十八进制 -&amp;gt; 八进制
    select conv(&apos;6E&apos;, 18, 8); # &apos;172&apos;

    -- 5 带符号
    select conv(-17, 10, -18); # &apos;-H&apos;

    -- 6
    select conv(10+&apos;10&apos;+&apos;10&apos;+0xa, 10, 10); # 40
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;9 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ELT&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    ELT(N, str1, str2, str3, ...)
    --  若N = 1，则返回值为 str1 ，若N = 2，则返回值为 str2 ，以此类推。 若N 小于1或大于参数的数目，则返回值为 NULL 。 ELT() 是 FIELD()的补数。

    -- 栗子
    1. select ELT(1, &apos;ej&apos;, &apos;Heja&apos;, &apos;hej&apos;, &apos;foo&apos;); # &apos;ej&apos;
    2. select ELT(4, &apos;ej&apos;, &apos;Heja&apos;, &apos;hej&apos;, &apos;foo&apos;); # &apos;foo&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;10 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FIELD&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    FIELD(str, str1, str2, str3, ...)
    -- 返回值为str1, str2, str3,……列表中的str 指数。在找不到str 的情况下，返回值为 0 。 如果所有对于FIELD() 的参数均为字符串，则所有参数均按照字符串进行比较。如果所有的参数均为数字，则按照数字进行比较。否则，参数按照双倍进行比较。 如果str 为NULL，则返回值为0 ，原因是NULL不能同任何值进行同等比较。FIELD() 是ELT()的补数。

    -- 栗子
    slect FIELD(&apos;ej&apos;, &apos;Hej&apos;, &apos;Heja&apos;); # 2
    select FIELD(&apos;e&apos;, &apos;Hej&apos;, &apos;Foo&apos;); # 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;11 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FIND_IN_SET&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    FIND_IN_SET(str, strlist)
    --  假如字符串str 在由N 子链组成的字符串列表strlist 中， 则返回值的范围在 1 到 N 之间 。一个字符串列表就是一个由一些被‘,’符号分开的自链组成的字符串。如果第一个参数是一个常数字符串，而第二个是type SET列，则 FIND_IN_SET() 函数被优化，使用比特计算。如果str不在strlist 或strlist 为空字符串，则返回值为 0 。如任意一个参数为NULL，则返回值为 NULL。 这个函数在第一个参数包含一个逗号(‘,’)时将无法正常运行。

    -- 栗子
    select FIND_IN_SET(&apos;b&apos;, &apos;a,b,c,d&apos;); # 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;12 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INSERT&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    INSERT(str, pos, len, newstr)
    -- 返回字符串 str, 其子字符串起始于 pos 位置和长期被字符串 newstr取代的len 字符。 如果pos 超过字符串长度，则返回值为原始字符串。 假如len的长度大于其它字符串的长度，则从位置pos开始替换。若任何一个参数为null，则返回值为NULL。

    -- 栗子
    1. select insert(&apos;Quadratic&apos;, 3, 4, &apos;What&apos;); # &apos;QuWhattic&apos;
    2. select insert(&apos;Quadratic&apos;, -1, 4, &apos;What&apos;); # &apos;QuaWhat&apos;
    3. select insert(&apos;Quadratic&apos;, 3, 100, &apos;What&apos;); # &apos;QuaWhat&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;13 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INSTR&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    INSRT(str, substr)
    -- 返回字符串 str 中子字符串的第一个出现位置。这和LOCATE()的双参数形式相同，除非参数的顺序被颠倒。

    -- 栗子
    1. SELECT INSTR(&apos;foobarbar&apos;, &apos;bar&apos;); # 4
    2. SELECT INSTR(&apos;xbar&apos;, &apos;foobar&apos;); # 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;14 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LEFT(str, len)&lt;/code&gt;: 返回从字符串str开始的len最左字符
    &lt;ul&gt;
      &lt;li&gt;select LEFT(‘foobarbar’, 5); # ‘fooba’&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RIGHT(str, len)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;15 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LOCATE&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    LOCATE(substr, str);
    LOCATE(substr, str, pos);
     -- 第一个语法返回字符串 str中子字符串substr的第一个出现位置。第二个语法返回字符串 str中子字符串substr的第一个出现位置, 起始位置在pos。如若substr 不在str中，则返回值为0。

     -- 栗子
     1. select LOCATE(&apos;bar&apos;, &apos;foobarbar&apos;); # 4
     2. select LOCATE(&apos;xbar&apos;, &apos;foobarbar&apos;); # 0
     3. select LOCATE(&apos;bar&apos;, &apos;foobarbar&apos;, 5); # 7
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;16 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LOWER&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPPER&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    LOWER(str) -- 返回字符串 str 以及所有根据最新的字符集映射表变为小写字母的字符 (默认为 cp1252 Latin1)
    UPPER(str) --

    -- 栗子
    1. select LOWER(&apos;QUADRATICALLY&apos;); # &apos;quadratically&apos;
    2. select UPPER(&apos;aaa&apos;); # &apos;AAA&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;17 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LTRIM&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TRIM&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RTRIM&lt;/code&gt; 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    LTRIM(str)  -- 去字符串左边空格
    TRIM(str)   -- 去字符串两边空格
      - TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
      -- 返回字符串 str ， 其中所有remstr 前缀和/或后缀都已被删除。若分类符BOTH、LEADIN或TRAILING中没有一个是给定的,则假设为BOTH 。 remstr 为可选项，在未指定情况下，可删除空格。
    RTRIM(str)  -- 去字符串右边字符

    -- 栗子
    set @str = &apos;  ab c  &apos;;
    select LTRIM(@str); -- &apos;ab c  &apos;
    select TRIM(@str);  -- &apos;ab c&apos;
    select RTRIM(@str); -- &apos;  ab c&apos;

    select TRIM(BOTH &apos;x&apos; FROM &apos;xxxbarxx&apos;); # &apos;bar&apos;
    select TRIM(TRAILING &apos;xyz&apos; FROM &apos;barxxyz&apos;); # &apos;barx&apos;
    select TRIM(LEADING &apos;xyz&apos; FROM &apos;xxxbarxxx&apos;); # &apos;barxxx&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;18 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OCT&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ORD&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;OCT(N); –  返回一个 N的八进制值的字符串表示，其中 N 是一个longlong (BIGINT)数
        &lt;ul&gt;
          &lt;li&gt;== CONV(N, 10, 8);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;ORD(N); – 若字符串str 的最左字符是一个多字节字符，则返回该字符的代码， 代码的计算通过使用以下公式计算其组成字节的数值而得出: (1st byte code) (2nd byte code × 256) (3rd byte code × 2562) … 假如最左字符不是一个多字节字符，那么 ORD()和函数ASCII()返回相同的值。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;19 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REPEAT&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    REPEAT(str, count);
    -- 返回一个由重复的字符串str 组成的字符串，字符串str的数目等于count 。 若 count &amp;lt;= 0,则返回一个空字符串。若str 或 count 为 NULL，则返回 NULL 。

    -- 栗子
    select REPEAT(&apos;MySQL&apos;, 3); -- &apos;MySQLMySQLMySQL&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;20 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REPLACE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    REPLACE(str, from_str, to_str)
    -- 返回字符串str 以及所有被字符串to_str替代的字符串from_str 。

    -- 栗子
    select replace(&apos;I hate you&apos;, &apos;hate&apos;, &apos;love&apos;); # &apos;I love you&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;21 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REVERSE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    REVERSE(str)
    -- REVERSE(str) 返回字符串 str ，顺序和字符顺序相反

    -- 栗子
    SELECT REVERSE(&apos;abc&apos;); # &apos;cba&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;22 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SPACE&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    SPACE(N) 返回一个由N间隔符号组成的字符串

    -- 栗子
    SELECT SPACE(6); # &apos;      &apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;23 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SUBSTRING&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    SUBSTRING(str, pos [, len])
    SUBSTRING(str FROM pos [FOR len])
    -- 返回从pos到末尾或从pos开始长度为len的子串

    -- 栗子
    1. SELECT SUBSTRING(&apos;abcdefg&apos;, 5); # &apos;efg&apos;
    2. SELECT SUBSTRING(&apos;abcdefg&apos;, 5, 2); # &apos;ef&apos;
    3. SELECT SUBSTRING(&apos;abcdefg&apos; from 5); # &apos;efg&apos;
    4. SELECT SUBSTRING(&apos;abcdefg&apos;, -3); # &apos;efg&apos;
    5. SELECT SUBSTRING(&apos;abcdefg&apos;, -4, 1); # &apos;d&apos;
    6. SELECT SUBSTRING(&apos;abcdefg&apos; FROM -4 FOR 2); # &apos;de&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;24 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SUBSTRING_INDEX&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    SUBSTRING_INDEX(str, delim, count)
    -- 在定界符 delim 以及count 出现前，从字符串str返回自字符串。若count为正值,则返回最终定界符(从左边开始)左边的一切内容。若count为负值，则返回定界符（从右边开始）右边的一切内容。

    -- 栗子
    1. select substring_index(&apos;abcd_efg_hi&apos;, &apos;_&apos;, 2); # &apos;abcd_efg&apos;
    2. select substring_index(&apos;abcd_efg_hi&apos;, &apos;_&apos;, -2); # &apos;efg_hi&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;25 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;STRCMP&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    STRCMP(expr1, expr2)
    --  若所有的字符串均相同，则返回STRCMP()，若根据当前分类次序，第一个参数小于第二个，则返回 -1，其它情况返回 1 。

    -- 栗子
    1. SELECT STRCMP(&apos;text&apos;, &apos;text2&apos;); # -1
    2. SELECT STRCMP(&apos;text2&apos;, &apos;text&apos;); # 1
    3. SELECT STRCMP(&apos;text&apos;, &apos;text&apos;); # 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四数值函数&quot;&gt;四、数值函数&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 算数操作符&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;+ 加号: SELECT 3+5; # 8
- 减号: SELECT 3-5; # -2
- 一元减号: SELECT -2; # -2
* 乘号: SELECT 3*5; # 15
/ 除号: SELECT 3/5; # 0.60
    NULL: SELECT 102/(1-1); # NULL
DIV 整除: SELECT 5 DIV 2; # 2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 数学函数&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. ABS(X) : 返回X的绝对值

2. 三角函数:
    1. COS(X): 返回X的余弦
       ACOS(X): 返回X的反余弦
    2. SIN(X): 返回X的正弦
       ASIN(X): 反正弦
    3. TAN(X): 正切
       ATAN(X): 反正切
    4. COT(X) ACOT(X)

3. 取近似:
    * 上界整数: CEILING(X) = CEIL(X); 返回不小于X的最小整数值
    * 下届整数: FLOOR(X): 返回不大于X的最大整数
    * 最接近(四舍五入): 
        * 整数: ROUND(X): X 是浮点数
        * 小数位数为D为的浮点数: ROUND(X, D)

3.1 TRUNCATE(X, D):
    * D为非负数, 则保留浮点数X的D位小数
    * D为负数, 只保留整数部分，并将|D|位整数置零
        * SELECT TRUNCATE(1.223, 1); # 1.2
        * SELECT TRUNCATE(1.999, 0); # 1
        * SELECT TRUNCATE(122.231, -2); # 100
        * SELECT TRUNCATE(-1.999, 1); # 1.9

4. CRC32(expr): 循环冗余校验值, 返回一个32比特无符号值.若参数为NULL ，则结果为 NULL。
    * SELECT CRC32(&apos;MySQL&apos;); # 3259397556
    * SELECT CRC32(&apos;mysql&apos;); # 2501908538

5. DEGREES(X): 返回参数X, 该参数由弧度被转化为度
    * select DEGREES(PI()); # 180
    * select DEGREES(PI() / 2); # 90

6. 指数和对数:
    * EXP(X): 返回e的X乘方后的值
        * SELECT EXP(0); # 1
    * LN(X): 返回X的自然对数, X相对于基数e的对数
        * SELECT LN(2); # 0.6931478055995
        * SELECT LN(-2); # NULL
    * LOG([B,] X): B为基数, 默认为e
        * SELECT LOG(2); # 0.6931478055995
        * SELECT LOG(2, 65536); # 16
    * LOG2(X): 以2为基数的对数
    * LOG10(X)
    * POW(X, Y) == POWER(X, Y): 返回X的Y次方结果
        * SELECT POW(2, 2); # 4

7. MOD(X, Y): 模, 返回X DIV Y的余数, 小数也起作用
    * select MOD(34.5, 4); # 1.5

8. PI(): 3.141593

9. RADIANS(X): 返回由角度X转化为弧度
    * select RADIANS(80);

10. 随机数:
    * RAND() : 返回0到1之间的浮点数
    * RAND(N): N为种子数，类似时间戳，种子数一样，则结果一样
        * 7-12之间的随机整数: SELECT FLOOR(7 + (RAND() * 6));
        * 随机顺序检索: SELECT * FROM tbl_name ORDER BY RAND();

11. SIGN(X):
    * X &amp;gt; 0, 返回1
    * X = 0, 返回0
    * X &amp;lt; 0, 返回-1

12. SQRT(X) : 返回非负数X的二次方根

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

&lt;h3 id=&quot;五日期和时间函数&quot;&gt;五、日期和时间函数&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. ADDDATE = DATE_ADD:
    * ADDDATE(date, INTERVAL expr type)
    * ADDDATE(date, days): 日期DATE加上天数days后的新日期
        * SELECT ADDDATE(&apos;2001-01-02&apos;, 31); # &apos;2001-02-02&apos;
        * SELECT ADDDATE(&apos;2001-01-02&apos;, INTERVAL 31 DAY); # &apos;2001-02-02&apos;
        * SELECT ADDDATE(&apos;2001-01-02&apos;, INTERVAL 31 SECOND); # &apos;2001-02-02 00:00:31&apos;
    * YEAR, MONTH DAY, HOUR, MINUTE, SECOND
    * MINUTE_SECOND, DAY_SECOND, HOUR_SECOND, DAY_HOUR ...

2. ADDTIME(expr, expr2) : 将expr2加到expr，然后返回结果.
    * SELECT ADDTIME(&apos;2001-12-31 23:59:59.99999&apos;, &apos;1 1:1:1.00002&apos;); # &apos;2002-01-02 01:01:01.000010&apos;
    * SELECT ADDTIME(&apos;01:00:00.999999&apos;, &apos;02:00:00.999998&apos;); # &apos;03:00:01.999997&apos;

3. CONVERT_TZ(dt, from_tz, to_tz): 将时间日期值dt从时区from_tz到时区to_tz
    * SELECT CONVERT_TZ(&apos;2004-01-01 12:00:00&apos;, &apos;GMT&apos;, &apos;MET&apos;);
    * SELECT CONVERT_TZ(&apos;2004-01-01 12:00:00&apos;, &apos;+00:00&apos;, &apos;+10:00&apos;); # &apos;2004-01-01 22:00:00&apos;

4. CURDATE() CURRENT_DATE(): 当前日期:
    * SELECT CURDATE(); # &apos;2015-06-23&apos;
    * SELECT CURDATE() + 0; 20150623
5. CURTIME() CURRENT_TIME(): 当前时间:
    * SELECT CURTIME(); # &apos;10:40:05&apos;
    * SELECT CURTIME(); # 104005

6. DATE(expr): 提取日期或时间日期表达式expr中的日期部分
    * SELECT DATE(&apos;2015-06-23 10:42:01&apos;);

7. DATEDIFF(expr1, expr2): 返回日期expr1和日期expr2相差的天数, expr1&amp;gt;expr2时为正
    * SELECT DATEDIFF(&apos;1981-11-26 23:45:45&apos;, &apos;2015-06-23&apos;); # -12262
    * SELECT DATEDIFF(ADDDATE(CURDATE(), 20), CURDATE()); # 20

8. DATE_FORMAT:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/06/21/mysql-learning-notes-5-FUNCTION.html</link>
    <guid>/2015/06/21/mysql-learning-notes-5-FUNCTION</guid>
    <pubDate>Sun, 21 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>MySQL (四) 数据控制语言(DCL): CREATE USER/GRANT/REVOKE ..</title>
    <description>
&lt;h2 id=&quot;mysql-数据库管理语句-数据控制语言dcl-data-control-language&quot;&gt;MySQL 数据库管理语句: 数据控制语言(DCL): Data Control Language&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;CREATE/DROP USER&lt;/li&gt;
  &lt;li&gt;GRANT + REVOKE&lt;/li&gt;
  &lt;li&gt;SET PASSWORD&lt;/li&gt;
  &lt;li&gt;SHOW …&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;一create-user-语法&quot;&gt;一、CREATE USER 语法&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;CREATE USER Syntax:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    CREATE USER username [IDENTIFIED BY [PASSWORD] &apos;password&apos;]
        [, username [IDENTIFIED BY [PASSWORD] &apos;password&apos;] ...];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;CREATE USER 栗子:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 创建无密码用户:
    create user no_password;
    exit;
    mysql -uno_password /*目前无任何权限*/

-- 2. 创建密码用户:
    create user what identified BY &apos;what&apos;;
    mysql -uwhat -pwhat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二drop-user-语法&quot;&gt;二、DROP USER 语法&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;DROP USER Syntax&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    DROP USER username [, username, ...]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;DROP USER Example:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    drop user what;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三grant-和-revoke-语法&quot;&gt;三、GRANT 和 REVOKE 语法&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;GRANT and REVOKE Syntax&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    GRANT priv_type [(column_list)] [, priv_type [(column_list) ...]]
        ON [object_type] {tbl_name | * | *.* | db_name.*}
        TO username [IDENTIFIED BY [PASSWORD] &apos;password_string&apos;]
            [, username [IDENTIFIED BY [PASSWORD] &apos;password_string&apos;] ...]
        [REQUIRE
            NONE |
            [{SSL | X509}]
            [CIPHER &apos;cipher&apos; [AND]]
            [ISSUER &apos;issuer&apos; [AND]]
            [SUBJECT &apos;subjectr&apos;]
          ]
        [WITH with_option [with_option] ...]


    object_type =
          TABLE
        | FUNCTION
        | PROCEDURE

    with_option = 
          GRANT OPTION
        | MAX_QUERIES_PER_HOUR count
        | MAX_UPDATES_PER_HOUR count
        | MAX_CONNECTIONS_PER_HOUR count
        | MAX_USER_CONNECTIONS count

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

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
        ON [object_type] {tbl_name | * | *.* | db_name.*}
        FROM username [, username, ...];

    REVOKE ALL PRIVILEGES, GRANT OPTION FROM username [, username ...];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;GRANT and REVOKE Example&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 赋予用户what权限select
    grant select
        on table Student
        to what;

-- 2. 赋予用户what对表Student的权限: 
    -- select, insert, update, delete, create, drop
    grant select, insert, update, delete, create, drop # 注意, 这里create 并没什么卵用
        on table Student
        to what;

-- 3. 赋予用户在数据库student中创建表: CREATE
    grant create
        on table student.* -- 注释: 注意, 数据库名.* 才行，如果指定单表则无效
        to what;

-- 4. 赋予用户what对数据库student的所有权限
    grant all privileges
        on student.*
        to what;

-- 5. 赋予用户what@&apos;192.168.1.%&apos;所有数据库权限
    -- @&apos;192.168.1.%&apos; 表示用户的范围
    -- 默认自带what@localhost
    -- show grants查看;
    grant all privileges
        on *.*
        to what@&apos;192.168.1.%&apos;;

-- 6. 查看用户权限
    show grants;

-- 7. 拥有赋予他人权限的权限: WITH GRANT OPTION
    grant select, insert
        on table student.*
        to what@localhost
        with grant option;

-- 8. ALTER 权限
    grant alter
        on table student.Student
        to what;

-- 9. 待续
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 收回用户what对表Student的select权限
    revoke select
        on table student.Student
        from what;

-- 1.1
    revoke select, insert, drop
        on table student.Student
        from what

-- 2. 收回用户what对数据库student的所有权限及GRANT OPTION
    revoke all privileges, grant option
        on table student.*
        from what;

-- 3. 收回用户what的所有权限
    revoke all privileges, grant option
        from what;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四rename-user-语法---rename-table-语法&quot;&gt;四、RENAME USER 语法 ( –&amp;gt; RENAME TABLE 语法)&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;RENAME USER 语法 和 栗子&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    RENAME USER old_user TO new_user
        [, old_user TO new_user];

Example:
    rename user what to student_user;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五set-password-语法设置密码&quot;&gt;五、SET PASSWORD 语法(设置密码)&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;SET PASSWORD Syntax&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    SET PASSWORD = PASSWORD(&apos;some password for current user&apos;);
    SET PASSWORD FOR user_name = PASSWORD(&apos;password for user_name&apos;);
    
    * user_name值应该以user_name@host_name的格式给定
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六show-语法&quot;&gt;六、SHOW 语法&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;SHOW Syntax&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 显示所有有权限的数据库
    SHOW DATABASES;
    栗子: show databases;

-- 2. 显示所有表
    SHOW TABLES;
    栗子: show tables; (必须进入数据库: use database_name;)

-- 3. 显示创建表的语句：
    SHOW CREATE TABLE table_name;
    栗子: show create table Student;

-- 4. 显示创建数据库/模式语句
    SHOW CREATE {DATABASE | SCHEMA} db_name;
    栗子: show create database mysql;

-- 5. 显示权限:
    SHOW GRANTS [FOR user];
    栗子: show grants; -- 当前用户所拥有的权限
          show grants for what; -- 用户 what 有的权限
    注意: user 应该以 user_name@host_name 的形式

-- 6. 显示MySQL服务器所支持的系统权限清单
    SHOW PRIVILEGES;

-- 7. 显示正在运行的线程、用户等
    SHOW [FULL] PROCESSLIST;
    栗子: show processlist;

-- 8 还有很多 ....
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/06/20/mysql-learning-notes-4-DCL.html</link>
    <guid>/2015/06/20/mysql-learning-notes-4-DCL</guid>
    <pubDate>Sat, 20 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>MySQL (三) 数据操作语言DML: JOIN/UNION/TRUNCATE ...</title>
    <description>
&lt;h2 id=&quot;mysql-数据操作语法-data-manipulate-language&quot;&gt;MYSQL 数据操作语法: Data Manipulate Language&lt;/h2&gt;

&lt;h3 id=&quot;一jion-语法&quot;&gt;一、JION 语法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;JOIN Syntax&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MySQL支持以下JOIN语法，主要用于SELECT语句的table_references部分
    和 多表 DELETE 和 UPDATE 语句

table_references:
    table_reference [, table_reference ...]

table_reference:
      table_factor
    | join_table

table_factor:
      tbl_name [[AS] alias]
        [{USE | IGNORE | FORCE} INDEX (key_list)]
    | (table_references)
    | { OJ table_reference LEFT OUTER JOIN table_reference 
            ON conditional_expr }

join_table:
      table_reference [INSERT | CROSS] JOIN table_factor [join_condition]
    | table_reference STRAIGHT_JOIN table_factor
    | table_reference STRAIGHT_JOIN table_factor ON condition
    | table_reference LEFT [OUTER] JOIN table_reference join_condition
    | table_reference NATURAL [LEFT [OUTER]] JOIN table_factor
    | table_reference RIGHT [OUTER] JOIN table_reference join_condition
    | table_reference NATURAL [RIGNT [OUTER]] JOIN table_factor

join_condition:
      ON condition_expr
    | USING (column_list)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 JOIN Example:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 待续
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二union-语法&quot;&gt;二、UNION 语法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 UNION Syntax: UNION用于把来自许多SELECT语句的结果组合到一个结果集中&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    SELECT ...
    UNION [ALL | DISTINCT]
    SELECT ...
    [UNION [ALL | DISTINCT] SELECT ...]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 UNION Example&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 待续
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;三truncate-语法&quot;&gt;三、TRUNCATE 语法:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 TRUNCATE Syntax
    &lt;ul&gt;
      &lt;li&gt;TRUNCATE TABLE 用于完全清空一个表。逻辑上，等同于删除所有行的DELETE, 但实际上有所不同&lt;/li&gt;
      &lt;li&gt;对于InnoDB表，如果有需要引用表的外键限制，则TRUNCATE TABLE被映射到DELETE上；否则使用快速删减（取消和重新创建表）。使用TRUNCATE TABLE重新设置AUTO_INCREMENT计数器，设置时不考虑是否有外键限制。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    TRUNCATE [TABLE] tbl_name;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 TRUNCATE Example:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 待续
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四handler-语法&quot;&gt;四、HANDLER 语法:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 HANDLER Syntax:
    &lt;ul&gt;
      &lt;li&gt;对于InnoDB表，如果有需要引用表的外键限制，则TRUNCATE TABLE被映射到DELETE上；否则使用快速删减（取消和重新创建表）。使用TRUNCATE TABLE重新设置AUTO_INCREMENT计数器，设置时不考虑是否有外键限制。&lt;/li&gt;
      &lt;li&gt;HANDLER…OPEN语句用于打开一个表，通过后续的HANDLER…READ语句建立读取表的通道。本表目标不会被其它线程共享，也不会关闭，直到线程调用HANDLER…CLOSE或线程中止时为止。如果您使用一个别名打开表，则使用其它HANDLER语句进一步参阅表是必须使用此别名，而不能使用表名。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HANDLER tbl_name OPEN [ AS alias ]
HANDLER tbl_name READ index_name { = | &amp;gt;= | &amp;lt;= | &amp;lt; } (value1,value2,...)
    [ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
    [ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ { FIRST | NEXT }
    [ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name CLOSE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 HANDLER Example
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 待续
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;五load-data-infile-语法&quot;&gt;五、LOAD DATA INFILE 语法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 LOAD DATA INFILE:
    &lt;ul&gt;
      &lt;li&gt;LOAD DATA INFILE语句用于高速地从一个文本文件中读取行，并装入一个表中。文件名称必须为一个文字字符串。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE &apos;file_name.txt&apos;
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [FIELDS
        [TERMINATED BY &apos;string&apos;]
        [[OPTIONALLY] ENCLOSED BY &apos;char&apos;]
        [ESCAPED BY &apos;char&apos; ]
    ]
    [LINES
        [STARTING BY &apos;string&apos;]
        [TERMINATED BY &apos;string&apos;]
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...)]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六replace-语法&quot;&gt;六、REPLACE 语法:&lt;/h3&gt;
&lt;p&gt;…&lt;/p&gt;
</description>
    <link>/2015/06/20/mysql-learning-notes-3-DML-2.html</link>
    <guid>/2015/06/20/mysql-learning-notes-3-DML-2</guid>
    <pubDate>Sat, 20 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>MySQL (二) 数据操作语言(DML): INSERT DELETE UPDATE SELECT</title>
    <description>
&lt;h2 id=&quot;数据操纵语言dml-data-manipulate-language&quot;&gt;数据操纵语言(DML): Data Manipulate Language&lt;/h2&gt;

&lt;h3 id=&quot;一-insert&quot;&gt;一. INSERT&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax 1:
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name [(col_name, ...)]
        VALUES ({expr | DEFAULT}, ....), ({expr | DEFAULT}, ...), ...
        [ON DUPLICATE KEY UPDATE col_name = expr, ...]

Syntax 2:
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name
        set col_name={expr | DEFAULT}, ...
        [ON DUPLICATE KEY UPDATE col_name=expr, ...]

Syntax 3:
    INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
        [INTO] tbl_name [(col_name, ...)]
        SELECT ...
        [ON DUPLICATE KEY UPDATE col_name=expr, ...]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 栗子&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# create database if not exists student default character charset utf8;
# use student;
# create table if not exists Student (id int primary key auto_increment, Sname varchar(255) not null);
#
# 插入数据
方法一:
    insert into Student (Sname)
        values (&apos;Lory&apos;);

方法二:
    insert into Student
        values (&apos;Mark&apos;); # 这里由于id是auto_increment, 所以可以省略; 否则不能, 必须全部字段都有值

方法三:
    insert into Student
        set Sname = &apos;Smith&apos;;

方法四: 插入多条
    insert into Student
        values (&apos;Mary&apos;), (&apos;Maria&apos;), (&apos;Kiumi&apos;);

方法五: 
    insert into Student
        select &apos;Mr.Cao&apos;;

# 查看
select * from Student;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二select&quot;&gt;二、SELECT&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    SELECT
        [ALL | DISTINCT | DOSTINCTROW]
          [HIGH_PRIORITY]
          [STRAIGHT_JOIN]
          [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
          [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
        select_expr, select_expr, ...
        [INTO OUTFILE &apos;file_name&apos; export_options
            | INTO DUMPFILE &apos;file_name&apos;]
        [FROM table_references
            [WHERE where_defination]
            [GROUP BY {col_name | expr | position}
                [ASC | DESC], ... [WITH ROLLUP]
              ]
            [HAVING where_defination]
            [ORDER BY {col_name | expr | position}
                [ASC | DESC], ...  
              ]
            [LIMIT {[offset,] row_count | row_count OFFSET offset}]
            [PROCEDURE procedure_name(argument_list)]
            [FOR UPDATE | LOCK IN SHARE MODE]
          ]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;SELECT 栗子&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 显示Student表的所有数据
    select * from Student;

-- 2. 显示Student表的Sname列数据
    select Sname from Student;

-- 3. 条件Where
    select Sname
        from Student
        where id = 10;

-- 4. 限制Limit
    select Sname
        from Student
        limit 3;

-- 5. 分组GROUP BY, ASC(默认正序), DESC(逆序)
    select *
        from Student
        group by Sname
        desc;

-- 建表:
    drop table if exists Student;
    create table if not exists Student 
    (
        Sno integer int primary key, 
        Sname varchar(255) not null
    );
    create table if not exists Course
    (
        Cno integer primary key,
        Cname varchar(255)
    );
    create table SC
    (
        id integer auto_increment,
        Sno integer,
        Cno integer,
        Grade integer,
        primary key (id),
        foreign key (Sno) references Student (Sno),
        foreign key (Cno) references Course (Cno)
    );

-- 6. 连接多张基本表，通过where相同条件
    select Student.Sno, Student.Sname, Course.Cname, SC.Grade
        from Student, Course, SC
        where SC.Sno = Student.Sno and
              SC.Cno = Course.Cno;

-- 7. 按字段排序: ORDER BY 
    select * 
        from Student
        order by Sname
        desc;

-- 8. 输出到文件中 OUTFILE/DUMPFILE &apos;file_name&apos;:
    .... (待续)

-- 9. 条件之 HAVING where_defination
    ....

-- 10 Like
    select title, category
        from movie_table
        where
            title like &apos;A%&apos;
            and
            category = &apos;family&apos;
        order by title;

-- 11 分组-&amp;gt;求和sum/求平均avg-&amp;gt;排序
    select first_name, sum(sales)
        from cookie_sales
        group by first_name
        order by sum(sales) desc;

-- 12 不同的值只返回一次，返回的结果没有重复值(distinct)
    select distinct first_name
        from cookie_sales;

-- 13 限制条数，并返回指定位置
    select first, count(day)
        from cookie_sales
        group by first_name
        order by count(day) desc
        limit 0, 4;  -- 从0位置开始，取四条结果
        /*取第二名: limit 1 1;*/

-- 14 函数: MAX MIN SUM AVG COUNT

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

&lt;h3 id=&quot;三update&quot;&gt;三、UPDATE&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 UPDATE 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Single-table 语法:
    UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
        SET col_name1=expr1 [, col_name2=expr2 ...]
        [WHERE where_defination]
        [ORDER BY ...]
        [LIMIT row_count];

Multiple-table 语法:
    UPDATE [LOW_PRIORITY] [IGNORE] table_references
        SET col_name1-expr1 [, col_name2=expr2 ...]
        [WHERE where_defination];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;UPDATE 栗子&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 更新一个字段(列)的所有值
    update SC
        set Grade = 100;

-- 2. 按条件更新
    update SC
        set Grade = 88
        where Sno = 200215123 and Cno = 1;

-- 3. 排序限制条数
    update SC
        set Grade = Grade + 2 -- 这是mysql单行注释, 可以做加减乘除 
        where Cno = 2        
        oreder by Grade desc  # 这也是单行注释，排序
        limit 5;

-- 4. 多表操作:
    .... (待续)

-- 5. 多个条件，更新不同值
    update movie_table
        set category = 
            case
                when drama = &apos;T&apos; then &apos;drama&apos;
                when comedy = &apos;T&apos; then &apos;comedy&apos;
                when action = &apos;T&apos; then &apos;action&apos;
                when gore = &apos;T&apos; then &apos;horror&apos;
                when scifi = &apos;T&apos; then &apos;scifi&apos;
                when for_kide = &apos;T&apos; or cartoon = &apos;T&apos; then &apos;family&apos;
                else &apos;misc&apos;
            end;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四delete&quot;&gt;四、DELETE&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 DELETE 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Single-Table 语法:
    DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
        FROM tbl_name
        [WHER where_defination]
        [ORDER BY ...]
        [LIMIT row_count];

Multiple-Table 语法:
    DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
        tbl_name[.*], [, tbl_name[.*] ...]
        FROM table_references
        [WHERE where_defination];
    或者
    DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
        FROM tbl_name[.*] [, tbl_name[.*] ...]
        USING table_references
        [WHERE where_defination];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 DELETE 栗子(慎用)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 删除一个表中的所有数据(慎用)
    delete from a;

-- 2. 满足条件就删除
    delete from SC
        where Grade = 0;

-- 3. 排序限制: 去掉最高分
    delete from SC
        order by Grade desc
        limit 1;

-- 4. 多表:
    ....(待续)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/06/18/mysql-learning-notes-2-DML.html</link>
    <guid>/2015/06/18/mysql-learning-notes-2-DML</guid>
    <pubDate>Thu, 18 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>MySQL (一) 数据库定义语言(DDL) CREATE/DROP/ALTER</title>
    <description>
&lt;h2 id=&quot;mysql-之-数据定义语言结构定义-data-definition-language&quot;&gt;MYSQL 之 数据定义语言(结构定义): Data Definition Language&lt;/h2&gt;

&lt;h3 id=&quot;第一-创建create&quot;&gt;第一: 创建CREATE&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 创建数据库/模式: CREATE DATABASE/SCHEME 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    create {database | schema} [IF NOT EXISTS] db_name
        [create_specification [, create_specification] ...];

    create_specification 选项:
        [DEFAULT] CHARACTER SET charset_name |
        [DEFAULT] COLLATE collation_name;

    # 栗子:
    1. create database blog;
    2. create database if not exist blog;
    3. create database blog;
        default character set utf8;
    4. create database if not exists blog
        default character set utf8;
    5. create schema blog
        default character set utf8;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 创建索引: CREATE INDEX 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    CREATE [UNIQUE | FULLTEXTISPATIAL] INDEX index_name
        [USING index_type]
        ON tbl_name (index_col_name);
    
    index_col_name 选项:
        col_name [(length)] [ASC | DESC];

    # 栗子
    # show databses;
    # create database if not exist t;
    # use t;
    # show tables;
    # create table t (a int primary key auto_increment, b varchar(255));
    # desc table_name;
    create index t_index 
        on t (a desc, b);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 创建表: CREATE TABLE 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Syntax
    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
        [(create_defination, ...)]
        [table_option] [select_statement];
或
    CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
        [(] LIKE old_tbl_name [)];

create_defination:
    column_defination 
    | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name, ...)
    | KEY [index_name] [index_type] (index_col_name, ...)
    | INDEX [index_name] [index_type] (index_col_name, ...)
    | [CONSTRAINT [symbol]] UNIQUE [index]
        [index_name] [index_type] (index_col_name, ...)
    | [FULLTEXTISPATIAL] [INDEX] [index_name] (index_col_name, ...)
    | [CONSTRAINT [symbol]] FOREIGN KEY
        [index_name] (index_col_name, ...) [reference_definition]
    | CHECK (expr)

column_defination:
    col_name type [NOT NULL | NULL] [DEFAULT default_value]
        [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
        [COMMET &apos;string&apos;] [reference_defination]

type:
      TINYINT(length)       [UNSIGNED] [ZEROFILL]
    | SMALLINT[(length)]    [UNSIGNED] [ZEROFILL]
    | MEDIUMINT[(length)]   [UNSIGNED] [ZEROFILL]
    | INT[(length)]         [UNSIGNED] [ZEROFILL]
    | INTEGER[(length)]     [UNSIGNED] [ZEROFILL]
    | BIGINT[(length)]      [UNSIGNED] [ZEROFILL]
    | REAL[(length, decimals)]      [UNSIGNED] [ZEROFILL]
    | DOUBLE[(length, decimals)]    [UNSIGNED] [ZEROFILL]
    | FLOAT[(length, decimals)]     [UNSIGNED] [ZEROFILL]
    | DECIMAL(length, decimals)     [UNSIGNED] [ZEROFILL]
    | NUMERIC(length, decimals)     [UNSIGNED] [ZEROFILL]
    | DATE
    | TIME
    | TIMESTAMP
    | DATETIME
    | CHAR(length) [BINARY | ASCII | UNICODE]
    | VARCHAR(length) [BINARY]
    | TINYBLOB
    | BLOB
    | MEDIUMBLOB
    | LONGBLOB
    | TINYTEXT [BINARY]
    | TEXT [BINARY]
    | MEDIUMTEXT [BINARY]
    | LONGTEXT [BINARY]
    | ENUM(value1, vaule2, value3, ...)
    | SET(value1, value2, value3, ...)
    | spatial_type

index_of_col_name:
    col_name [(length)] [ASC | DESC]

reference_defination:
    REFERENCES tbl_name [(index_col_name)]
        [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
        [ON DELETE reference_option]
        [ON UPDATE reference_option]

reference_option:
    RESTRICT | CASCADE | SET NULL | NO ACTION

table_options:
    table_option [table_option] ...

table_option:
      {ENGINE | TYPE} = engine_name
    | AUTO_INCREMENT = value
    | AVG_ROW_LENGTH = value
    | [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
    | CHECKSUM = {0 | 1}
    | COMMENT = &apos;string&apos;
    | CONNECTION = &apos;connect_string&apos;
    | MAX_ROWS = value
    | MIN_ROWS = value
    | PACK_KEYS = {0 | 1 | DEFAULT}
    | PASSWORD = &apos;string&apos;
    | DELAY_KEY_WRITE = {0 | 1}
    | ROW_FORMAT = {DEFAULT | DYNAMIC | FIXED | COMPRESSED | REDUNDANT | COMPACT}
    | UNION = (tbl_name[, tbl_name, ...])
    | INSERT_METHOD = {NO, FIRST, LAST}
    | DATE DIRECTORY = &apos;absolute path to directory&apos;
    | INDEX DIRECTORY = &apos;absolute path to directory&apos;

partition_options:
    PARTITION BY
          [LINEAR] HASH(expr)
        | [LINEAR] KEY(column_list)
        | RANGE(expr)
        | LIST(column_list)
    [PARTITIONS num]
    [ SUNPARTITION BY
          [LINEAR] HASH(expr)
        | [LINEAR] KEY(column_list)
      [SUBPARTITIONS(num)]
    ]
    [(partition_defination) [, partition_defination, ...]]

partition_defination:
    PARTITION partition_name
        [VALUES {
            LESS THAN (expr) | MAXVALUE | IN (value_list)
            }]
        [[STORAGE] ENGINE [=] engine_name]
        [COMMENT [=] &apos;comment_text&apos;]
        [DATA DIRECTORY [=] &apos;data_dir&apos;]
        [INDEX DIRECTORY [=] &apos;index_dir&apos;]
        [MAX_ROWS [=] max_number_of_rows]
        [MIN_ROWS [=] min_number_of_rows]
        [TABLESPACE [=] (tablespace_name)]
        [NODEGROUP [=] node_group_id]
        [(subpartition_defination) [, (subpartition_defination), ...]]

subpartition_defination:
    SUBPARTITION logical_name
        [[STORAGE] ENGINE [=] engine_name]
        [COMMENT [=] &apos;comment_text&apos;]
        [DATA DIRECTORY [=] &apos;data_dir&apos;]
        [INDEX DIRECTORY [=] &apos;index_dir&apos;]
        [MAX_ROWS [=] max_number_of_rows]
        [MIN_ROWS [=] min_number_of_rows]
        [TABLESPACE [=] (tablespace_name)]
        [NODEGROUP [=] node_group_id]

select_statement:
    [IGNORE | REPLACE] [AS] SELECT ... (some legal select statement)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// CREATE TABLE 栗子
// 1. 最简单
create table Student
(
    sno int,
    sname varchar(10),
    cno int
);

// 2. INF: 原子性(主属性不为空NULL) + 主键(PRIMARY key) 
create table Student
(
    id int primary key auto_increment,
    sname varchar(10) not null,
    cname varchar(30) not null
);

// 3. 不存在才创建
create table if no exists Cost
(
    id int,
    money decimal(20, 2),
    date date,
    time timestamp,
    comment text,
    age integer(2),
    primary key (id)
);

// 4. 外键/外码: foreign key .... references ...
create table SC
(
    id int,
    sno int,
    primary key (id),
    foreign key (sno) references Student(sno)
);
desc SC;
show create table SC;

// 5. 临时TABLE, 退出后自动删除
create temporary table temp_table 
(
    ...
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;一数据定义语言&quot;&gt;一、数据定义语言:&lt;/h2&gt;

&lt;h3 id=&quot;第一-删除drop&quot;&gt;第一: 删除DROP&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;1 DROP DATABASE 语法
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DROP {DATABASE | SCHENA} [IF EXISTS] db_name&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;2 DROP INDEX 语法
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DROP INDEX index_name ON tbl_name&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3 DROP TABLE 语法
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DROP [TEMPRARY] TABLE [IF EXISTS] tbl_name[, tbl_name, ...] [RESTRICT | CASCADE]&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;第二-改变结构alter&quot;&gt;第二: 改变结构ALTER&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1 ALTER DATABASE 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    ALTER {DATABASE | SCHEMA} [db_name]
        alter_specification [, alter_specification, ...]

    alter_specification:
          [DEFAULT] CHARACTER SET charset_name
        | [DEFAULT] COLLATE collation_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 ALTER TABLE 语法&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Syntax:
    ALTER [IGNORE] TABLE tbl_name
        alter_specification [, alter_specification, ...]

    alter_specification:
          ADD [COLUMN] column_defination [FIRST | LAST | FIFTH | BEFORE col_name | AFTER col_name]
        | ADD [COLUMN] (column_defination, ...)
        | ADD INDEX [index_name] [index_type] (index_col_name, ...)
        | ADD [CONSTRAINT [symbol]]
            PROMARY KEY [index_name] [index_type] (index_col_name, ...)
        | ADD [CONSTRAINT [symbol]]
            UNIQUE [index_name] [index_type] (index_col_name, ...)
        | ADD [FULLTEXTISPATIAL] [index_name] (index_col_name, ...)
        | ADD [CONSTRAINT [symbol]]
            FOREIGN KEY [index_name] (index_col_name, ...)
            [reference_defination]
        | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
        | CHANGE [COLUMN] old_col_name column_defination
        | MODIFY [COLUMN] column_defination [FIRST | AFTER col_name]
        | DROP [COLUMN] col_name
        | DROP PRIMARY KEY
        | DROP INDEX index_name
        | DROP FOREIGN KEY fk_symbol
        | DISABLE KEYS
        | ENABLE KEYS
        | RENAME [TO] new_tbl_name
        | ORDER BY col_name
        | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
        | [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
        | DISCADE TABLESPACE
        | IMPORT TABLESPACE
        | table_options
        | partition_options
        | ADD PARTITION partition_defination
        | DROP PARTITION partition_names
        | COALESCE PARTITION number
        | REORGANIZE PARTITION partition_names INTO (partition_definations)
        | ANALYZE PARTITION partition_names
        | CHECK PARTITION partition_names
        | OPTIMIZE PARTITION partition_names
        | REBUILD PARTITION partition_names
        | REPAIR PARTITION partition_names
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 ALTER 栗子&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- 1. 加入主键:
    alter table Student
        add primary key (Sno);
    /* desc Student; */
    /* show create table Student; */

-- 2. 加入新列:
    alter table Student
        add column Sdept varchar(2);

-- 3. 外键(含外键的是子表，被外键的是父表， 父表必须有主键)
    alter table SC
        add foreign key (Sno) references Student(Sno);

-- 4. 添加按顺序的列,默认是最后(LAST):
    -- FIRST: 加到第一列
    -- SENCOND: 加到第二咧
    -- THIRD: 加到第三列
    -- AFTER column_name: 在column_name列之后一列
    -- BEFORE column_name: 在column_name列之前一列
    -- 栗子:
    alter table Student
        add column id int first;
    alter table Student
        add column Sname varchar(20) before Sdept;
    alter table Student
        add column sex varchar(1) after Sname;
    show create table Student;

-- 5. 改变列名及属性(一起): CHANGE
    -- 1. 重命名, 最好RENAME
    alter table Student
        change column sex Ssex varchar(1);
    -- 2. 只修改属性, 用MODIFY效果更佳
    alter table Student
        change column Sname Sname varchar(30);

-- 6. 修正仅属性: MODIFY
    alter table Student
        modify column Sname varchar(255);
    show create table Student;

-- 7. 删除列:
    alter table Student
        drop column first_name;
    desc Student;

-- 8. 删除主键PRIMARY KEY:
    alter table Student
        drop primary key;

-- 9. 删除外键FOREIGN KEY: 
    -- 要拿到CONSTRAINT_NAME
        -- 1 show create table Student;
        -- 2 自己命名的限制名
    alter table Student
        drop foreign key Student_ibfk_1; -- 这里限制名是自动生成的
        /* 限制名可以自己在定义或添加属性时指定 */

-- 10. 删除索引INDEX:
    alter table Student
        drop index index_name;

-- 11. 重命名表名:
    alter table Student
        rename to student;
    show tables;
    另一种办法:
        rename table student to Student;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/06/18/mysql-learning-notes-1-DDL.html</link>
    <guid>/2015/06/18/mysql-learning-notes-1-DDL</guid>
    <pubDate>Thu, 18 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>CSS3 基础</title>
    <description>
&lt;h3 id=&quot;一初识css3&quot;&gt;一、初识CSS3&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1.1 在编写CSS3样式时，不同的浏览器可能需要不同的前缀.&lt;/li&gt;
&lt;/ul&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;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;-webkit&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;chrome和safari&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;-moz&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;firefox&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;-ms&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;IE&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;-o&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;opera&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;1.2 CSS3 能做: 圆角、图片边框、文字阴影和盒阴影、过渡、动画
    &lt;ul&gt;
      &lt;li&gt;选择器: class id tagname …&lt;/li&gt;
      &lt;li&gt;圆角效果: border-radius&lt;/li&gt;
      &lt;li&gt;块阴影与文字阴影&lt;/li&gt;
      &lt;li&gt;色彩: 新颜色: HSL CMYK HSLA RGBA&lt;/li&gt;
      &lt;li&gt;渐变效果&lt;/li&gt;
      &lt;li&gt;个性化字体: @Font-face&lt;/li&gt;
      &lt;li&gt;多背景图: 一个元素上添加多层背景&lt;/li&gt;
      &lt;li&gt;边框背景图&lt;/li&gt;
      &lt;li&gt;变形出路: 对HTML元素进行旋转、缩放、移动、一些JavaScript动画&lt;/li&gt;
      &lt;li&gt;多栏布局&lt;/li&gt;
      &lt;li&gt;媒体查询: 针对不同屏幕分辨率，应用不同样式&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二边框&quot;&gt;二、边框&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;2.1 圆角效果: border-radius
    &lt;ul&gt;
      &lt;li&gt;作用: 向元素添加圆角边框&lt;/li&gt;
      &lt;li&gt;Usage:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-radius: 10px; /*所有角都使用半径为10px的圆角*/&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-radius: 5px 4px 3px 2px; /*四个半径分别为左上角、右上角、右下角、左下角，顺时针*/&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;border-radius的值除了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;px&lt;/code&gt;单位，还能用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;百分比(%)&lt;/code&gt;或者&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;em&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-radius: 水平 / 垂直;&lt;/code&gt;
                &lt;ul&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-radius: 10px / 20px;&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-radius: 水平1 水平2 / 垂直1 垂直2&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.demo {
    border-radius: 10px 20px 30px 40px;
}

等价于

.demo {
    border-top-left-radius: 10px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 30px;
    border-bottom-left-radius: 40px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.demo {
    border-radius: 10px / 20px;
}

等价于

.demo {
    border-top-left-radius: 10px 20px;
    border-top-right-radius: 10px 20px;
    border-bottom-right-radius: 10px 20px;
    border-bottom-left-radius: 10px 20px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.demo {
    border-radius: 10px 20px / 20px 10px;
}

等价于

.demo {
    border-top-left-radius: 10px 20px;
    border-top-right-radius: 20px 10px;
    border-bottom-right-radius: 10px 20px;
    border-bottom-left-radius: 20px 10px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-html 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;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;circle&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;semi-circle&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-css 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;nt&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;.circle&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;/*与width设置一致*/&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#9da&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;/*四个角值都设为宽度Or高度一半*/&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;50px&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;nt&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;.semi-circle&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;50px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;background&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#9da&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;50px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;50px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&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;ul&gt;
  &lt;li&gt;2-2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;阴影 box-shadow&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;作用: 向盒子添加阴影，支持添加一个或多个&lt;/li&gt;
      &lt;li&gt;Usage:
        &lt;ul&gt;
          &lt;li&gt;box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式];&lt;/li&gt;
          &lt;li&gt;解释:
            &lt;ul&gt;
              &lt;li&gt;X轴偏移量: 必须，水平阴影的位置，允许负值&lt;/li&gt;
              &lt;li&gt;Y轴偏移量: 必须，垂直阴影的位置，允许负值&lt;/li&gt;
              &lt;li&gt;阴影模糊半径: 可选，模糊的距离&lt;/li&gt;
              &lt;li&gt;阴影扩展半径: 可选, 阴影的尺寸&lt;/li&gt;
              &lt;li&gt;阴影颜色: 可选，阴影的颜色，省略默认为黑色&lt;/li&gt;
              &lt;li&gt;投影方式: 可选，（设置inaset为内部阴影方式，否则省略为外阴影）&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-css 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;/*外阴影*/&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;.boxshadow-outset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#333&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;c&quot;&gt;/*内阴影*/&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;.boxshadow-inset&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#666&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;insert&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;c&quot;&gt;/*多阴影*/&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;.boxshadow-multi&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;100px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;box-shadow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#f00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;-4px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;-2px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;12px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;5px&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#330&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;inset&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;ul&gt;
  &lt;li&gt;2-3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;阴影 box-shadow (二)&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;阴影模糊半径(blur-radius)&lt;/code&gt; 与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;阴影扩展半径(spread-radius)&lt;/code&gt; 的区别
        &lt;ul&gt;
          &lt;li&gt;阴影模糊半径: 参数可选，其值只能为正，如果其值为0时，表示阴影不具有模糊效果，其值越大阴影的边缘月模糊&lt;/li&gt;
          &lt;li&gt;阴影扩展半径: 参数可选，其值可以是正负值，如果其值为正，整个阴影都延展扩大，反之值为负，则缩小&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X轴偏移量(offset-x)&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Y轴偏移量(offset-y)&lt;/code&gt; 可以设置为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;负数&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;box-shadow: offset-x offset-y [blur-radius] [spread-radius] [color] [projection-style]&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;负值，阴影方向: 边框左边向左，上边向上;&lt;/li&gt;
          &lt;li&gt;正直, 阴影方向: 边框右边向右，下边向下&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;当 offset-x 和 offset-y 都为0 时，四个边框都有阴影&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box {
    width: 100px;
    height: 100px;
    box-shadow: 4px 4px 5px -2px #ccc;    
}

&amp;lt;div class=&quot;box&quot;&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2-4 Border-image 边框应用图片
    &lt;ul&gt;
      &lt;li&gt;Function: 类似background-image, 添加图片&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-image: url(IMG_SOURCE) height width repeat-style&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;height/width 单位可以px也可以百分比&lt;/li&gt;
          &lt;li&gt;repeat-style: repeat(重复) stretch(拉伸) round(平铺)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;三颜色color&quot;&gt;三、颜色Color&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;3-1 颜色之RGBA
    &lt;ul&gt;
      &lt;li&gt;含义: R(红) G(绿) B(蓝) A(透明度)&lt;/li&gt;
      &lt;li&gt;Syntax: color: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rgba(R-v, G-v, B-v, Alpha);&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;3-2 渐变色彩Gradient
    &lt;ul&gt;
      &lt;li&gt;CSS3 Gradient 分为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;线性渐变(linear-gradient)&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;径向渐变(radial-gradient)&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;linear-gradient(angle | to &amp;lt;side-or-corner&amp;gt;, color-from[, color-stop])&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;side-or-conor&amp;gt; = [left | right] || [top | bottom]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;color-from/stop = &amp;lt;color&amp;gt; [ &amp;lt;percentage&amp;gt; | &amp;lt;length&amp;gt;]?&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;color-from 到 color-stop之间可以很多个过渡颜色，不限制个数&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;to top == 0 deg&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;to bottom == 180 deg&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;to top right == 45deg&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;颜色后面的percentage表示长度 == length&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;background: linear-gradient(45deg, blue, red);&lt;/li&gt;
          &lt;li&gt;color: linear-gradient(to left top, rgb(255,255,255), rgb(0, 0, 0))&lt;/li&gt;
          &lt;li&gt;background: linear-gradient(0 deg, blue, green 40%, red);
            &lt;ul&gt;
              &lt;li&gt;/* A gradient going from the bottom to top, starting blue, being green after 40% and finishing red */&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box {
    width: 400px;
    height: 400px;
    line-height: 400px;
    text-align: center;
    color: #000;
    font-size: 24px;
    background-image: linear-gradient(to right top, red, green, blue 30%);
}

&amp;lt;div class=&quot;box&quot;&amp;gt;
    右下角向左上角的线性渐变背景
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;四文字与字体&quot;&gt;四、文字与字体&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;4-1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-overflow&lt;/code&gt; 与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;word-wrap&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: 用来设置是否使用一个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;省略标记(...)&lt;/code&gt;标示对象内文本的溢出/&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-overflow: clip | ellipsis;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;clip: 表示剪切&lt;/li&gt;
              &lt;li&gt;ellipsis: 标示显示省略标记(…)&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-overflow: inherit | initial | unset;&lt;/code&gt; // Global values&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;But careful:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-overflow&lt;/code&gt; 只是用来说明文字溢出时用什么方式显示，要实现溢出时产生的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;省略号&lt;/code&gt;的效果，还必须定义&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;强制文本在行内显示(white-space: nowrap;)&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;溢出内容为隐藏(overflow: hidden;)&lt;/code&gt;, 只有这样才能实现溢出文本显示省略号的效果.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.box {
    /* 以下三条必须一起使用，否则无效*/
    text-overflow: ellipsis; /*显示省略号*/
    white-space: nowrap; /*禁止包含文本，只允许行内显示*/
    overflow: hidden; /*隐藏省略部分*/

    /*只能容下十(..)个字*/
    width: 200px;
    font-size: 20px; 
    background: #ccc;
}

&amp;lt;div class=&quot;box&quot;&amp;gt;
    一二三四五六七八(此处省略)
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;4-1-2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;word-wrap&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: 设置文本行为，当前行超过指定容器的边界时是否断开转行.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;word-wrap: normal | break-word;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;normal为默认值, break-word 设置在长单词或URL地址内部进行换行.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;用处: 文本编辑textarea 或 contentEditable = “true”;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;4-2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;嵌入字体@font-face&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@font-face&lt;/code&gt;能够加载服务器端的字体文件，让浏览器端可以显示用户电脑里没有安装的字体.&lt;/li&gt;
      &lt;li&gt;Syntax&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* @font-face Syntax*/
@font-face {
    font-family: diyFontName; /* 自定义字体名称; 该字体名称为后面使用*/
    src: 字体文件在服务器上的相对或绝对路径;
}

p {
    font-size: 12px;
    font-family: diyFontName; /* 与 @font-face中的font-family自定义的名字相同*/
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;4-3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;文本阴影text-shadow&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: text-shadow用来设置文本的阴影效果&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-shadow: offset-x offset-y blur-radius color;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-shadow: color offset-x offset-y blur-radius;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-shadow: offset-x offset-y color;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;text-shadow: offset-x offset-y;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;text-shadow: 1px 1px 2px black;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 设置文字阴影*/
.box {
    width: 340px;
    height: 200px;
    line-height: 200px;
    padding: 30px;
    font: bold 55px/100% &quot;微软雅黑&quot;;
    text-align: center;
    background: #C5D;
    text-shadow: 2px 2px 4px rgb(255, 255, 0);
}

&amp;lt;div class=&quot;box&quot;&amp;gt;
    文字阴影
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;五与背景相关的样式&quot;&gt;五、与背景相关的样式&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;5-1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-origin&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: 设置元素背景的原始位置&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-origin: border-box | padding-box | content-box | inherit;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;border-box: 边框&lt;/li&gt;
          &lt;li&gt;padding-box: 内边距(默认值)&lt;/li&gt;
          &lt;li&gt;content-box: 内容区域&lt;/li&gt;
          &lt;li&gt;inherit: 继承&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Take Care: 背景必须是no-repeat, 否则background-origin失效&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* background-origin 原始起始位置 */
.wrap {
    width: 400px;
    height: 400px;
    border: 20px dashed #000; /* border-box 开始位置 */
    padding: 40px; /* padding-box 开始位置 */
    font-size: 40px;
    font-weight: bold;
    color: #000;
    background: #ccc url(IMG_URL) no-repeat;

    background-origin: content-box;
}

.content {
    width: inherit;
    height: 80px;
    border: 1px solid #333;
}

&amp;lt;div class=&quot;wrap&quot;&amp;gt;
    &amp;lt;div class=&quot;content&quot;&amp;gt;内容盒子&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5-2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-clip&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: 用来将背景图片作适当裁剪以适应实际需求.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-clip: border-box | padding-box | content-box | no-clip | inherit;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;默认值是 border-box&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* background-clip 裁剪背景 */
.wrap {
    width: 400px;
    height: 400px;
    border: 20px dashed #000; /* border-box 开始位置 */
    padding: 40px; /* padding-box 开始位置 */
    font-size: 40px;
    font-weight: bold;
    color: #000;
    background: #ccc url(IMG_URL) no-repeat;

    background-origin: border-box;
    background-clip: content-box;
}

.content {
    width: inherit;
    height: 80px;
    border: 1px solid #333;
}

&amp;lt;div class=&quot;wrap&quot;&amp;gt;
    &amp;lt;div class=&quot;content&quot;&amp;gt;内容盒子&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5-3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-size&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function: 设置背景图片的大小.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-size: auto | cover | contain | &amp;lt;长度值&amp;gt; | &amp;lt;百分比&amp;gt;;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;auto: 默认值，不改变背景图片的原始高度和宽度.&lt;/li&gt;
              &lt;li&gt;cover: 覆盖, 将背景图片等比例缩放以填满整个容器.&lt;/li&gt;
              &lt;li&gt;contain: 容纳，将背景图片等比例缩放至某一边紧贴容器边缘为止.&lt;/li&gt;
              &lt;li&gt;
                &lt;长度值&gt;: 成对出现100px 50px, 即背景width height; 当只设置一个值时，图片等比例缩放.
&lt;/长度值&gt;
              &lt;/li&gt;
              &lt;li&gt;
                &lt;百分比&gt;: 只类型为0-100%, 其他同上.
            
&lt;/百分比&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* background-size */
.box {
    background: url(IMG_URL) no-repeat;
    width: 500px;
    height: 300px;
    border: 1px solid #999;
    background-size: cover;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5-4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multiple backgrounds&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;多重背景，也就是CSS2里background的属性外加origin、clip和size组成的新background的多次叠加，缩写为用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;逗号&lt;/code&gt;隔开的每组值;&lt;/li&gt;
          &lt;li&gt;用分解写法时，如果有多个背景图片，而其他属性只有一个(例如background-repeat只有一个)，表明所有图片都应用该属性值.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax: 以下都必须一起写
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background: bg1, bg2, bg3, ...;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;bgN : url(IMG_URL);&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-position: bgp1, bgp2, bgp3 ...;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;bgpN: offset-x offset-y;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-repeat: no-repeat, no-repeat, no-repeat ...;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;background-color: color;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;只能一个值&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Take Care&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;background-color 只能设置一个&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* multiple background */
.box {
    width: 400px;
    height: 400px;
    border: 1px solid #999;

    background: url(IMG_1), url(IMG_2), url(IMG_3);
    background-position: left top, 0 200px, 200px 0; /* 具体视图片大小而定 */
    background-repeat: no-repeat, no-repeat, no-repeat;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;5-5 导航实例&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt;
    &amp;lt;title&amp;gt;CSS制作立体导航&amp;lt;/title&amp;gt;
    &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;http://www.w3cplus.com/demo/css3/base.css&quot;&amp;gt;
    &amp;lt;style&amp;gt;
        body{
          background: #ebebeb;
        }
        .nav{
          width:560px;
          height: 50px;
          font:bold 0/50px Arial;
          text-align:center;
          margin:40px auto 0;
          background: #f65f57;
          /*制作圆*/
          border-radius: 10px;
          /*制作导航立体风格*/
          box-shadow: 5px 5px 10px #ccc;
        }
        .nav a{
          display: inline-block;
          -webkit-transition: all 0.2s ease-in;
          -moz-transition: all 0.2s ease-in;
          -o-transition: all 0.2s ease-in;
          -ms-transition: all 0.2s ease-in;
          transition: all 0.2s ease-in;
        }
        .nav a:hover{
          -webkit-transform:rotate(10deg);
          -moz-transform:rotate(10deg);
          -o-transform:rotate(10deg);
          -ms-transform:rotate(10deg);
          transform:rotate(10deg);
        }

        .nav li{
          position:relative;
          display:inline-block;
          padding:0 16px;
          font-size: 13px;
          text-shadow:1px 2px 4px rgba(0,0,0,.5);
          list-style: none outside none;
        }
        /*使用伪元素制作导航列表项分隔线*/
         .nav li:before {
            display: inline-block;
            content: &apos;&apos;;
            height: 18px;
            width: 1px;
            background: linear-gradient(to right, #ef6b5f,#ca584e);
            position: absolute;
            right: 0;
            top: 18px;
         }
        
        /*删除第一项和最后一项导航分隔线*/
        .nav li:last-child:before {
         display: none;   
        }
        .nav a, .nav a:hover{
          color:#fff;
          text-decoration: none;
        }

    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;ul class=&quot;nav&quot;&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;Home&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;About Me&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;Portfolio&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;Blog&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;Resources&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;&quot;&amp;gt;Contact Me&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;六css3选择器上-伪类选择器&quot;&gt;六、CSS3选择器(上): 伪类选择器&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;6-1 属性选择器
    &lt;ul&gt;
      &lt;li&gt;Syntax: E为选择器, attr为属性名, val为属性值
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E[attr=&quot;val&quot;]&lt;/code&gt;: 等于&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E[attr^=&quot;val&quot;]&lt;/code&gt;: 属性attr以val &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;开头(^)&lt;/code&gt; 的选择器E&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E[attr$=&quot;val&quot;]&lt;/code&gt;: 属性attr以val &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;结尾($)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E[attr*=&quot;val&quot;]&lt;/code&gt;: 属性attr &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;包含(*)&lt;/code&gt; val&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
a[class^=&quot;column&quot;] {
    background: red;
}
a[href$=&quot;.doc&quot;] {
    background: green;
}
a[title*=&quot;box&quot;] {
    background: blue;
}

&amp;lt;!-- Html --&amp;gt;
&amp;lt;a href=&quot;##&quot; class=&quot;columnNews&quot;&amp;gt;我的背景想变成红色&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;##&quot; class=&quot;columnVideo&quot;&amp;gt;我的背景想变成红色&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;##&quot; class=&quot;columnAboutUs&quot;&amp;gt;我的背景想变成红色&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;
&amp;lt;a href=&quot;1.doc&quot;&amp;gt;我的背景想变成绿色&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;2.doc&quot;&amp;gt;我的背景想变成绿色&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;
&amp;lt;a href=&quot;##&quot; title=&quot;this is a box&quot;&amp;gt;我的背景想变成蓝色&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;##&quot; title=&quot;box1&quot;&amp;gt;我的背景想变成蓝色&amp;lt;/a&amp;gt;
&amp;lt;a href=&quot;##&quot; title=&quot;there is two boxs&quot;&amp;gt;我的背景想变成蓝色&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;6-2 结构性伪类选择器- root
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:root&lt;/code&gt;选择器，是指HTML文档的根选择器, 而根元素是&amp;lt;html&amp;gt;, 所以就等同于html.&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:root {...}&lt;/code&gt; == &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;html {...}&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-3 结构性伪类选择器- not
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:not&lt;/code&gt; 称为 否定选择器.和jQuery中的:not选择器一样，可以选择除了某个元素以外的所有元素.
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一般配合属性选择使用, 别忘了括号&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input:not([type=&quot;submit&quot;]) {border: 1px solid red;}&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;input中除了type为submit之外的&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-4 结构性伪类选择器- empty
    &lt;ul&gt;
      &lt;li&gt;Function: 选择没有任何内容的元素，这里没有是指没有任何内容，包括空格也不能有.(注释不包括)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
div {
    height: 50px;
}


div:empty {
    border: 1px solid #ccc;
}

&amp;lt;!-- html --&amp;gt;
&amp;lt;div&amp;gt;我这里有内容&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt; &amp;lt;!-- 我这里有一个空格 --&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;&amp;lt;!-- 我这里任何内容都没有 --&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;6-5 结构性伪类选择器- target
    &lt;ul&gt;
      &lt;li&gt;Function: 目标选择器，用来匹配文档中a标签href值为另一个ID选择器值的目标元素&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
.menuSection { display: none; }
:target {
    /* 这里: target指的就是 id=&quot;brand&quot; 的div对象 */
    display: block;
}

&amp;lt;!-- html --&amp;gt;
&amp;lt;!-- 当点击Brand时, ID等于brand的选择器触发:target {...}效果 --&amp;gt;
&amp;lt;h2&amp;gt; &amp;lt;a href=&quot;#brand&quot;&amp;gt;Brand&amp;lt;/a&amp;gt;&amp;lt;h2&amp;gt;
&amp;lt;div class=&quot;menuSection&quot; id=&quot;brand&quot;&amp;gt;
    Content for Brand
&amp;lt;.div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
/* 当点击 href=&quot;brand&quot;的a标签时, ID=&quot;brand&quot;的标签的p标签变成黄色背景 */
#brand:target p { background: green;}

&amp;lt;!-- html --&amp;gt;
&amp;lt;div id=&quot;brand&quot;&amp;gt;
    &amp;lt;a href=&quot;#brand&quot; &amp;gt;你变黄&amp;lt;/a&amp;gt;
    &amp;lt;p&amp;gt;变黄&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;6-6 结构性伪类选择器- first-child
    &lt;ul&gt;
      &lt;li&gt;Function: 父选择器的第一个子选择器&lt;/li&gt;
      &lt;li&gt;:first-child == :nth-child(1)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-7 结构性伪类选择器- last-child
    &lt;ul&gt;
      &lt;li&gt;Function: 父元素的最后一个子元素&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-8 结构性伪类选择器- nth-child(n)
    &lt;ul&gt;
      &lt;li&gt;Funtion: 用来选择父元素的某一个或多个子元素, 不区分div:nth-child(n)的类型div&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;n 为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;整数值&lt;/code&gt;, 从1开始&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;n 为表达式 或 关键词(odd&lt;/td&gt;
                  &lt;td&gt;even):&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2n+1&lt;/code&gt; == &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;odd&lt;/code&gt; : 表示第&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;奇数&lt;/code&gt;子元素&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2n+2&lt;/code&gt; == &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;even&lt;/code&gt; : 表示第&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;偶数&lt;/code&gt;子元素&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n+5&lt;/code&gt; : 表示第5个元素(包含)以后的所有子元素&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-n+5&lt;/code&gt; : 表示第5个元素(包含)以前的所有子元素&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kN&lt;/code&gt;: k为常数，如之前的2n+1的2, 此时的第一个元素是k, 每隔k个子元素&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kN + m&lt;/code&gt;: 第一个元素为k+m(&amp;gt;0, 否则2k+m开始), 以后每隔k个子元素&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-9 结构性伪类选择器- nth-last-child(n)
    &lt;ul&gt;
      &lt;li&gt;与:nth-child(n)类似，只不过从最后一个开始倒数&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6-10 first-of-type 选择器 与 last-of-type 选择器
    &lt;ul&gt;
      &lt;li&gt;与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:first-child&lt;/code&gt; 的区别就是, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;指定了元素的类型&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;而类型就比如: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.box &amp;gt; p:first-of-type&lt;/code&gt; 中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt;, 因为p元素不一定是容器中的第一个子元素;&lt;/li&gt;
      &lt;li&gt;当 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.box &amp;gt; p:first-child {...}&lt;/code&gt; 中的第一个子元素不是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt;时，该css不产生任何效果; 但是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.box &amp;gt; p:first-of-type { ... }&lt;/code&gt; 会一直找到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* CSS */
/* 注意:伪类选择器冒号(:)前后不要空格*/
.box &amp;gt; p:first-child {
    background: red;
}

.box &amp;gt; p:first-of-type {
    background: green;
}

&amp;lt;!-- html --&amp;gt;
&amp;lt;div class=&quot;box&quot;&amp;gt;
    &amp;lt;div&amp;gt;第一个是DIV, 所有:first-child没效果&amp;lt;/div&amp;gt;
    &amp;lt;p&amp;gt;但是:first-of-type有效，该P变为绿色&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;6-11 nth-of-type(n) 选择器
    &lt;ul&gt;
      &lt;li&gt;和nth-child(n)类似, 取值可以是整数, 表达式或者关键字(odd, even)&lt;/li&gt;
      &lt;li&gt;与:nth-child(n)的区别是, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:nth-of-type(n)&lt;/code&gt;区分类型，只有同类型才计数, 而 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:nth-child(n)&lt;/code&gt; 不区分类型&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
/* box选择器下偶数子元素 */
/* 这里，even为偶数, 那么如果box所有元素的第二个元素类型不是div的话，这个css对所有失效; 这里所说的第二个元素指的是nth-child(n)中表达式的第一个作用的元素. */
/* 如果去掉这里的&apos;div&apos;符号，那么效果一直在; 去掉&apos;div&apos;符号试试 */
.box &amp;gt; div:nth-child(even) {
    background: red: 
}

/* box选择器下的全部类型为div的元素偶数次序*/
/* 当&apos;div&apos;省略时, 自动匹配偶数元素的类型, 每个类型的偶数次序都产生作用*/
.box &amp;gt; div:nth-of-type(even) {
    background: green;
}

&amp;lt;!-- html --&amp;gt;
&amp;lt;div class=&quot;box&quot;&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落元素&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
  &amp;lt;div&amp;gt;我是一个Div元素&amp;lt;/div&amp;gt;
  &amp;lt;p&amp;gt;我是一个段落&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;6-13 nth-last-of-type(n) 选择器&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;6-14 only-child 选择器
    &lt;ul&gt;
      &lt;li&gt;选择父元素有且只有唯一一个子元素的情况生效.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;6-15 only-of-type 选择器&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;区别&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;对象&lt;/th&gt;
      &lt;th&gt;空格&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;区别&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;first-child 与 first-of-type 及 nth-child 与 nth-of-type 及 only-child 与 only-of-type 及 last-child 与 last-oftype&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;*-child不区分类型，但是如果它前面指定了类型(也就是说可以不指定)，那么如果符合表达式的第一个作用的元素与该类型不同时，效果全部失效, 没有任何作用. *-of-type:区分类型，如果它前面指定了类型，则它会自动分类，找到与其类型相同的符合表达式的第一个元素开始作用; 如果没指定类型，则每种类型符合表达式的第一个元素开始生效.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;七css选择器下-伪类选择器&quot;&gt;七、CSS选择器(下): 伪类选择器&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;7-1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:enable&lt;/code&gt;选择器 与 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:disabled&lt;/code&gt;选择器
    &lt;ul&gt;
      &lt;li&gt;在Web的表单中，有些表单元素有可用(“:enabled”)和不可用(“:disabled”)状态下，比如输入框、密码框、复选框等.&lt;/li&gt;
      &lt;li&gt;在默认情况下，这些表单元素都默认为enabled状态&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
div { margin: 30px; }

input[type=&quot;text&quot;]:enabled {
    border: 1px solid #f36;
    box-shadow: 0 0 5px #f36;
}

input[type=&quot;text&quot;]:disbaled {
    box-shadow: none;
}

&amp;lt;!-- html --&amp;gt;
&amp;lt;form acttion=&quot;#&quot;&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;label for=&quot;enabled&quot;&amp;gt;可用输入框:&amp;lt;/label&amp;gt;
        &amp;lt;input type=&quot;text&quot; id=&quot;enabled&quot; /&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;label for=&quot;disabled&quot;&amp;gt;禁用输入框:&amp;lt;/label&amp;gt;
        &amp;lt;input type=&quot;text&quot; id=&quot;disabled&quot; /&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;7-2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:checked&lt;/code&gt;选择器
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;选中&lt;/code&gt;, 在表单元素中, 单选(radio)和复选(checkbox)都具有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;选中&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;未选中&lt;/code&gt;状态.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7-3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::selection&lt;/code&gt;选择器
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;鼠标选中文本&lt;/code&gt;的状态为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::selection&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;“:selection”伪元素是用来匹配&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;凸显&lt;/code&gt;的文本.&lt;/li&gt;
      &lt;li&gt;浏览器默认情况下，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;用鼠标选择&lt;/code&gt;网页文本是以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;深蓝的背景，白色的字体&lt;/code&gt;显示的.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
p::selection { background: orange;}

&amp;lt;!-- html --&amp;gt;
&amp;lt;div class=&quot;box&quot;&amp;gt;
    &amp;lt;p&amp;gt;鼠标选择该文本的颜色是橘黄色&amp;lt;/p&amp;gt;
    &amp;lt;div&amp;gt;鼠标选择是默认颜色是蓝色&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;7-4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:read-only&lt;/code&gt;选择器
    &lt;ul&gt;
      &lt;li&gt;只读选择器，　就是当元素中readonly属性值设为readonly的时候.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7-5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:read-write&lt;/code&gt;选择器
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:read-write&lt;/code&gt;选择器刚好与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:read-only&lt;/code&gt;选择器相反，主要用来指定当元素处于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;非只读&lt;/code&gt;状态时的样式。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;7-6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::before&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::after&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;与CSS2中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:before&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:after&lt;/code&gt;一样&lt;/li&gt;
      &lt;li&gt;主要用来给元素的前面或后面插入内容&lt;/li&gt;
      &lt;li&gt;常和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content&lt;/code&gt;配合使用，使用最多的场景是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;清除浮动&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css 清除浮动代码 */
.clearfix::before,
.clearfix::after {
    content: &apos;.&apos;;
    display: block;
    height: 0;
    visibility: hidden;
    overflow: hidden;
}
.clearfix:after { clear: both;}
.clearfix {zoom: 1;}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css 在::before和::after添加阴影效果 */
.effect::before, .effect::after {
    content: &quot;&quot;;
    position: absolute;
    z-index: -1;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);

    /* 通过position:absolute和top,bottom,left,right确定block的大小, 不用width和height, 更灵活 */
    top: 50%;
    bottom: 0;
    left: 10px;
    right: 10px;

    border-radius: 100px 10px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;八变形与动画上&quot;&gt;八、变形与动画(上)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;8-1 变形–旋转: rotate()
    &lt;ul&gt;
      &lt;li&gt;Function: 旋转rotate()函数通过指定的角度使元素相对原点进行旋转(二维).&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tranform: rotate( D deg);&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;当 D 为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;正值&lt;/code&gt;时，元素相对原点中心&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;顺时针&lt;/code&gt;旋转;&lt;/li&gt;
          &lt;li&gt;当 D 为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;负值&lt;/code&gt;时, 元素相对原点中心&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;逆时针&lt;/code&gt;旋转&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transform: rotate(-45deg);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-2 变形–扭曲: skew()
    &lt;ul&gt;
      &lt;li&gt;Funtcion:
        &lt;ul&gt;
          &lt;li&gt;扭曲(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skew()&lt;/code&gt;)函数能够让元素&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;倾斜显示&lt;/code&gt;.它可以将一个对象以其中心位置绕着X轴和Y轴按照一定的角度倾斜.&lt;/li&gt;
          &lt;li&gt;这与rotate()函数的旋转不同, rotate()函数只是旋转,而不会改变元素的形状.&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skew()&lt;/code&gt;不会旋转，而只会改变元素的形状.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skew(x)&lt;/code&gt; 等价于 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skewX(x)&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;仅使元素在水平(X轴)方向扭曲变形&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skew(x, y)&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;使元素水平(X轴)和垂直(Y轴)方向同时扭曲.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;skewY(y)&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;使元素在垂直(Y轴)方向扭曲变形.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-3 变形–缩放: scale()
    &lt;ul&gt;
      &lt;li&gt;Funtion: 让元素根据&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;中心原点&lt;/code&gt;对象进行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;缩放&lt;/code&gt;.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scale(x)&lt;/code&gt; 完全等价于 X(x)`&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scale(X, Y)&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;使元素水平(X轴)和垂直(Y轴)方向同时缩放&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scaleY(y)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Take Care&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;scale()的取值默认的值为1;&lt;/li&gt;
          &lt;li&gt;当值&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.01~0.99&lt;/code&gt;     –&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;缩小&lt;/code&gt;;&lt;/li&gt;
          &lt;li&gt;当值&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;=1.01&lt;/code&gt;时 –&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;放大&lt;/code&gt;;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-4 变形–位移: translate()
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;可以将元素向指定的方向移动，类似于position中的relative.&lt;/li&gt;
          &lt;li&gt;可以将元素从原来的位置移动，而不影响X、Y轴上的任何Web组件.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;值可以为正负&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translate(x)&lt;/code&gt; === &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translateX(x)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translate(x, y)&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translateY(y)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;8-5 变形–矩阵: matrix()&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;8-6 变形–原点: transform-origin
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;在没有重置transform-origin改变元素原点位置的情况下，CSS变形进行的旋转、位移、缩放，扭曲等操作都是以元素自己中心位置进行变形&lt;/li&gt;
          &lt;li&gt;但很多时候，我们可以通过transform-origin来对元素进行原点位置改变，使元素原点不在元素的中心位置，以达到需要的原点位置。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-7 动画: transition
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;鼠标点击(click)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;获得焦点(:focus)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;被点击&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;对元素任何改变&lt;/code&gt;中触发，并平滑地以动画效果改变CSS的属性值.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Steps:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 1: 在默认样式中声明元素的元素状态&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 2: 声明过渡元素的最终状态，比如悬浮(:hover)状态&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Step 3: 在默认样式中通过添加过渡函数，添加一些不同的样式&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Categorie:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-property&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-duration&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-timing-function&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-delay&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-7 动画–过渡属性: transition-property
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;transition-property用来指定过渡动画的CSS属性名称，而这个过渡属性只有具备一个中点值的属性（需要产生动画的属性）才能具备过渡效果&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Properties:
        &lt;ul&gt;
          &lt;li&gt;大部分css属性, 比如 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-property: background-color;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-8 动画–过渡所需时间: transition-duration
    &lt;ul&gt;
      &lt;li&gt;Function: 主要用来设置一个属性过渡到另一个属性所需要的时间。
        &lt;ul&gt;
          &lt;li&gt;一般设置在初始状态上&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-duration: 0.5s;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;单位: 秒(s), 毫秒(ms)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-9 动画–过渡函数: transition-timing-function
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;指的是过渡的”缓动函数”，即从初始状态到最终状态.&lt;/li&gt;
          &lt;li&gt;主要用来指定浏览器的过滤速度，以及过滤期间的操作进展情况.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Functions(函数): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;从初始状态到最终状态&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ease&lt;/code&gt;: 由快到慢&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ease-in&lt;/code&gt;:　加速(渐显效果)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ease-out&lt;/code&gt;: 减速(渐隐效果)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ease-in-out&lt;/code&gt;: 先加速再减速(渐显渐隐)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;linear&lt;/code&gt;: 恒速&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-timing-function: FUNCTION_NAME;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-timing-function: ease-in-out;&lt;/code&gt; /&lt;em&gt;先加速再减速&lt;/em&gt;/&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;8-10 动画–过渡延迟时间: transition-delay
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;与&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-duration&lt;/code&gt;相似, 但是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-duration&lt;/code&gt;是用来设置过渡动画的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;持续时间&lt;/code&gt;;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-delay&lt;/code&gt;主要用来指定&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一个动画开始执行时的时间&lt;/code&gt;, 也就是说当改变元素属性值后多长时间开始执行(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;延迟时间&lt;/code&gt;).&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Usage:
        &lt;ul&gt;
          &lt;li&gt;有时我们想改变两个或者多个css属性的transition效果时，只要把几个transition的声明串在一起，用逗号（“，”）隔开，然后各自可以有各自不同的延续时间和其时间的速率变换方式。但需要值得注意的一点：第一个时间的值为 transition-duration，第二个为transition-delay。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition-delay: TIME;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;合并: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition: [PROPERTY] DURATION DELAY, [PROPERTY2] DURATION2 DELAY2;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;transition: width 1s 0.5s, height 5s 3s;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;长度在延迟0.5秒后执行，持续时间1s;&lt;/li&gt;
              &lt;li&gt;高度在延迟3s后执行, 持续时间5s&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;九变形与动画下&quot;&gt;九、变形与动画(下)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;9-1 Keyframes介绍
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@keyframes&lt;/code&gt;称为关键帧&lt;/li&gt;
          &lt;li&gt;在一个&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@keyframes&lt;/code&gt;中的样式规则可以由多个百分比构成，如在”0%”到”100%”之间创建更多个百分比，分别给每个百分比中给需要有动画效果的元素加上不同样式，从而达到一种在不断变化的效果.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;Step 1: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation: ANIMATION_NAME DURATION TIMING_FUNCTION DELAY;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;Step 2: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@keyframes ANIMATION_NAME { 0%{...}, 20%{...}..., 100%{...}}&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css */
div {
    width: 300px;
    height: 200px;
    background: red;
    color: #fff;
    margin: 20px auto;
}

div:hover {
    animation: change 5s ease-out 0.2s;
}

@keyframes change {
    0% {
        background: red;
    }

    20% {
        background: orange;
    }

    40% {
        background: yellow;
    }

    60% {
        background: green;
    }

    80% {
        background: blue;
    }

    100% {
        background: purple;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;9-2 调用动画: animation-name
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;用来调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@keyframes&lt;/code&gt;定义好的动画.&lt;/li&gt;
          &lt;li&gt;名称必须完全一致，区分大小写.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-name: none | IDENT[, none | DENT]*&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;IDENT 指的是你定义的名字&lt;/li&gt;
              &lt;li&gt;none 为默认值，是任何动画失效，可用于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;覆盖任何动画&lt;/code&gt;.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-3 设置动画播放时间: animation-duration
    &lt;ul&gt;
      &lt;li&gt;类似: transition-duration&lt;/li&gt;
      &lt;li&gt;完成从0%到100%需要的时间&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-4 设置动画播放方式: animation-timing-function
    &lt;ul&gt;
      &lt;li&gt;类似: transition-timing-function&lt;/li&gt;
      &lt;li&gt;多组用逗号(,)分开&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-5 设置动画开始播放时间: animation-delay
    &lt;ul&gt;
      &lt;li&gt;类似: transition-delay&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-6 设置动画播放次数: animation-iteration-count
    &lt;ul&gt;
      &lt;li&gt;Function: 定义动画播放次数&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-iteration-count: infinite | &amp;lt;number&amp;gt; [, infinite | &amp;lt;number&amp;gt; ... ;]&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;infinite: 无限循环&lt;/li&gt;
              &lt;li&gt;number 为整数，小数也行.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* css3: animation */
div {
    width: 200px;
    height: 200px;
    border: 1px solid red;
    margin: 20px auto;
}

div span {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: orange;
    border-radius: 100%;
    animation-name: ball-around;
    animation-duration: 10s;
    animation-timing-function: ease;
    animation-delay: 1s;
    animation-iteration-count: infinite; 
}
 
@keyframes ball-around {
    0% {
        transform: translate(0, 0);
    }
    25% {
        transform: translate(180px, 0);
        /* 等价于 transform: translateX(180px); */
    }
    50% {
        transform: translate(180px, 180px);
    }
    75% {
        transform: translate(0, 180px);
    }
    100% {
        transform: translateY(0);
    }
}


&amp;lt;!-- html --&amp;gt;
&amp;lt;div&amp;gt;
    &amp;lt;span&amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;9-7 设置动画播放方向: animation-direction
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-direction: normal | alternate [, normal | alternate, ...];&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;normal&lt;/code&gt; 是默认值, 也就是动画的每次循环都是向前播放;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alternate&lt;/code&gt;: 动画播放在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第偶次&lt;/code&gt;向前播放, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;第奇次&lt;/code&gt;向反方向播放.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-8 设置动画的播放状态: animation-play-state
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-play-state: running | paused;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;running&lt;/code&gt;: 默认值,主要作用是类似音乐播放器，可以通过paused将正在播放的动画停下来，也可以通过running将暂停的动画重新播放.这里的重新播放不一定是从元素动画开始播放,而是从暂停的哪个位置开始播放.另外如果暂停了动画的播放，元素的样式将回到最原始的设置状态.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Example:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-play-state: paused;&lt;/code&gt; : 页面加载时，动画不播放.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-9 设置动画时间外属性: animation-fill-mode
    &lt;ul&gt;
      &lt;li&gt;Function: 在动画开始之前和结束之后发生的操作&lt;/li&gt;
      &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation-fill-mode: none | forwards | backwords | both;&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;node&lt;/code&gt;: 默认, 表示动画预期进行和结束，在动画完成最后一帧时，动画会反转到初始帧;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forwards&lt;/code&gt;: 表示动画在结束后继续应用最后的关键帧的位置;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;backwards&lt;/code&gt;: 会在向元素应用动画样式时迅速应用动画的初始帧;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;both&lt;/code&gt;: 元素动画同时具有forwards和backwards效果.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;9-10 制作3D旋转导航练习&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;十布局样式&quot;&gt;十、布局样式&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;10-1 多列布局–Columns
    &lt;ul&gt;
      &lt;li&gt;Function: CSS Multi Column Layout Module&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;columns: &amp;lt;column-width&amp;gt; || &amp;lt;column-count&amp;gt;;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;column-width&amp;gt;&lt;/code&gt;: 主要用来定义多列每列的宽度;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;column-count&amp;gt;&lt;/code&gt;: 主要用来定义多列中的列数&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-2 多列布局–column-width
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-width&lt;/code&gt;的使用和CSS中的width属性一样，不过不同的是，column-width属性在定义元素列宽的时候，既可以单独使用，也可以和多列属性中的其他属性配合使用.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-width: auto | &amp;lt;length&amp;gt;;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt;: 默认，元素多列的宽度由其他属性决定，比如column-count;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;length&lt;/code&gt;: 正数 + 单位&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-3 多列布局–column-count
    &lt;ul&gt;
      &lt;li&gt;Function: 列数&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-count: auto | &amp;lt;integer&amp;gt;;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;auto&lt;/code&gt;: 默认，表示元素只有一列，其主要依靠浏览器计算自动设置;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;integer&amp;gt;&lt;/code&gt;: 列数, 正整数&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-4 列间距–column-gap
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-gap: normal | &amp;lt;length&amp;gt;;&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-5 列表边框–column-rule
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;主要用来定义列与列之间的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;边框宽度&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;边框样式&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;边框颜色&lt;/code&gt;.但column-rule是不占用任何空间位置，在列与列之间改变其宽度不会改变任何列的位置.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-rule: &amp;lt;column-rule-width&amp;gt; | &amp;lt;column-rule-style&amp;gt; | &amp;lt;column-rule-color&amp;gt;;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-width&lt;/code&gt; 类似 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-width&lt;/code&gt;, 大于等于零的数，也可以是关键字: medium、thick、thin.&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-rule-style&lt;/code&gt; 类似 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-style&lt;/code&gt;, 默认值为none, 其他属性值: hidden, dotted, dashed, solid, double, groove, ridge, inset, outset&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-rule-color&lt;/code&gt; 类似 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-color&lt;/code&gt;, 可以所有颜色，也可以是透明色(transparent);&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-6 跨列设置–column-span
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;column-span: none | all;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;none : 不跨列;&lt;/li&gt;
              &lt;li&gt;all : 夸所有列;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-7 盒子模型
    &lt;ul&gt;
      &lt;li&gt;在盒模型中主要包括width、height、border、background、padding和margin这些属性&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;box-sizing: content-box | border-box | inherit;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;定义盒模型的尺寸解析方式&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content-box&lt;/code&gt;: 默认值,也就是元素的宽度(width)和高度(height)等于元素边框(border)加上元素内边距(padding)加上元素内容快读或高度(content width/height).&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;border-box&lt;/code&gt;: 重新定义CSS2.1中盒模型组成的模式, 也就是说元素的宽度或高度等于元素内容的宽度或高度。&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-8 伸缩布局(一): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Flexbox Box&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;第一，屏幕和浏览器窗口大小发生改变也可以灵活调整布局；&lt;/li&gt;
      &lt;li&gt;第二，可以指定伸缩项目沿着主轴或侧轴按比例分配额外空间（伸缩容器额外空间），从而调整伸缩项目的大小；&lt;/li&gt;
      &lt;li&gt;第三, 可以指定伸缩项目沿着主轴或侧轴将伸缩容器额外空间，分配到伸缩项目之前、之后或之间；&lt;/li&gt;
      &lt;li&gt;第四，可以指定如何将垂直于元素布局轴的额外空间分布到该元素的周围；&lt;/li&gt;
      &lt;li&gt;第五，可以控制元素在页面上的布局方向；&lt;/li&gt;
      &lt;li&gt;第六，可以按照不同于文档对象模型（DOM）所指定排序方式对屏幕上的元素重新排序。也就是说可以在浏览器渲染中不按照文档流先后顺序重排伸缩项目顺序。&lt;/li&gt;
      &lt;li&gt;Step:
        &lt;ul&gt;
          &lt;li&gt;1 创建一个flex容器: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;display: flex;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {display: -webkit-flex; display: flex;}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;2 Flex 项目显示
            &lt;ul&gt;
              &lt;li&gt;Flex项目是Flex容器的子元素。他们沿着主要轴和横轴定位。默认的是沿着水平轴排列一行。你可以通过flex-direction来改变主轴方向修改为column，其默认值是row。&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;3 Flex项目列显示
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {display: -webkit-flex; display: flex; -wekit-flex-direction: column; flex-direction: column;}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;4 Flex项目移动到顶部
            &lt;ul&gt;
              &lt;li&gt;主要取决于主轴的方向.如果是垂直方向通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;align-items&lt;/code&gt;设置;如果是水平方向通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;justify-content&lt;/code&gt;设置.&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {-webkit-flex-direction: colun; flex-direction: column; -webkit-justify-content: flex-start; justify-content: flex-start;}&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {display: -webkit-flex; display: flex; -webkit-flex-direction: row; flex-direction: row; -webkit-align-items: flex-start; align-items: flex-start;}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;10-9 伸缩布局(二)
    &lt;ul&gt;
      &lt;li&gt;5 Flex项目移到左边
        &lt;ul&gt;
          &lt;li&gt;flex项目称动到左边或右边也取决于主轴的方向。如果flex-direction设置为row，设置justify-content控制方向；如果设置为column，设置align-items控制方向。&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer{ display: -webkit-flex; display: flex; -webkit-flex-direction: row; flex-direction: row; -webkit-justify-content: flex-start; justify-content: flex-start; }&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer{ display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; -webkit-align-items: flex-start; align-items: flex-start; }&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;6 Flex项目移动右边
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer{ display: -webkit-flex; display: flex; -webkit-flex-direction: row; flex-direction: row; -webkit-justify-content: flex-end; justify-content: flex-end; }&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer{ display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; -webkit-align-items: flex-end; align-items: flex-end; }&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;7 水平垂直居中
        &lt;ul&gt;
          &lt;li&gt;在Flexbox容器中制作水平垂直居中是微不足道的。设置justify-content或者align-items为center。另外根据主轴的方向设置flex-direction为row或column。&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {display: -webkit-flex; display: flex; -webkit-flex-direction: row; flex-direction: row; -webkit-align-items: center; align-items: center; -webkit-justify-content: center; justify-content: center;}&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.flexcontainer {display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;}&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;8 Flex项目实现自动伸缩
        &lt;ul&gt;
          &lt;li&gt;可以自定义一个flex项目，如何相对于flex容器实现自动的伸缩。需要给每个flex项目设置flex属性设置需要伸缩的值.&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.bigitem {-webkit-flex: 200; flex: 200;}&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.smallitem {-webkit-flex: 100; flex: 100;}&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;十一media-queries-与-responsive-设计&quot;&gt;十一、Media Queries 与 Responsive 设计&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;11-1 Media Queries – 媒体类型(一)
    &lt;ul&gt;
      &lt;li&gt;一、媒体类型
        &lt;ul&gt;
          &lt;li&gt;媒体类型(Media Type)在CSS2中是一个常见的属性，也是一个非常有用的属性，可以通过媒体类型对不同的设备指定不同的样式.&lt;/li&gt;
          &lt;li&gt;常见的类型 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;all(全部)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;screen(屏幕)&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print(页面打印或打印预览模式)&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;11-2 Media Queries – 媒体类型(二)
    &lt;ul&gt;
      &lt;li&gt;媒体类型的引用方法:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;link标签&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@import&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;CSS3新增的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@media&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;link&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;Function: link方法引入媒体类型其实是在&lt;link /&gt;标签引用样式的时候，通过link标签中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;media&lt;/code&gt;属性来指定不同的媒体类型。&lt;/li&gt;
          &lt;li&gt;Example:
            &lt;ul&gt;
              &lt;li&gt;&amp;lt;link rel=”stylesheet” type=”text/css” href=”style.css” &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;media=&quot;screen&quot;&lt;/code&gt; /&amp;gt;&lt;/li&gt;
              &lt;li&gt;&amp;lt;link rel=”stylesheet” type=”text/css” href=”style.css” &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;media=&quot;print&quot;&lt;/code&gt; /&amp;gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@import&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;Function:
            &lt;ul&gt;
              &lt;li&gt;@import 可以引用样式文件，通用也可以引用媒体类型.&lt;/li&gt;
              &lt;li&gt;@import引入媒体有两种方式.一是在样式中通过@import调用另一个样式；另一种是在&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;标签中的&lt;style&gt;&lt;/style&gt;中引入.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;Example:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@importurl(reset.css) screen;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@importurl(print.css) print;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;head&amp;gt;&amp;lt;style type=&quot;text/css&quot;&amp;gt;@importurl(style.css) all;&amp;lt;/style&amp;gt;&amp;lt;/head&amp;gt;&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@media&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;Function:
            &lt;ul&gt;
              &lt;li&gt;@media 是CSS3中新引进的一个特性，被称为媒体查询.&lt;/li&gt;
              &lt;li&gt;在页面中也可以通过这个属性来引入媒体类型.&lt;/li&gt;
              &lt;li&gt;@media引入媒体类型和@import有点类似.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* (1) 在样式文件中引用媒体类型 */
@media screen {
    选择器{....}
}

/* (2) 使用@media引入媒体类型的方式*/
&amp;lt;head&amp;gt;
    &amp;lt;style type=&quot;text/css&quot;&amp;gt;
        @media screen {
            选择器 {
                ....
            }
        }
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;11-3 Media Queries 使用方法
    &lt;ul&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@media 媒体类型 and (媒体特性) [ and (媒体特性) ...] { 样式 }&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;媒体类型: 也称设备类型, screen, all, print&lt;/li&gt;
              &lt;li&gt;媒体特性: max-width: 480px;
                &lt;ul&gt;
                  &lt;li&gt;媒体特性是通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;min/max&lt;/code&gt;来表示大于等于或小于作为逻辑判断，而不是使用&lt;和&gt;符号来判断.&lt;/和&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 1. 最大宽度 max-width */
/* 意思是指媒体类型小于等于指定的宽度时，样式生效 */
/* 案例: 当屏幕小于或等于480px时, 页面中的广告区块(.ads)都被隐藏. */
@media screen and (max-width: 480px) {
    .ads {
        display: none;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 2.最小宽度: min-width */
/* 指媒体类型大于等于指定宽度时，样式生效. */
/* 案例: 当屏幕大于等于900px时，容器&quot;.wrapper&quot;的宽度为980px. */
@media screen and (min-width: 900px) {
    .wrapper {
        width: 980px;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 3.多个媒体特性使用 */
/* and 关键字连接多个媒体特性 */
/* 案例: 当屏幕600px-900px之间时, body的背景色渲染为&quot;#f5f5f5&quot;. */
@media screen and (min-width: 600px) and
 (max-width: 900px) {
    body {
        background-color: #f5f5f5;
    }
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 4.设备屏幕的输出宽度Device Width */
/* */
&amp;lt;link rel=&quot;stylesheet&quot; media=&quot;screen and (max-width: 480px)&quot; href=&quot;iphone.css&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 5.not关键词 */
/* 使用关键字noy是用来排除某种指定的媒体类型. */
@media not print and (max-width: 1200px) { 样式 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 6.only关键词 */
/* only用来指定某种特定的媒体类型, 可以用来排除不支持媒体查询的浏览器. 其实only很多时候是用来对那些不支持Media Query但却支持Media Type的设备隐藏样式表的.其主要有: 支持媒体特性的设备，正常调用样式，此时就当only不存在; 不支持媒体特性但支持媒体类型的设备，这样就会不读样式，因为其先会读取only而不是screen; 另外不支持Media Query的浏览器, 不论是否支持only, 样式都不会被采用. */
&amp;lt;link rel=&quot;stylesheet&quot; media=&quot;only screen and (max-device-width: 240px)&quot; href=&quot;android240.css&quot; /&amp;gt;

/* 在Media Query中如果没有明确指定Media Type, 那么其默认为all. */
&amp;lt;link rel=&quot;stylesheet&quot; media=&quot;(min-width: 701px) and (max-width: 900px)&quot; href=&quot;mediu.css&quot; /&amp;gt;

/* 另外在样式中，还可以使用多条语句来将同一个样式应用于不同的媒体类型和媒体特性 */
&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; media=&quot;handheld and (max-width: 480px), screen and (min-width: 960px)&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;11-4 Responsive 设计(一)
    &lt;ul&gt;
      &lt;li&gt;响应式设计:(3个条件)
        &lt;ul&gt;
          &lt;li&gt;网站必须建立灵活的网格基础;&lt;/li&gt;
          &lt;li&gt;引用到网站的图片必须是可伸缩的;&lt;/li&gt;
          &lt;li&gt;不同的显示分隔，需要在Media Queries上写不同样式;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Responsive 术语:
        &lt;ul&gt;
          &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;流体网格&lt;/code&gt;: 将每个网格各自使用百分比来控制网格大学.&lt;/li&gt;
          &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;弹性图片&lt;/code&gt;: 不给图片设置固定尺寸，而是根据&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;流体网格&lt;/code&gt;进行缩放，用于适应各种网格的尺寸。
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;img {max-width: 100%;}&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;媒体查询&lt;/code&gt;: Responsive设计离开了Media Queries就失去了意义.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 为每个断点提供不同的图片，这是比较头疼的，因为Media Queries并不能改变图片的&quot;src&quot;的属性值.*/
/* 解决方法: 使用background-image给元素使用背景图片，显示/隐藏父元素，给父元素使用不同的图片，然后通过Media Queries来控制这些图片显示或隐藏.*/
&amp;lt;img src=&quot;image.jpg&quot; data-src-600px=&quot;image-600px.jpg&quot; data-src-800px=&quot;image-800px.jpg&quot; alt=&quot;&quot; /&amp;gt;

@media (min-device-width: 600px) {
    img[data-src-600px] {
        content: attr(data-src-600px, url);
    }
}
@media (min-device-width: 800px) {
    img[data-src-800px] {
        content: attr(data-src-800px, url);
    }
}
                
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;11-5 Responsive 设计(二)
    &lt;ul&gt;
      &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;屏幕分辨率&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;主要断点&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;11-6 Responsive 布局技巧
    &lt;ul&gt;
      &lt;li&gt;在Responsive布局中，可以毫无保留的丢弃:
        &lt;ul&gt;
          &lt;li&gt;1 少用无关要紧的div&lt;/li&gt;
          &lt;li&gt;2 不要使用内联元素(inline)&lt;/li&gt;
          &lt;li&gt;3 尽量少用js或flash&lt;/li&gt;
          &lt;li&gt;4 丢弃没用的绝对定位和浮动样式&lt;/li&gt;
          &lt;li&gt;5 摒弃任何冗余结构和不要使用100%设置&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;对Responsive布局有帮助:
        &lt;ul&gt;
          &lt;li&gt;1 使用HTML5 Doctype和相关指南&lt;/li&gt;
          &lt;li&gt;2 重置好你的样式(reset.css)&lt;/li&gt;
          &lt;li&gt;3 一个简单的有意义的核心布局;&lt;/li&gt;
          &lt;li&gt;4 给重要的网页元素使用简单的技巧，比如导航次啊当之类元素.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;11-7 Responsive 设计 – meta标签
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;在Responsive设计中如果没有meta标签，你就是蹩脚，响应式设计就是空谈.&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meta&lt;/code&gt;标签被称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;可视区域meta标签&lt;/code&gt;.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;meta name=&quot;viewport&quot; content=&quot;&quot; /&amp;gt;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;content属性值，用来处理可视区域:
                &lt;ul&gt;
                  &lt;li&gt;width: 可视区域高度，可以是数字或关键字device-width&lt;/li&gt;
                  &lt;li&gt;height: … 数字或device-height&lt;/li&gt;
                  &lt;li&gt;initial-scale: 页面首次被显示时可视区域的缩放级别，取值为1.0时，将使页面按实际显示，无任何缩放.&lt;/li&gt;
                  &lt;li&gt;minamum-scale: 可视区域的最小缩放级别，表示用户可以将页面缩小的程度，取值为1.0时，禁止用户缩小至实际尺寸以下.&lt;/li&gt;
                  &lt;li&gt;maximum-scale&lt;/li&gt;
                  &lt;li&gt;user-scaleable: 指定用户是否可以对页面进行缩放，设置为yes表示允许缩放, no为禁止缩放.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;在实际项目中，为了让Responsive设计在智能设备中能显示正常，也就是浏览Web页面适应屏幕的大小，显示在屏幕上，可以通过这个可视区域的meta标签进行重置，告诉他使用设备的宽度为视图的宽度，也就是说禁止其默认的自适应页面的效果
&amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-with,intial-scale=1.0&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;11-8 Responsive 设计 – 不同设备的分辨率设置&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 1.1024显屏 */
@media screen and (max-width: 1024px) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 2.800px显屏 */
@media screen and (max-width: 800px) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 3.640px显屏 */
@media screen and (max-width: 640px) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 4.iPad 横屏显屏 */
@media screen and (max-device-width: 1024px) and (orientation: landscape) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 5.iPad 竖屏 */
@media screen and (max-device-widthL 768px) and (orientation: portrait) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 6.iPhone 和 SmartPhones */
@media screen and (min-device-width: 320px) and (min-device-width: 480px) {
    /* style code */
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;十二用户界面与其他重要属性&quot;&gt;十二、用户界面与其他重要属性&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;12-1 自由缩放属性resize
    &lt;ul&gt;
      &lt;li&gt;Function: Css3新特性, resize允许用户通过拖地的方式来修改元素的尺寸来改变元素大小.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;resize: none | both | horizontal | vertical | inherit;&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;none: 用户不能拖动元素修改尺寸.&lt;/li&gt;
              &lt;li&gt;both: 可以拖动元素修改元素的宽度和高度&lt;/li&gt;
              &lt;li&gt;horizontal: 只能改变宽度&lt;/li&gt;
              &lt;li&gt;vertical&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-css 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;nt&quot;&gt;textarea&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;-webkit-resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;horizontal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;-moz-resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;horizontal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;-o-resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;horizontal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;-ms-resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;horizontal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;horizontal&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;ul&gt;
  &lt;li&gt;12-2 CSS3外轮廓属性
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;外轮廓outline&lt;/code&gt;在页面中呈现的效果和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;边框border&lt;/code&gt;呈现的效果机器相似，但和元素边框不同的是，外轮廓不沾永网页布局空间,不一定是举行，外轮廓属于动态样式，只有元素货渠道焦点或被激活时呈现.&lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;outline: [outline-color] || [outline-style] || [outline-width] || [outline-offset] || inherit;&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;outline属性和border类似&lt;/li&gt;
          &lt;li&gt;outline-offset: 定义轮廓边框的偏移位置的数值，此值可以取负数值。当此参数的值为正数值，表示轮廓边框向外偏离多少个像素；当此参数的值为负数值，表示轮廓边框向内偏移多少个像素。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;12-3 CSS 生成内容: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Function:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content&lt;/code&gt;通过结合&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::before&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;::after&lt;/code&gt;来实现&lt;/li&gt;
          &lt;li&gt;对input和img不起作用&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Syntax:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content: none;&lt;/code&gt; : 不生成任何内容&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content: attr(...);&lt;/code&gt;: 插入标签属性值&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content: URL;&lt;/code&gt;: 使用指定的绝对或相对地址插入一个外部资源(图像、声频、视频或浏览器支持的任何资源)&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;content: STRING;&lt;/code&gt;: 插入字符串&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/* 这里的title是该标签的属性值，不是title标签*/
/* attr(data-*)这样用法比较好 */
a::after {
    content: attr(title);
    color: #f00;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;12-4 制作3D旋转视频&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/06/01/css3-getting-started.html</link>
    <guid>/2015/06/01/css3-getting-started</guid>
    <pubDate>Mon, 01 Jun 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>重新捡起 virtualenv and virtualenvwrapper</title>
    <description>
&lt;h2 id=&quot;官方文档&quot;&gt;官方文档&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://virtualenv.pypa.io/en/latest/&quot;&gt;virtualenv&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://virtualenvwrapper.readthedocs.org/en/latest/&quot;&gt;virtualenvwrapper&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;一-virtualenv&quot;&gt;一 virtualenv&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;What&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;virtualenv 是一个隔离Python环境的工具.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Why&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;virtualenv 可以让你在同一个操作系统上建立多个不同的Python环境.&lt;/li&gt;
      &lt;li&gt;如一个Python2, 另一个Python3,　还有Django1.2 和 Django1.5&lt;/li&gt;
      &lt;li&gt;项目Python环境互不相同，互不干涉.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;How&lt;/code&gt;: (So Easy)
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Install&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;sudo pip install virtualenv&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Use&lt;/code&gt;: (Recommend)
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;virtualenv -p PYTHON_VERSION VIRTUAL_ENVIRONMENT_NAME&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;解释:
                &lt;ul&gt;
                  &lt;li&gt;-p PYTHON_EXE, –python=PYTHON_EXE : 指定Python版本, Python2, Python2.5, Python3等&lt;/li&gt;
                  &lt;li&gt;注意: 这个Python版本必须存在于系统内部&lt;/li&gt;
                  &lt;li&gt;–no-site-packages : 废弃了，因为默认没有权限访问全局包&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;栗子:
                &lt;ul&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;virtualenv -p python3 django1.8&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;进入环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;source path/to/VIRTUAL_ENVIRONMENT_NAME/bin/activate&lt;/li&gt;
              &lt;li&gt;栗子:
                &lt;ul&gt;
                  &lt;li&gt;source django1.8/bin/activate&lt;/li&gt;
                  &lt;li&gt;或者 cd django1.8; source bin/activate&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;有明显标志(VIRTUAL_ENVIRONMENT_NAME)，说明成功进入环境&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;退出环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;deactivate&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;只要删除创建的虚拟环境目录即可: rm -rf path/to/VIRTUAL_ENVIRONMENT_NAME
                &lt;ul&gt;
                  &lt;li&gt;rm -rf django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;二-virtualenvwrapper&quot;&gt;二 virtualenvwrapper&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;what&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;virtualenvwrapper 是 virtaulenv 的扩展的集合.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Why&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;便于使用和管理 virtualenv&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;How&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Install&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;sudo pip install virtualenvwrapper&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Use&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;每次使用前必须先source环境&lt;/code&gt;: 才有mkvirtualev, lssitepackages等命令
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;source /usr/local/bin/virtualenvwrapper.sh&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;或者将/etc/profile 或者 ~/.bashrc 或者 ~/.zshrc&lt;/code&gt; 启动终端时自动载入source&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] VIRTUAL_ENVIRONMENT_NAME&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 项目默认创建一律在 ~/.virtualenvs 目录下&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;栗子:&lt;/li&gt;
              &lt;li&gt;默认:
                &lt;ul&gt;
                  &lt;li&gt;mkvirtualenv django1.8 # (ls ~/.virtualenvs 可见)&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;指定Python版本:
                &lt;ul&gt;
                  &lt;li&gt;mkvirtualenv -p python3 django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;指定Python版本和依赖的包:
                &lt;ul&gt;
                  &lt;li&gt;mkvirtualenv -r requirements.txt -p python3 django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;指定项目地址, 只要载入环境，自动切换到项目目录:
                &lt;ul&gt;
                  &lt;li&gt;mkvirtualenv -a . django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 环境创建完成后，会自动载入环境&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;打开或切换工作环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;workon [(-c|--cd)|(-n|--no-cd)] [environment_name|&quot;.&quot;]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;栗子:&lt;/li&gt;
              &lt;li&gt;默认:
                &lt;ul&gt;
                  &lt;li&gt;workon django1.8&lt;/li&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 默认进入 mkvirtualenv 选项 -a 指定的目录，如果没有，则在当前目录&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;切换, 即已经在一个虚拟环境, 但要切换另一个环境:
                &lt;ul&gt;
                  &lt;li&gt;workon django1.5&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;不进入 -a 指定的目录:
                &lt;ul&gt;
                  &lt;li&gt;workon -n django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;退出环境，使用系统环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;deactivate&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;rmvirtualenv VIRTUAL_ENVIRONMENT_NAME&lt;/li&gt;
              &lt;li&gt;或 rm -rf ~/.virtualenvs/VIRTUAL_ENVIRONMENT_NAME&lt;/li&gt;
              &lt;li&gt;栗子:
                &lt;ul&gt;
                  &lt;li&gt;rmvirtualenv django1.8 (推荐)&lt;/li&gt;
                  &lt;li&gt;rm -rf ~/.virtualenvs/django1.8&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;让所有创建的环境都执行某个命令,比如安装某个包等&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;allvirtualenv command with arguments&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;栗子:
                &lt;ul&gt;
                  &lt;li&gt;allvirtualenv pip install ipython&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;切换当前环境能否访问系统的Python包, 建议关闭(disable)&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggleglobalsitepackages [-p]&lt;/code&gt;
                &lt;ul&gt;
                  &lt;li&gt;-p : 不输出日志&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;栗子:
                &lt;ul&gt;
                  &lt;li&gt;toggleglobalsitepackages&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除第三方包&lt;/code&gt;: (注意: 必须已经在虚拟环境中)
            &lt;ul&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wipeenv&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;创建项目+环境&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;Create a new virtualenv in the WORKON_HOME and project directory in PROJECT_HOME.&lt;/li&gt;
              &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mkproject [-f|--force] [-t template] [virtualenv_options] ENVNAME&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意设置 WORKON_HOME 和 PROJECT_HOME&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;其他命令:
            &lt;ul&gt;
              &lt;li&gt;显示安装的包: lssitepackages (建议用 pip list 更清楚)&lt;/li&gt;
              &lt;li&gt;复制一份虚拟环境: cpvirtualenv [sorce] [dest]
                &lt;ul&gt;
                  &lt;li&gt;cp django1.8 django&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;临时环境，deactivate后删除:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;table&gt;
                      &lt;tbody&gt;
                        &lt;tr&gt;
                          &lt;td&gt;mktmpenv [(-c&lt;/td&gt;
                          &lt;td&gt;–cd)&lt;/td&gt;
                          &lt;td&gt;(-n&lt;/td&gt;
                          &lt;td&gt;–no-cd)] [VIRTUALENV_OPTIONS]&lt;/td&gt;
                        &lt;/tr&gt;
                      &lt;/tbody&gt;
                    &lt;/table&gt;
                  &lt;/li&gt;
                  &lt;li&gt;栗子: mktmpenv -p python3&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;列出所有创建的虚拟环境: 即~/.virtualenvs目录下的
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;table&gt;
                      &lt;tbody&gt;
                        &lt;tr&gt;
                          &lt;td&gt;lsvirtualenv [-b&lt;/td&gt;
                          &lt;td&gt;-l&lt;/td&gt;
                          &lt;td&gt;-h]&lt;/td&gt;
                        &lt;/tr&gt;
                      &lt;/tbody&gt;
                    &lt;/table&gt;
                    &lt;ul&gt;
                      &lt;li&gt;-b 简短形式, 建议&lt;/li&gt;
                      &lt;li&gt;-l 默认的详细信息输出&lt;/li&gt;
                      &lt;li&gt;-h help&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;绑定项目目录&lt;/code&gt;:
                &lt;ul&gt;
                  &lt;li&gt;Syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setvirtualenvproject [virtualenv_path project_path]&lt;/code&gt;&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/05/19/revise-virtualenv-and-virtualenvwrapper.html</link>
    <guid>/2015/05/19/revise-virtualenv-and-virtualenvwrapper</guid>
    <pubDate>Tue, 19 May 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>linux web nginx practice</title>
    <description>
&lt;h2 id=&quot;一参考&quot;&gt;一、参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.shiyanlou.com/courses/95&quot;&gt;实验室&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://nginx.org/&quot;&gt;官网&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;二安装-nginx-ubuntu&quot;&gt;二、安装 nginx (ubuntu)&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;方法一: sudo apt-get install nginx&lt;/li&gt;
  &lt;li&gt;方法二: &lt;a href=&quot;/scripts/install_nginx.sh&quot;&gt;脚本&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;以下配置根据方法一&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;三nginx实践-lnmp&quot;&gt;三、NGINX实践: LNMP&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;nginx
        &lt;ul&gt;
          &lt;li&gt;安装: sudo apt-get install nginx&lt;/li&gt;
          &lt;li&gt;启动: sudo service nginx start 或 sudo /etc/init.d/nginx start&lt;/li&gt;
          &lt;li&gt;停止: sudo service nginx stop&lt;/li&gt;
          &lt;li&gt;重载配置: sudo service nginx reload&lt;/li&gt;
          &lt;li&gt;重启: sudo service nginx restart&lt;/li&gt;
          &lt;li&gt;检测配置是否正确: sudo nginx -t&lt;/li&gt;
          &lt;li&gt;配置文件: /etc/nginx/conf/nginx.conf&lt;/li&gt;
          &lt;li&gt;默认server: /etc/nginx/sites-available/default&lt;/li&gt;
          &lt;li&gt;浏览器访问: http://127.0.0.1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;mysql
        &lt;ul&gt;
          &lt;li&gt;安装: sudo apt-get install mysql-server mysql-client&lt;/li&gt;
          &lt;li&gt;配置文件: /etc/mysql/my.cnf&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 配置文件将bind-address = 127.0.0.1 注释掉，就可以远程连接数据库了&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;启动/停止/重新启动: sudo service mysql start/stop/restart&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;php5
        &lt;ul&gt;
          &lt;li&gt;在LNMP中的作用或角色:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;nginx 本身不能处理PHP, 他只是个web服务器, 当接收到请求后,&lt;/li&gt;
          &lt;li&gt;如果是php请求, 则发个php解释器处理，并把结果返回给客户端.&lt;/li&gt;
          &lt;li&gt;php-fpm 是一个守护进程(FastCGI进程管理器)用于替换PHP FastCGI的&lt;/li&gt;
          &lt;li&gt;大部分附加功能, 对于高负载网站是非常有用的
    * 安装: sudo apt-get install php5-fpm
    * 开启NGINX的PHP配置(下图)
    * 测试NGINX配置是否正确:&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ nginx -t&lt;/code&gt;
    * 修改php-fpm监听配置(下图)
    * 重启php-fpm服务:&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ service php-fpm restart&lt;/code&gt;
    * 安装好后连同上面的nginx一同测试:&lt;/li&gt;
          &lt;li&gt;现在创建一个探针文件保存在 /usr/share/nginx/html 目录下&lt;/li&gt;
          &lt;li&gt;(这个目录是nginx配置文件中的root目录).&lt;/li&gt;
          &lt;li&gt;新php文件: sudo vim /usr/share/nginx/html/phpinfo.php&lt;/li&gt;
          &lt;li&gt;添加代码: &amp;lt;? php phpinfo();
    * 启动php5-fpm服务: sudo service php5-fpm start
    * 访问浏览器: http://127.0.0.1/phpinfo.php&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;

    &lt;ul&gt;
      &lt;li&gt;ISSUE:
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Page Error: file not found&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;Solved:
            &lt;ul&gt;
              &lt;li&gt;修改nginx.conf&lt;/li&gt;
              &lt;li&gt;修改 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;其中 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/nginx/html&lt;/code&gt; 为 nginx 的 html 目录, @TODO 似乎必须是绝对路径&lt;/li&gt;
              &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/17808787/file-not-found-when-running-php-with-nginx&quot;&gt;Stack Overflow 相关问题&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# 开启NGINX的PHP配置
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

# 修改php-fpm的监听端口，使适应NGINX的PHP配置
# vim /etc/php5/fpm/pool.d/www.conf
# 修改
; listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;组合配置, 互相支持:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;让php5支持mysql:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;安装: sudo apt-get install php5-mysql&lt;/li&gt;
          &lt;li&gt;重启php: sudo service php5-fpm restart&lt;/li&gt;
          &lt;li&gt;访问浏览器: http://127.0.0.1/phpinfo.php
    * 2. 让php使用tcp连接:&lt;/li&gt;
          &lt;li&gt;只需要将nginx的default配置(所在目录/etc/nginx/sites-available/)&lt;/li&gt;
          &lt;li&gt;配置中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;端口&lt;/code&gt;改回来，然后再将php配置文件www.conf&lt;/li&gt;
          &lt;li&gt;(所在目录/etc/php5/fpm/pool.d/) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;端口&lt;/code&gt; 也该文与nginx的default端口中相同就行.&lt;/li&gt;
          &lt;li&gt;相关语句:
            &lt;ul&gt;
              &lt;li&gt;(nginx -* default) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fastcgi_pass 127.0.0.1:9000&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;(php5-fpm -* www.conf) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;listen = 127.0.0.1:9000&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;测试配置文件:
            &lt;ul&gt;
              &lt;li&gt;sudo service nginx start&lt;/li&gt;
              &lt;li&gt;sudo service php5-fpm start&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;重载配置-&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: 配置文件只有重载才生效&lt;/code&gt;
            &lt;ul&gt;
              &lt;li&gt;sudo service nginx reload&lt;/li&gt;
              &lt;li&gt;sudo service php5-fpm reload&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;重启服务:
            &lt;ul&gt;
              &lt;li&gt;sudo service nginx restart&lt;/li&gt;
              &lt;li&gt;sudo service php5-fpm restart&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;四nginx-http-模块&quot;&gt;四、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NGINX HTTP 模块&lt;/code&gt;&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;1 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http index 模块&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index file1 file2 ...&lt;/code&gt;;&lt;/li&gt;
      &lt;li&gt;作用域: http, server, location&lt;/li&gt;
      &lt;li&gt;模块功能及注意:
        &lt;ul&gt;
          &lt;li&gt;功能: 定义将要被作为默认页的文件&lt;/li&gt;
          &lt;li&gt;注意: 文件的名字可以包含变量. 文件以配置中指定的顺序被nginx检测.
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;列表的最好一个元素可以是一个带有绝对路径的文件&lt;/code&gt;.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;例子: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index index.$geo.html index.0.html /index.html&lt;/code&gt;:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;需要注意的是，index文件会引发内部重定向，请求可能会被其他location处理, 如下例2&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;模块: ngx_http_index_module 配置范例:例1&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例1
location / &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    index index.&lt;span class=&quot;nv&quot;&gt;$geo&lt;/span&gt;.html index.html
&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-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例2
location &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; / &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    index index.html&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

location / &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    ....
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
// 请求&lt;span class=&quot;s2&quot;&gt;&quot;/&quot;&lt;/span&gt;实际上将会在第二个location中作为&lt;span class=&quot;s2&quot;&gt;&quot;/index.html&quot;&lt;/span&gt;被处理
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;2 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http log 模块&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;模块: ngx_http_log_module 配置范例: 例3&lt;/li&gt;
      &lt;li&gt;指令:
        &lt;ul&gt;
          &lt;li&gt;access_log :
            &lt;ul&gt;
              &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;access_log path [format [buffer=size | off]]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;默认值: access_log log/access.log combined&lt;/li&gt;
              &lt;li&gt;作用域: http, server, location&lt;/li&gt;
              &lt;li&gt;模块功能及注意:
                &lt;ul&gt;
                  &lt;li&gt;指令access_log指派路径、格式和缓存大小&lt;/li&gt;
                  &lt;li&gt;参数”off”将清除当前几倍的所有access_log指令。&lt;/li&gt;
                  &lt;li&gt;如果未指定格式，则使用预置的”combined”格式.&lt;/li&gt;
                  &lt;li&gt;缓存不能大于能写入磁盘的文件的最大值。在FreeBSD3.0-6.0, 缓存大小无限制.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;log_format :
            &lt;ul&gt;
              &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log_format name format [format ...]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;默认值: log_format combined “…”&lt;/li&gt;
              &lt;li&gt;作用域: http, server&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例3
log_format &lt;span class=&quot;nb&quot;&gt;gzip&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;$remote_addr-$remote_user[$time_local]&apos;&lt;/span&gt;
:&lt;span class=&quot;s1&quot;&gt;&apos;$request$status $bytes_sent&apos;&lt;/span&gt;
:&lt;span class=&quot;s1&quot;&gt;&apos;&quot;$ http _ referer&quot; &quot;$http_user_agent&quot; &quot;$gzip_ratio&quot;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
access_log /spool/logs/nginx-access.log &lt;span class=&quot;nb&quot;&gt;gzip &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;32k&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;3 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Access模块&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;模块: ngx_http_access_module 功能描述:
            &lt;ul&gt;
              &lt;li&gt;此模块提供简易的基于主机的访问控制.&lt;/li&gt;
              &lt;li&gt;ngx_http_access_module 模块使有可能对特定的IP客户端进行控制.&lt;/li&gt;
              &lt;li&gt;规则检查第一次匹配的顺序，此模块对网络地址有放行和禁止的权利.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;Access 配置范例: 例4&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;放行: allow
            &lt;ul&gt;
              &lt;li&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;语法: allow [address&lt;/td&gt;
                      &lt;td&gt;CIDR&lt;/td&gt;
                      &lt;td&gt;all]&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/li&gt;
              &lt;li&gt;作用域: http, server, location, limit_except&lt;/li&gt;
              &lt;li&gt;功能: 网络地址有直接访问权限.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;禁止: deny
            &lt;ul&gt;
              &lt;li&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;语法: deny [address&lt;/td&gt;
                      &lt;td&gt;CIDR&lt;/td&gt;
                      &lt;td&gt;all]&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/li&gt;
              &lt;li&gt;作用域: http, server, location, limit_except&lt;/li&gt;
              &lt;li&gt;功能: 网络地址拒绝访问.&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例4
location / &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    deny  192.168.1.1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    allow 192.168.1.0/24&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    allow 10.1.1.0/16&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    deny  all&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
// 在上面的例子中，仅允许网段10.1.1.0/16和192.168.1.0/24中除了192.168.1.1之外的ip访问.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;4 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Rewrite 模块&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;模块: ngx_http_rewrite_module
            &lt;ul&gt;
              &lt;li&gt;功能描述:&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;执行URL重定向, 允许你去掉带有恶意的URL, 包含多个参数(修改);&lt;/li&gt;
              &lt;li&gt;利用正则的匹配，分组和引用,达到目的配置范例.&lt;/li&gt;
              &lt;li&gt;该模块允许使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;正则表达式改变URL,并根据变量来转向以及选择配置&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;语法:
            &lt;ul&gt;
              &lt;li&gt;(1) if 语法&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if (condition) { ... }&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;作用域: server, location&lt;/li&gt;
              &lt;li&gt;范例: 例5
    * (2) return 语法:&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return code;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;作用域: server, location, if&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;这个指令规则的执行情况，返回一个状态值给客户端。&lt;/li&gt;
                  &lt;li&gt;可用值包括: 204, 400, 402-406, 408, 410, 411, 413, 416, 500-504.&lt;/li&gt;
                  &lt;li&gt;也可以发送非标准的444代码，未发送任何信息下结束连接.
                    &lt;ul&gt;
                      &lt;li&gt;(3) rewrite 语法:&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rewrite regex replacement flag;&lt;/code&gt;
                &lt;ul&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last&lt;/code&gt; : 表示完成&lt;/li&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rewrite break&lt;/code&gt; : 本规则匹配完成, 终止匹配，不再匹配后面的规则&lt;/li&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;redirect&lt;/code&gt; : 返回302临时重定向，地址栏会显示跳转后的地址&lt;/li&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;permanent&lt;/code&gt; : 返回301永久重定向，地址栏会显示跳转后的地址.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;作用域: server, location, if&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;根据正则表达式或者替换字符来更改URL.&lt;/li&gt;
                  &lt;li&gt;指令根据配置文件中的先后顺序执行生效&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例5
&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;nv&quot;&gt;$http_user_agent&lt;/span&gt; ~ MSIE&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    rewrite ^&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;.&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;/msie/&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;break&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;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$http_cookie&lt;/span&gt; ~&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;id=([^;]+)(?:;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&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;nb&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$id&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&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;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$request_method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; POST&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;405&lt;span class=&quot;p&quot;&gt;;&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;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$request_filename&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;nb&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    proxy_pass http://127.0.0.1&lt;span class=&quot;p&quot;&gt;;&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;nv&quot;&gt;$slow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    limit_rate 10k&lt;span class=&quot;p&quot;&gt;;&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;nv&quot;&gt;$invalid_referer&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;403&lt;span class=&quot;p&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;ul&gt;
  &lt;li&gt;5 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Proxy模块&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;模块: ngx_http_proxy_module&lt;/li&gt;
      &lt;li&gt;功能描述:
        &lt;ul&gt;
          &lt;li&gt;此模块能代理请求到其他服务器&lt;/li&gt;
          &lt;li&gt;也就是说允许你把客户端请求转到后端服务器&lt;/li&gt;
          &lt;li&gt;(这部分指令非常多，但不是全部都被用到)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;指令:
        &lt;ul&gt;
          &lt;li&gt;(1) pass_header
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proxy_pass_header Server;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;该指令强制一些被忽略的头传递到客户端.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;(2) redirect
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proxy_redirect off;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;允许改写出现在HTTP头却被后端服务器触发重定向的URL.&lt;/li&gt;
                  &lt;li&gt;对响应本身不做任何处理.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;(3) set_header
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proxy_set_header Host $http_host;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;允许你重新定义代理header值再转到后端服务器&lt;/li&gt;
                  &lt;li&gt;目标服务器可以看到客户端的原始主机名.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;(4) set_header
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proxy_set_header X-Real-IP $remote_addr;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;功能描述:
                &lt;ul&gt;
                  &lt;li&gt;目标服务器可以看到客户端的真实ip, 而不是转发服务器的ip.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;(5) &lt;a href=&quot;http://nginx.org/en/docs/http/ngx_http_proxy_module.html&quot;&gt;更多proxy指令&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;upstream 模块&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;模块: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ngx_http_upstream_module&lt;/code&gt;&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;功能简介:
            &lt;ul&gt;
              &lt;li&gt;该指令使请求被上行信道之间的基于客户端的IP地址分布.&lt;/li&gt;
              &lt;li&gt;范例: 例6&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;指令:
            &lt;ul&gt;
              &lt;li&gt;(1) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip_hash&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip_hash;&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;作用域: upstream&lt;/li&gt;
              &lt;li&gt;指令功能及注意:
                &lt;ul&gt;
                  &lt;li&gt;指定服务器租的负载均衡方法，请求基于客户端的IP地址在服务器间进行分发。&lt;/li&gt;
                  &lt;li&gt;IPv4地址的前三个字节或者IPv6的整个地址，会被用来作为一个散列key.&lt;/li&gt;
                  &lt;li&gt;这种方法可以确保从同一个客户端过来的请求，会窗格同一台服务器.&lt;/li&gt;
                  &lt;li&gt;除了当服务器被认为不可用的时候，这些客户端的请求会被传给其他服务器，而且很有可能也是同一台服务器.&lt;/li&gt;
                  &lt;li&gt;如果其中一个服务器想暂时移除，应该加上down参数.这样可以保留当前客户端IP地址散列分布. 如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;例6.1&lt;/code&gt;
                    &lt;ul&gt;
                      &lt;li&gt;(2) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server&lt;/code&gt;&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;server address [parameters];&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;作用域: upstream&lt;/li&gt;
              &lt;li&gt;指令功能及注意:
                &lt;ul&gt;
                  &lt;li&gt;定义服务器的地址address和其他参数parameters.&lt;/li&gt;
                  &lt;li&gt;地址可以是域名或者IP地址，端口是可选的，或者是指定”unix:”前缀的UNIX域套接字的路径.&lt;/li&gt;
                  &lt;li&gt;如果没有指定端口，就使用80端口.&lt;/li&gt;
                  &lt;li&gt;如果一个域名解析到多个IP, 本质上是定义了多个server.&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;配置范例: 例6.2
    * (3) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;upstream&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;语法: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;upstream name { ... }&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;作用域: http&lt;/li&gt;
              &lt;li&gt;指令功能及注意:
                &lt;ul&gt;
                  &lt;li&gt;功能: 描述一个服务器的集合，该集合可被用于proxy_pass和fastcgi_pass指令中, 作为一个单独的实体.&lt;/li&gt;
                  &lt;li&gt;这些服务器可以是监听在不同的端口，另外，并发使用同时监听TCP端口和Unix套接字的服务器是可能的。&lt;/li&gt;
                  &lt;li&gt;这些服务器能被分配不同的权重(weight).weight默认为1.&lt;/li&gt;
                  &lt;li&gt;配置范例: 例6.3&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例6
upstream backend &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    server backend1.example.com &lt;span class=&quot;nv&quot;&gt;weight&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server backend2.example.com:8000&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server unix:/tmp/backend3&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

server &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    location / &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        proxy_pass http://backend&lt;span class=&quot;p&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-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例6.1
upstream backend &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    ip_hash&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server backend1.example.com&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server backend2.example.com&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server backend3.example.com down&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server backend4.example.com&lt;span class=&quot;p&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-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例6.2
upstream backend &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    server backend1.example.com &lt;span class=&quot;nv&quot;&gt;weight&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server 127.0.0.1:8080       &lt;span class=&quot;nv&quot;&gt;max_fails&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3 &lt;span class=&quot;nv&quot;&gt;fail_timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;30s
    server unix:/tmp/backend3&lt;span class=&quot;p&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-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 例6.3
upstream backend &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    server backend1.example.com &lt;span class=&quot;nv&quot;&gt;weight&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;5&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server 127.0.0.1:8080       &lt;span class=&quot;nv&quot;&gt;max_fails&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3 &lt;span class=&quot;nv&quot;&gt;fail_timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;30s&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    server unix:/tmp/backend3&lt;span class=&quot;p&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;ul&gt;
  &lt;li&gt;7 &lt;a href=&quot;http://wiki.nginx.org/Modules&quot;&gt;NGINX全部模块&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;五nginx模块开发实验&quot;&gt;五、Nginx模块开发实验&lt;/h2&gt;
</description>
    <link>/2015/05/03/linux-web-nginx-practice.html</link>
    <guid>/2015/05/03/linux-web-nginx-practice</guid>
    <pubDate>Sun, 03 May 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>docker 问题汇总(持续更新)</title>
    <description>
&lt;h2 id=&quot;1-非root身份运行docker&quot;&gt;1. 非root身份运行Docker&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;你需要将自己添加到docker群组，那样才能以非root用户的身份来运行Docker&lt;/li&gt;
  &lt;li&gt;解决方法:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;将当前用户加入docker组: sudo usermod -a -G docker $USER&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;创建个新docker组用户: sudo useradd –create-home –shell /bin/bash –user-group –groups docker,adm,sudo YOUR_USER_NAME&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/28/docker-problems-set.html</link>
    <guid>/2015/04/28/docker-problems-set</guid>
    <pubDate>Tue, 28 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>docker getting started</title>
    <description>
&lt;h2 id=&quot;参考&quot;&gt;参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://yeasy.gitbooks.io/docker_practice/content/&quot;&gt;Docker —— 从入门到实践&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://letong.gitbooks.io/docker/content/#&quot;&gt;Docker中文教程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://richardhc.gitbooks.io/chinese_docker/content/&quot;&gt;Docker中文指南&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/userguide/&quot;&gt;官方 UserGuide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h2&gt;

&lt;h3 id=&quot;一-ubuntu-安装-docker&quot;&gt;一 Ubuntu 安装 Docker&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://letong.gitbooks.io/docker/content/install/ubuntu.html&quot;&gt;方法一&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.docker.com/installation/ubuntulinux/&quot;&gt;方法二&lt;/a&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;推荐&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wget -qO- https://get.docker.com/ | sh&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;二-命令集合&quot;&gt;二 &lt;a href=&quot;http://yeasy.gitbooks.io/docker_practice/content/appendix_command/README.html&quot;&gt;命令集合&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;常用命令: docker –help
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker pull [OPTIONS] IMAGENAME[:TAG|@DIGEST] # 拉取名叫IMAGENAME的镜像
            &lt;ul&gt;
              &lt;li&gt;sudo docker pull ubuntu:14.04 # &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt;后面的是标记&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker run [OPTIONS] IMAGE [COMMAND] [ARG…] # 运行镜像，创建容器(容器是镜像的实例)
            &lt;ul&gt;
              &lt;li&gt;sudo docker run -i -t ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker images [OPTIONS] : 查看镜像
            &lt;ul&gt;
              &lt;li&gt;sudo docker images -a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;查看所有镜像&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker ps [OPTIONS]: 查看容器状态
            &lt;ul&gt;
              &lt;li&gt;sudo docker ps&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker build [OPTIONS] PATH|URL|- # 用Dockerfile创建自己的镜像
            &lt;ul&gt;
              &lt;li&gt;sudo docker build -t diyImageName –no-cache –rm=true . # (.是Dockerfile所在的路径)&lt;/li&gt;
              &lt;li&gt;sudo docker build -t diyImageName –no-cache –rm=true - &amp;lt; /path/to/Dockerfile&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker login # 登陆远程服务器&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker push [OPTIONS] NAME[:TAG] # 推送镜像到远程
            &lt;ul&gt;
              &lt;li&gt;sudo docker push whatwewant/ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker save [OPTIONS] IMAGE [IMAGE…] # 保存镜像到本地
            &lt;ul&gt;
              &lt;li&gt;sudo docker save -o ubuntu.tar ubuntu:14.04&lt;/li&gt;
              &lt;li&gt;(如果没指定TAG, 这里是14.04, 则默认是lastest)&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker load [OPTIONS] # 导入本地镜像
            &lt;ul&gt;
              &lt;li&gt;sudo docker load –input=ubuntu.tar&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;容器操作:
            &lt;ul&gt;
              &lt;li&gt;docker start [OPTIONS] CONTAINER [CONTAINER…]&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;sudo docker start 4e817cb70b48&lt;/li&gt;
              &lt;li&gt;sudo docker start containerName&lt;/li&gt;
              &lt;li&gt;(docker run 用 –name=containerName 指定容器名字，　默认无名字)
      * docker stop [OPTIONS] CONTAINER [CONTAINER…]
      * docker restart [OPTIONS] CONTAINER [CONTAINER…]&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker rm [OPTIONS] CONTAINER [CONTAINER2 …]
            &lt;ul&gt;
              &lt;li&gt;删除容器: sudo docker rm web&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker rmi [OPTIONS] IMAGE [IMAGE2 …]
            &lt;ul&gt;
              &lt;li&gt;删除镜像: sudo docker rmi -f ubuntu&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除所有本地镜像: sudo docker rmi -f $(docker ps -aq)&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
            &lt;ul&gt;
              &lt;li&gt;提交改动，类似git commit&lt;/li&gt;
              &lt;li&gt;因为容器是只读的，所以不提交改动，一旦容器关闭，配置便失效了&lt;/li&gt;
              &lt;li&gt;所以，建议写Dockerfile&lt;/li&gt;
              &lt;li&gt;Ex: sudo docker -a cole -m “Comments: Where or what change ..” web&lt;/li&gt;
              &lt;li&gt;Ex: sudo docker -a cole -m “Comments: Where or what change ..” d10c3120b4d7&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER:IMAGE…]
            &lt;ul&gt;
              &lt;li&gt;查看容器或镜像的详细信息&lt;/li&gt;
              &lt;li&gt;Ex: sudo docker inspect ubuntu:14.04&lt;/li&gt;
              &lt;li&gt;Ex: sudo docker inspect -f  ubuntu:14.04&lt;/li&gt;
              &lt;li&gt;Ex: sudo docker inspect -f  ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;docker import
            &lt;ul&gt;
              &lt;li&gt;Ex: docker import http://docker.widuu.com/ubuntu.tar&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;常用选项: 这里针对 docker run
    &lt;ul&gt;
      &lt;li&gt;-p, –publish=[] : 指定端口映射, 可多次使用
        &lt;ul&gt;
          &lt;li&gt;docker run -p [HOST_IP:]HOST_PORT:CONTAINER_PORT …
            &lt;ul&gt;
              &lt;li&gt;sudo docker run -p 8080:80 -d ubuntu:14.04&lt;/li&gt;
              &lt;li&gt;sudo docker run -p 8080:80 -p 127.0.0.1:2022:22 -d ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;-P, –publish-all: 所有为所有EXPOSE的端口随机映射
        &lt;ul&gt;
          &lt;li&gt;EXPOSE 一般在Dockerfile中指定&lt;/li&gt;
          &lt;li&gt;EXPOSE 80, 22&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;-i, –interactive: 用户交互，建议和-t一起使用，效果更棒
        &lt;ul&gt;
          &lt;li&gt;sudo docker run -i -t ubuntu:14.04&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;-t, –tty : tty方式，伪终端:
        &lt;ul&gt;
          &lt;li&gt;sudo docker run -i -t ubuntu:14.04&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;-d, –detach: 以Daemon方式运行Container
        &lt;ul&gt;
          &lt;li&gt;sudo docker run -d ubuntu:14.04&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;-v, –volume=[]: 将本地数据(文件夹等)挂载到Container
        &lt;ul&gt;
          &lt;li&gt;docker run -v /hostAsbpathSrc:/containerAbspathSrc …
            &lt;ul&gt;
              &lt;li&gt;sudo docker run -i -t -v /home/ubuntu/data:/data ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;-u, –user= :  Username or UID (format: &amp;lt;name&lt;/td&gt;
              &lt;td&gt;uid&amp;gt;[:&amp;lt;group&lt;/td&gt;
              &lt;td&gt;gid&amp;gt;])&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;-w, –workdir= : 指定工作路径, 如果不存在会自动创建
        &lt;ul&gt;
          &lt;li&gt;sudo docker run -i -t -w /home/xxx/workdir ubuntu:14.04&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;–name= : 给容器命名, 好处多多的, 代替容器ID
        &lt;ul&gt;
          &lt;li&gt;sudo docker run –name work -it ubuntu:14.04&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;三-docker-命令实习&quot;&gt;三 Docker 命令实习:&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1. 拉取或创建镜像&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;拉取: sudo docker pull ubuntu:14.04&lt;/li&gt;
      &lt;li&gt;创建: sudo docker build -t “whatwewant/ubuntu:14.04” –no-cache –rm=true - &amp;lt; Dockerfile # 请确保Dockerfile存在
        &lt;ul&gt;
          &lt;li&gt;注意: 这里: -t == –tag, 最好指定, 这里不仅仅是标签，更重要的是镜像名字(Repository)，属于自己的，而不是官方的&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2. 运行镜像IMAGE，即新建容器CONTAINER&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;伪终端交互: sudo docker run –name web -i -t -P ubuntu:14.04&lt;/li&gt;
      &lt;li&gt;Daemon方式: sudo docker run -d -P ubuntu:14.04&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3. 提交改动&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;sudo docker commit -a cole -m “Comments” d10c3120b4d7&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4. 推送到远程服务器&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;sudo docker push whatwewant/ubuntu:14.04&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5. 删除容器&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;sudo docker rm d10c3120b4d7&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;6. 删除镜像&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;sudo docker rmi whatwewant/ubuntu:14.04&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除所有镜像: sudo docker rmi -f $(sudo docker ps -aq)&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;7. 结束容器&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;容器ID: sudo docker kill d10c3120b4d7&lt;/li&gt;
      &lt;li&gt;容器名字: sudo docker kill web&lt;/li&gt;
      &lt;li&gt;伪终端结束: exit 或 C-d(Ctrl+d)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8. 查看容器或镜像详细信息&lt;/code&gt;: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;容器是镜像的实例&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;sudo docker inspect d10c3&lt;/li&gt;
      &lt;li&gt;sudo docker inspect ubuntu:14.04&lt;/li&gt;
      &lt;li&gt;查看个别属性，因为输出是json&lt;/li&gt;
      &lt;li&gt;Ex: sudo docker inspect -f  ubuntu:14.04&lt;/li&gt;
      &lt;li&gt;Ex: sudo docker inspect -f  ubuntu:14.04&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;四-dockerfile-的编写自定义镜像&quot;&gt;四 Dockerfile 的编写，自定义镜像&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;常用指令: 每个命令在原基础上新建一个容器, 表现为容器ID
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;FROM
            &lt;ul&gt;
              &lt;li&gt;格式: FROM &lt;image&gt;:&lt;tag&gt;&lt;/tag&gt;&lt;/image&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;第一条指令必须为FROM指令。如果在同一个Dockerfile中创建多个镜像时，可以使用多个FROM指令。
    * 例子: FROM ubuntu:14.04&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;MAINTAINER :
            &lt;ul&gt;
              &lt;li&gt;格式: MAINTAINER &lt;name&gt; &lt;e-mail&gt;&lt;/e-mail&gt;&lt;/name&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;指定维护信息
    * 例子: MAINTAINER Cole Smith &lt;a href=&quot;mailto:whatwewant@gmail.com&quot;&gt;whatwewant@gmail.com&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;RUN :
            &lt;ul&gt;
              &lt;li&gt;格式: RUN &lt;command /&gt; 或 RUN [“executable”, “param1”, “param2”]&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;执行系统命令&lt;/li&gt;
              &lt;li&gt;例子: RUN apt-get install -qqy nginx&lt;/li&gt;
              &lt;li&gt;例子: RUN [“mkdir”, “-p”, “/data/v1”]&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;CMD :
            &lt;ul&gt;
              &lt;li&gt;格式: CMD [“excutable”, “param1”, “param2”]&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;使用exec执行, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;一个Dockerfile只能执行一条CMD, 以最后一条为准&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;Ex(表示例子): CMD [“/usr/sbin/sshd”, “-D”]&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;EXPOSE :
            &lt;ul&gt;
              &lt;li&gt;格式: EXPOSE &lt;port&gt;&lt;/port&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;容器暴露端口，一般和docker run -P结合，自动端口映射&lt;/li&gt;
              &lt;li&gt;可以有多条EXPOSE语句&lt;/li&gt;
              &lt;li&gt;Ex: EXPOSE 80&lt;/li&gt;
              &lt;li&gt;Ex: EXPOSE 80 22&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;ENV :
            &lt;ul&gt;
              &lt;li&gt;格式: ENV &lt;keyy&gt; &lt;value&gt;&lt;/value&gt;&lt;/keyy&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;指定一个环境变量。
                &lt;ul&gt;
                  &lt;li&gt;Ex: ENV PYTHON python3&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;ADD :
            &lt;ul&gt;
              &lt;li&gt;格式: ADD &lt;src&gt; &lt;dest&gt;&lt;/dest&gt;&lt;/src&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;复制本地或URL&lt;src&gt;到容器&lt;dest&gt;
    * Ex: ADD&lt;/dest&gt;&lt;/src&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;COPY :
            &lt;ul&gt;
              &lt;li&gt;格式: COPY &lt;src&gt; &lt;dest&gt;&lt;/dest&gt;&lt;/src&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;和ADD类似，复制功能，但是src为本地目录是推荐使用
    * Ex: COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;VOLUME :
            &lt;ul&gt;
              &lt;li&gt;格式: VOLUME []&lt;/li&gt;
              &lt;li&gt;Ex: VOLUME [“/data”]&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dockerfile 实习&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;# Comments&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 拉取镜像&lt;/span&gt;
FROM ubuntu:14.04

&lt;span class=&quot;c&quot;&gt;# 维护者信息&lt;/span&gt;
MAINTAINER Cole Smith &amp;lt;tobewhatwewant@gmail.com&amp;gt;

&lt;span class=&quot;c&quot;&gt;# 更换为163的源，国内你懂的&lt;/span&gt;
RUN &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb http://mirrors.163.com/ubuntu/ trusty main restricted universemultiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb http://mirrors.163.com/ubuntu/ trusty-security main restricte universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/apt/sources.list

&lt;span class=&quot;c&quot;&gt;# 更新源&lt;/span&gt;
RUN apt-get &lt;span class=&quot;nt&quot;&gt;-qqy&lt;/span&gt; update

&lt;span class=&quot;c&quot;&gt;# 安装软件&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 安装ssh&lt;/span&gt;
RUN apt-get &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-qqy&lt;/span&gt; openssh-server

&lt;span class=&quot;c&quot;&gt;# 安装nginx&lt;/span&gt;
RUN apt-get &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-qqy&lt;/span&gt; nginx

&lt;span class=&quot;c&quot;&gt;# 安装supervisor&lt;/span&gt;
RUN apt-get &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-qqy&lt;/span&gt; supervisor

&lt;span class=&quot;c&quot;&gt;# 复制supervisord配置&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 确保当前目录有 supervisord.conf 文件&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 配置写法，看下边&lt;/span&gt;
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

&lt;span class=&quot;c&quot;&gt;# 指定主机数据卷(文件夹等)在容器中挂载&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 和 -v HOST_DIR:CONTAINER_DIR 效果一致&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 这里，将主机的/data目录挂载到容器/data, 容器会自动创建/data&lt;/span&gt;
VOLUME &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/data&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 映射端口&lt;/span&gt;
EXPOSE 22 80

&lt;span class=&quot;c&quot;&gt;# 执行命令&lt;/span&gt;
CMD &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/usr/bin/supervisord&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# 最后，终端创建, 命令如下&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# sudo docker build -t whatwewant/ubuntu:14.04 --no-cache --rm - &amp;lt; Dockerfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;supervisor的配置文件supervisord.conf&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;supervisord]
&lt;span class=&quot;nv&quot;&gt;nodaemon&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;program:sshd]
&lt;span class=&quot;nb&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/sbin/sshd &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;program:nginx]
&lt;span class=&quot;nb&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/sbin/nginx start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;五-我的dockerfile&quot;&gt;五 &lt;a href=&quot;/confs/Dockerfile&quot;&gt;我的Dockerfile&lt;/a&gt;&lt;/h2&gt;
</description>
    <link>/2015/04/27/docker-getting-started.html</link>
    <guid>/2015/04/27/docker-getting-started</guid>
    <pubDate>Mon, 27 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>linux mysql5.5 不能显示中文问题解决办法</title>
    <description>
&lt;h2 id=&quot;问题-mysql-不能正确显示中文&quot;&gt;问题: mysql 不能正确显示中文&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;mysql5.5 默认字符集是 latin1 :
        &lt;ul&gt;
          &lt;li&gt;查看: show variables like ‘character%’;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;注意
        &lt;blockquote&gt;
          &lt;p&gt;请确保在把character_set_database 和
character_set_server的字符集改为utf8以后再写数据,
否则数据以latin1字符集存入，永远无法正确显示&lt;/p&gt;
        &lt;/blockquote&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;解决-编辑配置文件-ectmysqlmyconf&quot;&gt;解决: 编辑配置文件: /ect/mysql/my.conf&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在[client]里加入 default-character-set = utf8:&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;client]
port            &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 3306
socket          &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; /var/run/mysqld/mysqld.sock
default-character-set &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; utf8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在[mysqld]字段加入charter-set-server = utf-8&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;mysqld]
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# * Basic Settings&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
user            &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; mysql
pid-file        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; /var/run/mysqld/mysqld.pid
socket          &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; /var/run/mysqld/mysqld.sock
port            &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 3306
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在[mysql]字段加入default-character-set = utf-8&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;mysql]
no-auto-rehash
default-character-set &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; utf8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;重启mysqld : sudo service mysql restart&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;参考&quot;&gt;&lt;a href=&quot;http://www.ha97.com/5359.html&quot;&gt;参考&lt;/a&gt;&lt;/h3&gt;
</description>
    <link>/2015/04/19/linux-mysql-character-set.html</link>
    <guid>/2015/04/19/linux-mysql-character-set</guid>
    <pubDate>Sun, 19 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>gulp 入门</title>
    <description>
&lt;h2 id=&quot;参考&quot;&gt;参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.html-js.com/article/Nimojs--frontend-development-1&quot;&gt;不错的入门教程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.gulpjs.com.cn/docs/api/&quot;&gt;Gulp API 文档&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/&quot;&gt;Gulp 较完整的配置, 可以直接使用&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;一-安装-gulp&quot;&gt;一. 安装: gulp&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;(&lt;a href=&quot;http://javascript.ruanyifeng.com/nodejs/npm.html&quot;&gt;npm 模块管理器安装&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;-g 全局安装&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;nb&quot;&gt;sudo &lt;/span&gt;npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; gulp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;二-实习开始&quot;&gt;二. 实习开始&lt;/h2&gt;
&lt;div class=&quot;language-js 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;// 实验一 begin: 使用gulp入门&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 在项目根目录新建 gulpfile.js 文件&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 获取 gulp&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 获取 uglify 模块, 用于压缩JS&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 提前安装: npm install uglify&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 在项目目录下安装即可，不用全局, 会创建node_modules目录存放模块&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;uglify&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-uglify&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 压缩JS文件&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// script 是task的一个参数名, 字符串&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 执行命令: gulp script&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 1. gulp.task(name, fn) - 定义任务，第一个参数是任务名，第二个参数是任务内容&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 2. gulp.src(path) - 选择文件，传入参数是文件路径&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 3. gulp.dest(path) - 输出文件&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 4. gulp.pipe() - 管道，你可以暂时将 pipe 理解为将操作加入执行队列&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 注意: 请确保src指定的目录和文件存在，否则将不执行压缩，即使添加修改新文件&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;c1&quot;&gt;// 找到文件&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./js/*.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;uglify&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;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 实验一 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验二 创建监听器,一旦修改, 自动执行 begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 新任务: 监听改变&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 执行命令: gulp auto&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;c1&quot;&gt;// 监听文件修改，当文件修改则执行 script 任务&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;js/*.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 实验二 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验三 启用默认任务 begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// default 是默认名字&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 执行命令: gulp&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 实验三 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验四 压缩 css Begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// gulp-minify-css 模块,用于压缩 CSS&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 安装: npm install gulp-minify-css&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;minifyCSS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-minify-css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 压缩css&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 启动命令: gulp css&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./css/*.css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;minifyCSS&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 启动命令: gulp auto&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;css/*.css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 使用 gulp.task(&apos;default&apos;)定义默认任务&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 命令: gulp&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 实验四 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验五 压缩图片: begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 获取压缩图片模块: gulp-imagemin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 安装: npm install gulp-imagemin&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;imagemin&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-imagemin&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 压缩图片任务: src + 模块 + dest&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 注意: 请确保images目录及文件存在&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;images/*.*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;imagemin&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/images&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// auto watch&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;images/*.*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// default task&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 实验五 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验六 编译less begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 获取 gulp-less 模块&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 安装: npm install gulp-less&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;less&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 启动命令: gulp less&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./less/**.less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;less&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./dist/less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 启动命令: gulp auto&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;./less/**.less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;c1&quot;&gt;// 启动命令: gulp&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 实验六 end&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 实验七 用 glup 编译 Sass begin&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 用 ruby-sass 编译css&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 安装: npm install gulp-ruby-sass&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 注意: 前提得先安装 ruby 和 sass&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 可参考: https://github.com/nimojs/blog/issues/14&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 安装 ruby: sudo apt-get intsall ruby-dev&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 能翻墙直接: gem install sass&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-ruby-sass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sass/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;err&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;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Error!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&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;span class=&quot;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/css&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;c1&quot;&gt;// sass/**/*.scss 是 glob 语法, node-glob&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sass/**/*.scss&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;sass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;auto&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 实验七 end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;三-使用gulp构建项目&quot;&gt;三 &lt;a href=&quot;https://github.com/nimojs/gulp-book/blob/master/chapter7.md&quot;&gt;使用gulp构建项目&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;请看 &lt;a href=&quot;http://javascript.ruanyifeng.com/nodejs/npm.html&quot;&gt;npm模块管理器&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;生成 package.json:
        &lt;ul&gt;
          &lt;li&gt;npm init&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;安装依赖:
        &lt;ul&gt;
          &lt;li&gt;npm install gulp –save-dev (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;非常有用&lt;/code&gt;)&lt;/li&gt;
          &lt;li&gt;(package.json 会多出 devDependencies … gulp …)&lt;/li&gt;
          &lt;li&gt;其他依赖:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;npm install gulp-uglify gulp-watch-path stream-combiner2&lt;/li&gt;
          &lt;li&gt;npm install gulp-sourcemaps gulp-minify-css gulp-autoprefixer gulp-less&lt;/li&gt;
          &lt;li&gt;npm install gulp-ruby-sass gulp-imagemin gulp-util –save-dev
    * &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;当你将这份 gulpfile.js 配置分享给你的朋友时，就不需要将 node_modules/　发送给他，他只需在命令行输入&lt;/code&gt;：&lt;/li&gt;
          &lt;li&gt;npm install&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;设计目录结构:
        &lt;ul&gt;
          &lt;li&gt;src : 源码目录:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;less *.less文件&lt;/li&gt;
          &lt;li&gt;sass *.scss *.sass文件&lt;/li&gt;
          &lt;li&gt;css&lt;/li&gt;
          &lt;li&gt;js&lt;/li&gt;
          &lt;li&gt;fonts&lt;/li&gt;
          &lt;li&gt;images
    * dist : 编译后压缩的版本目录&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;让命令行输出的文字带颜色&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-util&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;red&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;some&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置JS压缩任务: gulp-uglify
        &lt;ul&gt;
          &lt;li&gt;…&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;gulp-watch-path: 只编辑改动文件
        &lt;ul&gt;
          &lt;li&gt;通过 event 改变的信息来指定文件, event是自动的&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;nx&quot;&gt;event&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;nl&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;changed&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/path/to/src/js/log.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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-js 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;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;watchPath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-watch-path&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchjs&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;src/js/**/*.js&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&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;c1&quot;&gt;// watchPath(event, search, replace[, distExt])&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  eventgulp.watch 回调函数的 event&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  search需要被替换的字符串或正则（字符串会被转换为正则 /^src\//）&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  replace第三个参数是新的的字符串&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//  distExt扩展名(非必填)&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;watchPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;src/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/dist&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/*
          paths 
            {
                srcPath: &apos;src/js/log.js&apos;,
                srcDir: &apos;src/js/&apos;,
                distPath: &apos;dist/js/&apos;,
                srcFilename: &apos;log.js&apos;,
                distFilename: &apos;log.js&apos;
            }
        */&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;srcPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Dist &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;distPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;srcPath&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;uglify&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;distPath&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;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchjs&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;stream-combiner2: 用于检测js错误, 一出错, gulp立即终止并报错&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;gulp-sourcemaps:
        &lt;ul&gt;
          &lt;li&gt;压缩后的代码不存在换行符和空白符，导致出错后很难调试，好在我们可以使用sourcemap 帮助调试&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置CSS任务: gulp-minify-css&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;gulp-autoprifixer:
        &lt;ul&gt;
          &lt;li&gt;autoprefixer 解析 CSS文件并且添加浏览器前缀到CSS规则里&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置 less 任务: gulp-less&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置 sass 任务: gulp-sass&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置 image 任务: gulp-imagemin&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;配置复制文件任务&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchcopy&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;src/fonts/**/*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&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;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;watchPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 

        &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;type&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;srcPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;gutil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;distPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        
        &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;paths&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;srcPath&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;distDir&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;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;src/fonts/**/*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/fonts/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchjs&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchcss&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchless&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchsass&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watchimage&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;wacthcopy&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;15. 自动刷新浏览器页面，无需F5: gulp-livereload&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://github.com/vohof/gulp-livereload&quot;&gt;文档&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/&quot;&gt;也许这也的livereload更简洁&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-js 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;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;livereload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;gulp-livereload&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;src/less/*.less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;livereload&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;dist/less/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;nx&quot;&gt;pipe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;livereload&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;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;task&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&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;nx&quot;&gt;livereload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;gulp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;watch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less/*.less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;less&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&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;
</description>
    <link>/2015/04/18/gulp-getting-started.html</link>
    <guid>/2015/04/18/gulp-getting-started</guid>
    <pubDate>Sat, 18 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>PHP CodeIgniter Framework Study 2</title>
    <description>
&lt;h2 id=&quot;course-5-session机制和登陆验证&quot;&gt;Course 5 SESSION机制和登陆验证&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;利用SESSION进行登陆验证的原理:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;基本流程:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;客户端登陆: 用户输入用户名密码&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;服务端验证: 验证用户名和密码&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;生成SESSION, 并返回验证信息
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;一些常量:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;POST信息: $_POST对象 (var_dump($_POST))&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;GET信息: $_GET对象&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;COOKIE信息: $_COOKIE&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;SESSION信息: $_SESSION&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;SERVER信息: $_SERVER&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;FILE上传信息: $_FILES&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;ENV信息: $_ENV&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;REQUEST信息: $_REQUEST&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;利用CI框架进行SESSION登陆验证:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;CI的SESSION类:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;修改配置: application/config/config.php:
                &lt;ul&gt;
                  &lt;li&gt;$config[‘encryption_key’]&lt;/li&gt;
                  &lt;li&gt;要使用SESSION, 该项不能为空&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;加载SESSION类:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;load-&amp;gt;library(‘session’)&lt;/li&gt;
                  &lt;li&gt;在system/libraries/session/&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;创建SESSION:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;session-set_userdata($array)&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;查看SESSION:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;session-&amp;gt;userdata(session名)&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;删除SESSION:
  $this-&amp;gt;session-&amp;gt;unset_userdata(‘SESSION名’);&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;course-6-分页原理及实现&quot;&gt;Course 6 分页原理及实现&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;分页原理介绍:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;必须知道的一些参数:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;a. 总共有多少条记录&lt;/li&gt;
          &lt;li&gt;b. 一页要有多少条记录&lt;/li&gt;
          &lt;li&gt;c. 总共有多少页&lt;/li&gt;
          &lt;li&gt;d. 当前页前后要显示及格分页链接&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;利用CI的分页类实现分页列表:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;设置一些CI分页基本参数:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;总条数:
                &lt;ul&gt;
                  &lt;li&gt;$config[‘total_rows’]&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;一页显示几条:
                &lt;ul&gt;
                  &lt;li&gt;$config[‘per_page’]&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;定义当前页的前后各有及格数字链接:
                &lt;ul&gt;
                  &lt;li&gt;$config[‘num_links’]&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;定义没有分页参数，主URL:
                &lt;ul&gt;
                  &lt;li&gt;$config[‘base_url’]&lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;调用CI的分页类:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;library(‘pagination’);
    * 3. 执行分页方法:&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;pagination-&amp;gt;initialize(%config);
    * 4. 输出分页链接:&lt;/li&gt;
          &lt;li&gt;echo $this-&amp;gt;pagination-&amp;gt;create_links();
    * 5. 查询部分数据(limit):&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;db-&amp;gt;limit($length, $start);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;其他:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;count($array); // 数组的长度&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
    <link>/2015/04/14/php-codeigniter-study-2.html</link>
    <guid>/2015/04/14/php-codeigniter-study-2</guid>
    <pubDate>Tue, 14 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>PHP CodeIgniter Framework Study</title>
    <description>
&lt;h2 id=&quot;course-1-entrance-to-codeigniter&quot;&gt;Course 1. Entrance To CodeIgniter&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;MVC简单介绍:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;解释:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;M: Model (数据模型)&lt;/li&gt;
          &lt;li&gt;V: View (用户界面)&lt;/li&gt;
          &lt;li&gt;C: Controller (控制器)
    * 2.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI的简单介绍&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI的目录结构和工作流程:
        &lt;ul&gt;
          &lt;li&gt;CodeIgniter2.0.0目录结构:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;index.php : 应用主入口文件&lt;/li&gt;
          &lt;li&gt;system: 矿建核心程序目录:
            &lt;ul&gt;
              &lt;li&gt;core : 核心程序: 框架的基类、初始化&lt;/li&gt;
              &lt;li&gt;database : 数据库操作相关程序&lt;/li&gt;
              &lt;li&gt;fonts : 字库&lt;/li&gt;
              &lt;li&gt;helpers : 辅助函数&lt;/li&gt;
              &lt;li&gt;language : 语言包&lt;/li&gt;
              &lt;li&gt;libraries : 通用类库，比如验证、缓存、图像处理&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;application : 项目目录:
            &lt;ul&gt;
              &lt;li&gt;cache : 存放数据或模板缓存文件&lt;/li&gt;
              &lt;li&gt;config : 与目录相关的配置&lt;/li&gt;
              &lt;li&gt;controllers : MVC的控制器，继承CI_Controller&lt;/li&gt;
              &lt;li&gt;core : 项目的核心程序&lt;/li&gt;
              &lt;li&gt;errors : 错误提示模板&lt;/li&gt;
              &lt;li&gt;helpers : 项目的辅助函数&lt;/li&gt;
              &lt;li&gt;hooks : 钩子，在不修改系统核心文件的基础上扩展系统功能&lt;/li&gt;
              &lt;li&gt;language : 语言包&lt;/li&gt;
              &lt;li&gt;libraries : 通用类库&lt;/li&gt;
              &lt;li&gt;logs : 日志&lt;/li&gt;
              &lt;li&gt;models : MVC的模型, 一般继承CI_Model&lt;/li&gt;
              &lt;li&gt;third_party : 第三方类库&lt;/li&gt;
              &lt;li&gt;views : MVC的视图，主要是模板
                &lt;ul&gt;
                  &lt;li&gt;CI的业务流程:&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;入口 -&amp;gt; 控制器 -&amp;gt; 方法 -&amp;gt; 参数:
            &lt;ul&gt;
              &lt;li&gt;1.index.php -&amp;gt; URL路由 -&amp;gt; 安全过滤 -&amp;gt; 控制器 -&amp;gt; 模型/类库/辅助函数/插件/脚本&lt;/li&gt;
              &lt;li&gt;
                &lt;ol&gt;
                  &lt;li&gt;控制器-&amp;gt; 视图 -&amp;gt; 缓存 -&amp;gt; index.php 显示&lt;/li&gt;
                &lt;/ol&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意，每一个控制器都是一个类Class, 在每个Class里面的function都是一个页面&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;URL:
            &lt;ul&gt;
              &lt;li&gt;http://localhost&lt;/li&gt;
              &lt;li&gt;http://localhost/index.php&lt;/li&gt;
              &lt;li&gt;http://localhost/index.php/welcome&lt;/li&gt;
              &lt;li&gt;http://localhost/index.php/welcome/index.php&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[SERVER]/[Controller-Class]/[Controller-Method]/[Arguments]&lt;/code&gt;&lt;/li&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;默认控制器在: application/config/routes.php中有$route[&apos;default_controller&apos;]配置默认&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如何创建并操作一个CI控制器:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;什么是控制器:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;一个控制器是一个类文件，用户通过URL访问的就是某个控制器类中的具体成员方法，并由这个方法中的代码去做某些操作
    * 2. 如何创建控制器:&lt;/li&gt;
          &lt;li&gt;a. 进入application\controllers目录&lt;/li&gt;
          &lt;li&gt;b. 控制器文件名必须和类名一致，并且类名必须以大写之母开头&lt;/li&gt;
          &lt;li&gt;c. 继承核心的控制器类CI_Controller
    * 3. 创建方法:&lt;/li&gt;
          &lt;li&gt;a. 创建一个成员方法 function funName …&lt;/li&gt;
          &lt;li&gt;b. 默认访问的是index方法
    * 4. URL如何传递参数给方法:&lt;/li&gt;
          &lt;li&gt;方法段后的按次序传入方法中的形式参数&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;course-2-controller-and-views&quot;&gt;Course 2 Controller And Views&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;简述视图与控制器的关系:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;控制器:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;调用视图: 控制器需要根据用户的访问的不同方法，去调用相关视图&lt;/li&gt;
          &lt;li&gt;传送数据: 控制器需要向视图中传送需要展示个用户的业务数据
    * 2. 视图:&lt;/li&gt;
          &lt;li&gt;一个视图就是一个网页或网页的部分&lt;/li&gt;
          &lt;li&gt;application\views文件夹&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI如何创建视图:
        &lt;ul&gt;
          &lt;li&gt;进入application/views&lt;/li&gt;
          &lt;li&gt;创建php文件&lt;/li&gt;
          &lt;li&gt;写HTML嵌入PHP代码&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI控制器如何调用视图:
        &lt;ul&gt;
          &lt;li&gt;a. 调用一个视图:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘viewName’)&lt;/li&gt;
          &lt;li&gt;这里 viewName是application/views中创建的视图文件名&lt;/li&gt;
          &lt;li&gt;注意这里的视图文件一般以php结尾, 可以省去.php; 如果不是以.php结尾, 那么必须写完整的视图文件名
    * b. 调用多个视图:&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘v1’);&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘v2’);&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘v3’);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI控制器如何向视图传值:
        &lt;ul&gt;
          &lt;li&gt;a. 介绍:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;数据通过控制器以一个数组或是对象的形式传入视图，这个数组或对象作为视图载入函数的第二个参数&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘viewName’, ArrayOrObject);
    * b. 实例:&lt;/li&gt;
          &lt;li&gt;$data[‘title’] = ‘Title First’;&lt;/li&gt;
          &lt;li&gt;$data = array(‘name’ =&amp;gt; $name, ‘count’=&amp;gt;$count)&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;view(‘test_view’, $data)
    * c. 解释&lt;/li&gt;
          &lt;li&gt;传入的是对象或数组&lt;/li&gt;
          &lt;li&gt;视图中使用的是键名$name对象获取对应键值$value; 
    * d. 一些函数:&lt;/li&gt;
          &lt;li&gt;@$count = file_get_contents($fileName);&lt;/li&gt;
          &lt;li&gt;$resource = fopen($fileName, ‘w’);&lt;/li&gt;
          &lt;li&gt;fwrite($resource, $count);&lt;/li&gt;
          &lt;li&gt;fclose($resource);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;course-3-模型model&quot;&gt;Course 3. 模型Model&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;模型的介绍:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;模型是一个数据库类&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;一个模型针对一张表&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;类中的方法是针对功能的具体需求而做的&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如何利用CI进行模型创建(增删改查):
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;模型的存放目录:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;application/models
    * 2. 创建模型就是创建一个类文件:&lt;/li&gt;
          &lt;li&gt;必须继承核心类CI_Model, 同上重载父类中的构造方法
    * 3. 配置数据库: application/config/database.php:&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;…&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Model_Name&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CI_Model&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__construct&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;k&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;database&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;CI 为我们提供了一个强大而简单的数据库函数类:
        &lt;ul&gt;
          &lt;li&gt;Active Record 类: system/database/DB_active_rec.php&lt;/li&gt;
          &lt;li&gt;(3.0.0: system/database/DB_query_builder.php)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如何在模型中使用Active Record类中的方法呢:
        &lt;ul&gt;
          &lt;li&gt;$this-&amp;gt;db-&amp;gt;方法名()&lt;/li&gt;
          &lt;li&gt;例如: $this-&amp;gt;db-&amp;gt;get(‘entries’, 10); // 10是默认值&lt;/li&gt;
          &lt;li&gt;方法:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;连接数据库: $this-&amp;gt;load-&amp;gt;database():
                &lt;ul&gt;
                  &lt;li&gt;写在模型的构造函数里，这样加载模型的同时就连接上数据库了&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;插入数据: $this-&amp;gt;db-&amp;gt;insert($table_name, $data);:
                &lt;ul&gt;
                  &lt;li&gt;参数:&lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;$table_name 表名&lt;/li&gt;
                  &lt;li&gt;$data=你要插入的数据(键名=字段名, 键值=字段值, 自增主键不用写)&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;更新数据:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;db-&amp;gt;where(字段名, 字段值);&lt;/li&gt;
                  &lt;li&gt;$this-&amp;gt;db-&amp;gt;update(表名, 修改的数组);&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;查询数据:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;db-&amp;gt;where(字段名, 字段值);&lt;/li&gt;
                  &lt;li&gt;$this-&amp;gt;db-&amp;gt;select(字段);&lt;/li&gt;
                  &lt;li&gt;$query = $this-&amp;gt;db-&amp;gt;get(表名);&lt;/li&gt;
                  &lt;li&gt;return $query-&amp;gt;result();&lt;/li&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var_dump($query-&amp;gt;result);&lt;/code&gt; 输出一个对象的。。。&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;删除数据:
                &lt;ul&gt;
                  &lt;li&gt;$this-&amp;gt;db-&amp;gt;where(字段名, 字段值);&lt;/li&gt;
                  &lt;li&gt;$query-&amp;gt;db-&amp;gt;delete(表名);&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在Controller中载入模型:
        &lt;ul&gt;
          &lt;li&gt;$this-&amp;gt;load-&amp;gt;model(模型名)&lt;/li&gt;
          &lt;li&gt;$this-&amp;gt;模型名-&amp;gt;方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;course-4-ci快捷类库&quot;&gt;Course 4 CI快捷类库&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;PHP的文件上传如何实现:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;提交上传:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;enctype=”multipart/form-data”:
            &lt;ul&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;form action=&quot;/index.php/upload/up&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&amp;gt;&lt;/code&gt;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;type=”file”
    * 2. 接收信息:&lt;/li&gt;
          &lt;li&gt;$_FILES : var_dump($_FILES);&lt;/li&gt;
          &lt;li&gt;原文件名&lt;/li&gt;
          &lt;li&gt;临时文件名&lt;/li&gt;
          &lt;li&gt;大小&lt;/li&gt;
          &lt;li&gt;文件编码格式&lt;/li&gt;
          &lt;li&gt;报错信息
    * 3. 判断:&lt;/li&gt;
          &lt;li&gt;文件大小&lt;/li&gt;
          &lt;li&gt;文件格式
    * 4. 上传:&lt;/li&gt;
          &lt;li&gt;move_uploaded_file(oldfile, newfile);&lt;/li&gt;
          &lt;li&gt;例如: move_uploaded_file($_FILES[‘tmp_name’], ‘./upload/’.$_FILES[‘name’])&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如何利用CI提供的类库实现便捷上传:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;定义一个数组，设置一些与上传相关的参数:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;必须参数(3个):
            &lt;ul&gt;
              &lt;li&gt;// 设置上传目录, 这里写./, 目录要建在网站根目录，就是和application同级&lt;/li&gt;
              &lt;li&gt;// 如果你要在application目录下，可以使用系统定义的路劲常量APPPATH&lt;/li&gt;
              &lt;li&gt;// 例如: APPPATH.’uploads/’;&lt;/li&gt;
              &lt;li&gt;$config[‘upload_path’] = ‘./uploads/’;&lt;/li&gt;
              &lt;li&gt;// 设置允许上传的类型&lt;/li&gt;
              &lt;li&gt;
                &lt;table&gt;
                  &lt;tbody&gt;
                    &lt;tr&gt;
                      &lt;td&gt;$config[‘allowed_types’] = ‘gif&lt;/td&gt;
                      &lt;td&gt;jpg&lt;/td&gt;
                      &lt;td&gt;png’;&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              &lt;/li&gt;
              &lt;li&gt;$config[‘max_size’] = ‘100’;&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;可选参数:
            &lt;ul&gt;
              &lt;li&gt;// 如果是图片还还能设置最大高度和宽度&lt;/li&gt;
              &lt;li&gt;$config[‘max_width’] = ‘1024’;&lt;/li&gt;
              &lt;li&gt;$config[‘max_height’] = ‘768’;&lt;/li&gt;
              &lt;li&gt;// 要使用的文件名&lt;/li&gt;
              &lt;li&gt;$config[‘file_name’] = ‘xxx’;&lt;/li&gt;
              &lt;li&gt;// 是否覆盖&lt;/li&gt;
              &lt;li&gt;$config[‘override’] = FALSE; // 默认&lt;/li&gt;
              &lt;li&gt;// 是否将文件名中的空格替换为下划线&lt;/li&gt;
              &lt;li&gt;$config[‘remove_spaces’] = TRUE;&lt;/li&gt;
              &lt;li&gt;// 是否重命名文件，将文件名重命名为随机的加密字符串&lt;/li&gt;
              &lt;li&gt;$config[‘encrypt_name’] = TRUE&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;现成类库: system/libraries: Upload.php&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;调用CI的上传通用类，并执行上传:
            &lt;ul&gt;
              &lt;li&gt;// upload为调用的类名，全小写&lt;/li&gt;
              &lt;li&gt;$this-&amp;gt;load-&amp;gt;library(‘upload’, $config);&lt;/li&gt;
              &lt;li&gt;// 如果上传框的name写的是userfile, 那就不用传参数，如果不是，把name的值传进去&lt;/li&gt;
              &lt;li&gt;$this-&amp;gt;upload-&amp;gt;do_upload(‘上传框的name’):&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;该函数返回值为boolean, 成功为TRUE&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;接收出错信息或成功信息:
            &lt;ul&gt;
              &lt;li&gt;出错信息:&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;$error = array(‘error’ =&amp;gt; $this-&amp;gt;upload-&amp;gt;display_errors());
    * 成功信息，会把上传后的文件信息返回来:&lt;/li&gt;
              &lt;li&gt;$data = array(‘upload_data’ =&amp;gt; $this-&amp;gt;upload-&amp;gt;data());&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/12/php-codeigniter-study.html</link>
    <guid>/2015/04/12/php-codeigniter-study</guid>
    <pubDate>Sun, 12 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Tmux 初识</title>
    <description>
&lt;h2 id=&quot;tmux-terminal-multiplexer&quot;&gt;Tmux: Terminal Multiplexer&lt;/h2&gt;

&lt;h2 id=&quot;linux安装tmux最新版脚本&quot;&gt;&lt;a href=&quot;/scripts/install_tmux.sh&quot;&gt;linux安装tmux最新版脚本&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;1-基本命令&quot;&gt;1. 基本命令&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;新建一个无名session:
        &lt;ul&gt;
          &lt;li&gt;tmux&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;显示有多少个session:
        &lt;ul&gt;
          &lt;li&gt;tmux list-session&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;新建有名字 sessionName 的session:
        &lt;ul&gt;
          &lt;li&gt;tmux new-session -s sessionName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;脱离tmux, 断开session, 但保留现场:
        &lt;ul&gt;
          &lt;li&gt;ctrl+b+d (d: detachead):&lt;/li&gt;
          &lt;li&gt;C-b (Ctrl+b): Send the prefix key (C-b) through to the application.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;重写连接session:
        &lt;ul&gt;
          &lt;li&gt;tmux attach-session -t sessionName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;结束/杀死session:
        &lt;ul&gt;
          &lt;li&gt;tmux kill-session -t sessionName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;删除所有session, 只要删除server即可, 因为所有的session的跑在一个server上:
        &lt;ul&gt;
          &lt;li&gt;tmux kill-server&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;一个server可以有多个session, 一个session上可以有多个窗口:
        &lt;ul&gt;
          &lt;li&gt;C-b c (ctrl+b +c): c: create, 在session中新建多窗口&lt;/li&gt;
          &lt;li&gt;C-b 窗口序号: 可以切换窗口, 如 C-b 0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;一个窗口可以分割多个窗格:
        &lt;ul&gt;
          &lt;li&gt;C-b % : 分列&lt;/li&gt;
          &lt;li&gt;C-b “ : 分行&lt;/li&gt;
          &lt;li&gt;C-b o 或者 C-b 方向键: 切换窗格&lt;/li&gt;
          &lt;li&gt;C-d 结束当前窗格&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;获取帮助信息，快捷键:
        &lt;ul&gt;
          &lt;li&gt;C-b ?&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;执行快捷键两种方式:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;C-b + 快捷键&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;C-b + : + 快捷键全称&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在.tmux.conf配置:
        &lt;ul&gt;
          &lt;li&gt;内容:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;unbind C-b&lt;/li&gt;
          &lt;li&gt;set -g prefix C-a
      * 更新环境, 使配置生效:&lt;/li&gt;
          &lt;li&gt;C-b + : + source-file ~/.tmux.conf&lt;/li&gt;
          &lt;li&gt;现在C-a 生效&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;13 快捷键 C-b 来send prefix (默认):
|ShortCut|Meanings|
|:——:|:——:|
|?|list-keys|
|d|detach-client|
|c|new-window|
|n|next-window|
|p|previous-window|
|”|split-window|
|%|split-window -h|
|!|break-panel|
|q|display-panels|
|o|rotate-window|
|0-9|select-window|
|:|command-prompt|&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;tmux Copy Mode 来支持鼠标滚轮:
        &lt;ul&gt;
          &lt;li&gt;C-b [&lt;/li&gt;
          &lt;li&gt;类似vim的命令模式&lt;/li&gt;
          &lt;li&gt;编辑 .tmux.conf, 添加:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;set -g mode-keys vi
      * source-file ~/.tmux.conf&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;复制黏贴:
        &lt;ul&gt;
          &lt;li&gt;vim 复制:
            &lt;ul&gt;
              &lt;li&gt;移到想要复制的位置, 敲空格建来开始复制命令&lt;/li&gt;
              &lt;li&gt;然后vim方式移动&lt;/li&gt;
              &lt;li&gt;敲回车结束复制操作&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;粘贴: C-b ]&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-远程服务器tmux&quot;&gt;2. 远程服务器tmux&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;如果远端一个命令阻塞, tmux就很好用了&lt;/li&gt;
  &lt;li&gt;如果网络断开也不怕&lt;/li&gt;
  &lt;li&gt;tmux聊天, 分享窗口, 同步显示:
    &lt;ul&gt;
      &lt;li&gt;只要对方attach同一个session即可: tmux a -t sessionName == tmux attach-session -t sessionName&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-tmuxconf-配置-下载地址&quot;&gt;3. .tmux.conf 配置: &lt;a href=&quot;/confs/tmux.conf&quot;&gt;下载地址&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;unbind C-b
&lt;span class=&quot;nb&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; prefix C-a
setw &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; mode-keys vi

&lt;span class=&quot;c&quot;&gt;# split window like vim&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# vim&apos;s defination of a horizontal/vertical split is revised from tmux&apos;s&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;s split-window &lt;span class=&quot;nt&quot;&gt;-h&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;v split-window &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# move around panes with hjkl, as one would in vim after C-w&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;h &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;j &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;k &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind &lt;/span&gt;l &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-pane&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# resize panes like vim&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# feel free to change the &quot;1&quot; to however many lines you want to resize by&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# only one at a time can be slow&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; &amp;lt; resize-pane &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt; 10
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; resize-pane &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; 10
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; - resize-pane &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; 10
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; + resize-pane &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; 10

&lt;span class=&quot;c&quot;&gt;#bind : to command-prompt like vim&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# this is the default in tmux&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; : command-prompt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/04/11/tmux.html</link>
    <guid>/2015/04/11/tmux</guid>
    <pubDate>Sat, 11 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux 高级网络配置</title>
    <description>
&lt;h2 id=&quot;1-网卡高级命令&quot;&gt;1. 网卡高级命令&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看物理网卡状态:
        &lt;ul&gt;
          &lt;li&gt;sudo mii-tool eth0&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看物理网卡配置:
        &lt;ul&gt;
          &lt;li&gt;ethtool eth0 查看网卡特性&lt;/li&gt;
          &lt;li&gt;ethtool -i eth0 查看驱动信息&lt;/li&gt;
          &lt;li&gt;ethtool -S eth0 查看网卡状态&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-ip-别名&quot;&gt;2. IP 别名&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;Linux 支持在一个物理网卡上配置多个IP地址
用来实现类是子接口之类的功能，也就是IP别名&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;禁用网卡管理: (CentOS or RHEL):
        &lt;ul&gt;
          &lt;li&gt;service NetworkManager stop&lt;/li&gt;
          &lt;li&gt;chkconfig NetworkManager off&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;用IP命令临时创建一个IP别名:
        &lt;ul&gt;
          &lt;li&gt;ip addr add 10.1.1.1/24 dev eth0 label eth0:0&lt;/li&gt;
          &lt;li&gt;eth0:0中第二个0为别名的编号&lt;/li&gt;
          &lt;li&gt;第二个别名可以为eth0:1&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;当然也可以使用ifconfig&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;永久添加IP别名..&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
    <link>/2015/04/11/linux-network-settings.html</link>
    <guid>/2015/04/11/linux-network-settings</guid>
    <pubDate>Sat, 11 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>apache2.4: You don't have permission to access / on this server.</title>
    <description>
&lt;h2 id=&quot;1-檢查權限&quot;&gt;1. 檢查權限&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;用戶和組的配置
```bash
 sudo vim /etc/apache2/apache2.conf 找到 User 和 Group
发现配置用户和组的文件在/etc/apache2/envvars&lt;/li&gt;
      &lt;li&gt;第一种强制方法就是将User ${APACHE_RUN_USER}改为 User ubuntu, 将Group ${APACHE_RUN_GROUP}改为Group ubuntu (其中ubuntu是web根目录(DocumentRoot)权限用户)&lt;/li&gt;
      &lt;li&gt;第二种方法是修改/etc/apache2/envvars
    将export APACHE_RUN_USER=www-data改为export APACHE_RUN_USER=ubuntu
    将export APACHE_RUN_GROUP=www-data改为export APACHE_RUN_GROUP=ubuntu (其中ubuntu为web根目录(DocumentRoot)权限用户)
```&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;修改web根目录权限, 默认是当前用户:
        &lt;ul&gt;
          &lt;li&gt;sudo chown -R owner:group /path/to/webDocumentRootDirectory&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;默认启动/etc/apache2/sites-enabled/*.conf, 因为/etc/apache2/apache2.conf中IncludeOptional sites-enabled/*.conf&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;默认启动的virtual host是/etc/apache2/sites-enabled/000-default.conf, 修改DocumentRoot:
        &lt;ul&gt;
          &lt;li&gt;DocumentRoot /path/to/webDocumentRootDirectory&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Directory是配置文件，这个不明白; DocumentRoot是virtual host的web文件根目录&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/11/apache24-403-forbidden.html</link>
    <guid>/2015/04/11/apache24-403-forbidden</guid>
    <pubDate>Sat, 11 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>LVM: Logical Volume Manager</title>
    <description>
&lt;h2 id=&quot;lvm-逻辑卷管理&quot;&gt;LVM: 逻辑卷管理&lt;/h2&gt;

&lt;h3 id=&quot;1-概念&quot;&gt;1. 概念&lt;/h3&gt;
&lt;p&gt;|缩写|全称|中文|
|:—|:—|:—|
|PE|Physical Extend|物理扩展|
|PV|Physical Volume|物理卷|
|VG|Volume Group|卷组|
|LV|Logical Volume|逻辑卷|&lt;/p&gt;

&lt;h3 id=&quot;2-顺序-or-层次&quot;&gt;2. 顺序 or 层次&lt;/h3&gt;
&lt;p&gt;|Module|Direction|Module|
|:—-:|:——-:|:—-:|
|PV|&amp;lt;—-|PE|
|向下组成||向下组成|
|VG|&amp;lt;—-|PE Pool|
|向下组成||向下组成|
|LV|&amp;lt;—-|PE|&lt;/p&gt;

&lt;h3 id=&quot;3-顺序创建&quot;&gt;3. 顺序创建&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;将物理磁盘设备初始化为物理卷:
        &lt;ul&gt;
          &lt;li&gt;创建: pvcreate /dev/sda /dev/sdb&lt;/li&gt;
          &lt;li&gt;查看状态: pvs 查看简单信息; pvdisplay 查看详细信息&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;创建卷组, 将PV加入卷组中:
        &lt;ul&gt;
          &lt;li&gt;创建: vgcreate vgName /dev/sda /dev/sdb&lt;/li&gt;
          &lt;li&gt;查看状态：　vgs vgdisplay&lt;/li&gt;
          &lt;li&gt;位置: /dev/vgName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;基于卷组创建逻辑卷:
        &lt;ul&gt;
          &lt;li&gt;创建: lvcreate -n lvName -L 2G vgName&lt;/li&gt;
          &lt;li&gt;查看状态: lvs lvdisplay&lt;/li&gt;
          &lt;li&gt;位置: /dev/vgName/lvName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;格式化文件系统:
        &lt;ul&gt;
          &lt;li&gt;mkfs.ext4 /dev/vgName/lvName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;挂在文件系统:
        &lt;ul&gt;
          &lt;li&gt;mount /dev/vgName/lvName /mnt&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看挂载文件系统状态:
        &lt;ul&gt;
          &lt;li&gt;mount&lt;/li&gt;
          &lt;li&gt;df -m&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-顺序删除&quot;&gt;4. 顺序删除&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;卸载逻辑卷: umount /mnt&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;移除逻辑卷: lvremove /dev/vgName/lvName&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;移除卷组(前提: 必须移除所有lv才行): vgremove /dev/vgName&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;移除物理卷: pvremove /dev/sda /dev/sdb&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5-拉伸一个逻辑卷&quot;&gt;5. 拉伸一个逻辑卷&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;保证VG有足够的空闲空间, vgdisplay&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;扩充逻辑卷:
        &lt;ul&gt;
          &lt;li&gt;lvextend -L +1G /dev/vgName/lvName&lt;/li&gt;
          &lt;li&gt;为lvName逻辑卷增加1G扩展空间&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看扩充后LV大小, lvdisplay&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;更新文件系统，才能让系统知道(df 前后可知):
        &lt;ul&gt;
          &lt;li&gt;resize2fs /dev/vgName/lvName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看新的文件系统: df -h&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;6-拉伸一个卷组&quot;&gt;6. 拉伸一个卷组&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;将要添加到VG的硬盘格式化为PV:
        &lt;ul&gt;
          &lt;li&gt;pvcreate /dev/sdd&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;将新的PV添加到指定卷组:
        &lt;ul&gt;
          &lt;li&gt;vgextend vgName /dev/sdd&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看VG大小 vgdisplay&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;7-缩小一个逻辑卷&quot;&gt;7. 缩小一个逻辑卷&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;卸载已经挂载的文件系统:
        &lt;ul&gt;
          &lt;li&gt;umount /dev/vgName/lvName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;缩小文件系统:
        &lt;ul&gt;
          &lt;li&gt;resize2fs /dev/vgName/lvName 1G&lt;/li&gt;
          &lt;li&gt;将文件系统缩小到 1G&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;缩小LV:
        &lt;ul&gt;
          &lt;li&gt;lvreduce -L -1G /dev/vgName/lvName&lt;/li&gt;
          &lt;li&gt;将lvName逻辑卷减小 1G 大小&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;lvdisplay&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;挂载文件系统:
        &lt;ul&gt;
          &lt;li&gt;mount /dev/vgName/lvName /mnt&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;8-缩小卷组&quot;&gt;8. 缩小卷组&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;将一个pv从指定卷组中移除:
        &lt;ul&gt;
          &lt;li&gt;vgreduce vgName /dev/sdd&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看 vgdisplay&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;3, 移除物理卷:
    &lt;ul&gt;
      &lt;li&gt;pvremove /dev/sdd&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/10/lvmlogical-volume-manager.html</link>
    <guid>/2015/04/10/lvmlogical-volume-manager</guid>
    <pubDate>Fri, 10 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Iptables 基础</title>
    <description>
&lt;h2 id=&quot;参考&quot;&gt;参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://linux.die.net/man/8/iptables&quot;&gt;Man Page&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Iptables&quot;&gt;Arch Wiki&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-iptables-命令的基础&quot;&gt;1. IPTABLES 命令的基础&lt;/h2&gt;

&lt;h3 id=&quot;one-iptables-规则的基本格式&quot;&gt;One IPTABLES 规则的基本格式:&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;iptables [-t table] command [match] [target/jump]&lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;
      &lt;ol&gt;
        &lt;li&gt;table 默认为 filter 表&lt;/li&gt;
      &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;ol&gt;
        &lt;li&gt;没有人要求target 必须放在 command 后面，但是最好这样。&lt;/li&gt;
      &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;ol&gt;
        &lt;li&gt;match : 细致的描述了包的某个特点,以使这个包区别于其他所有包.这里可以指定包的来源:
          &lt;ul&gt;
            &lt;li&gt;
              &lt;ol&gt;
                &lt;li&gt;来源IP地址&lt;/li&gt;
              &lt;/ol&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;ol&gt;
                &lt;li&gt;网络接口(-o eth0等)&lt;/li&gt;
              &lt;/ol&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;ol&gt;
                &lt;li&gt;端口(–sport, –dport)&lt;/li&gt;
              &lt;/ol&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;ol&gt;
                &lt;li&gt;协议类型(tcp udp icmp ….)&lt;/li&gt;
              &lt;/ol&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;ol&gt;
                &lt;li&gt;其他&lt;/li&gt;
              &lt;/ol&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ol&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;ol&gt;
        &lt;li&gt;target: 指定匹配报文的所有动作(ACCEPT, DROP, REDIRECT, CHAIN-NAME等)&lt;/li&gt;
      &lt;/ol&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;two-iptables-tables-表&quot;&gt;Two IPTABLES tables 表&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-t 选项指明要操作的表, 默认是filter表&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;tables:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nat&lt;/code&gt; (3链): 主要用于网络地址转换,即Network Address Translation, 缩写为NAT.:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;注意: 属于一个流的包只会经过这个表一次。如果第一个包被允许做NAT或Masqueraded, 那么余下的包会自动地被做相同的动作。也就是余下的包不会再通过nat这个表，一个一个的被NAT, 而是自动完成。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;这就是为什么不应该在nat表做任何过滤的主要原因&lt;/code&gt;.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PREROUTING&lt;/code&gt; 链: 主要用于包刚刚到达防火墙时该表它的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;目的地址&lt;/code&gt;。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(对远程进来的包)可以重定向访问的地址, 很方便&lt;/code&gt;&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUTPUT&lt;/code&gt; 链: 改变&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;本地&lt;/code&gt;产生的包的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;目的地址&lt;/code&gt;.&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;全局代理用到,将本机产生的所有包通过OUTPUT表全部转到本地某个端口, 不明白？&lt;/code&gt;&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POSTROUTING&lt;/code&gt; 链: 在包就要离开防火墙是改变其&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;源地址&lt;/code&gt;.
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mangle&lt;/code&gt; (5链): 主要用来 mangle 数据包:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以改变不同的包及包头的内容，如TTL, TOS 或 MARK.注意MARK并没有真正地改动数据包，它只是在内核空间为包设定一个标记.防火墙内的其他规则或程序(如tc)可以使用这中标记对包进行过滤或高级路由.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PREROUTING&lt;/code&gt; 链: 在包进入防火墙之后、路由判断之前改变包.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POSTROUTING&lt;/code&gt; 链: 在所有路由判断之后改变包.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUTPUT&lt;/code&gt; 链: 在确定包的目的之前更改数据包.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INPUT&lt;/code&gt; 链: 在包被路由到本地之后, 但是在用户空间的程序看到他之前被改变.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FORWARD&lt;/code&gt; 链: 在最初的路由判断之后、最后一次更改包的目的之前 mangle 包.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: mangle 表不能做任何NAT, 它只是该表数据包的TTL, TOS 或 MARK, 而不是其源目地址. NAT在nat表中操作.&lt;/code&gt;
    * 3. filter (3链): 用来完成报文的过滤，和其他操作一样，在filter表里可以DROP/记录/ACCEPT/REJECT报文.:&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FORWARD&lt;/code&gt; 链: 主要用来处理非本机报文.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INPUT&lt;/code&gt; 链: 处理所有目的地址为本机的报文&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUTPUT&lt;/code&gt; 链: 处理所有本机发送的报文.
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;raw 表 (2链): Raw表和它的链都在netfilter的模块之前，主要用来完成NOTRACK功能.需要kernel大于等于2.6 :&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PREROUTING&lt;/code&gt; 链: 用于到本机的所有报文&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUTPUT&lt;/code&gt; 链: 用于本机发送的所有报文&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;three-iptables-commands-命令&quot;&gt;Three IPTABLES Commands 命令&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-A, –append: 链尾追加规则:
        &lt;ul&gt;
          &lt;li&gt;iptables -t filter -A INPUT …&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-D, –delete: 删除某链的规则:
        &lt;ul&gt;
          &lt;li&gt;用序号(第1.条是1不是0, 累加): iptables -t filter -D INPUT 1&lt;/li&gt;
          &lt;li&gt;用完整规则: iptables -D INPUT –dport 80 -j DROP&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-R, –replace: 替换规则:
        &lt;ul&gt;
          &lt;li&gt;和-D使用方式类似，但较少使用&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-I, –insert: 插入规则:
        &lt;ul&gt;
          &lt;li&gt;iptable -I INPUT 1 –dport 80 -j ACCEPT # 在序号1上插入规则&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-L, –list: 列出某链上的所有规则:
        &lt;ul&gt;
          &lt;li&gt;iptables -L INPUT&lt;/li&gt;
          &lt;li&gt;如果没有指定链的名称，就列出该表上所有链的所有规则: iptables -L&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-F, –flush: 清空某连上的规则, 也就是删除某链上的所有规则:
        &lt;ul&gt;
          &lt;li&gt;iptable -F INPUT&lt;/li&gt;
          &lt;li&gt;iptables -F # 没有指定链名，会清空该表上的所有链的所有规则&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-Z, –zero: 清空计数器值:
        &lt;ul&gt;
          &lt;li&gt;iptables -Z INPUT&lt;/li&gt;
          &lt;li&gt;同&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-N, –new-chain: 新建用户自定义链:
        &lt;ul&gt;
          &lt;li&gt;iptables -N allowed&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-X, –delete-chain: 从表上删除指定的链, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;删除链前，必须清空链的规则&lt;/code&gt;.
        &lt;ul&gt;
          &lt;li&gt;iptables -X allowed&lt;/li&gt;
          &lt;li&gt;只能删除用户自定义的链&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-P, –policy: 为链配置默认的target(值为ACCEPT或DROP), 这个target称为策略:
        &lt;ul&gt;
          &lt;li&gt;iptables -P INPUT DROP&lt;/li&gt;
          &lt;li&gt;默认使用这个target(策略), 只有符合特定规则的采用特定方式.&lt;/li&gt;
          &lt;li&gt;只有内建的链才可以使用规则.但内建的链和用户自定义的链都不能用作策略&lt;/li&gt;
          &lt;li&gt;不允许: iptables -P INPUT allowed&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-E, –rename-chain:为链重命名:
        &lt;ul&gt;
          &lt;li&gt;iptables -E ChainOldName ChainNewName&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;four-iptables-options-选项&quot;&gt;Four IPTABLES OPTIONS (选项)&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -Lv
        &lt;ul&gt;
          &lt;li&gt;Option: -v, –version&lt;/li&gt;
          &lt;li&gt;Commands: –list, –append, –insert, –delete, –replace&lt;/li&gt;
          &lt;li&gt;Such as: iptables -Lv&lt;/li&gt;
          &lt;li&gt;Explanation:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -Lx :
        &lt;ul&gt;
          &lt;li&gt;Option: -x, –exact # 将输出中的计数器显示准确的数字，必须和–list连用&lt;/li&gt;
          &lt;li&gt;Commands: -L, –list&lt;/li&gt;
          &lt;li&gt;Explanation:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -Ln or iptables -Lvn:
        &lt;ul&gt;
          &lt;li&gt;Option: -n, –numeric # 使输出的IP地址和端口以数值的形式显示, 而不是默认名字，如主机名，网络名，程序名等&lt;/li&gt;
          &lt;li&gt;Commands: -L, –list&lt;/li&gt;
          &lt;li&gt;Explanation:&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -L –line-numbers:
        &lt;ul&gt;
          &lt;li&gt;Option: –line-numbers # 显示规则的行号&lt;/li&gt;
          &lt;li&gt;Commands: -L, –list # 列出规则&lt;/li&gt;
          &lt;li&gt;Explanation:&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -I INPUT -c 20 4000:
        &lt;ul&gt;
          &lt;li&gt;Option: -c, –set-counters # 设置字节或者报文的计数值&lt;/li&gt;
          &lt;li&gt;Commands: -I, -A, -R&lt;/li&gt;
          &lt;li&gt;Explanation&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;…:
        &lt;ul&gt;
          &lt;li&gt;Option: –modprobe # iptables 探测并装在要使用的模块.&lt;/li&gt;
          &lt;li&gt;Commands: All&lt;/li&gt;
          &lt;li&gt;Explanation:&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-iptables-的匹配matches&quot;&gt;2. IPTABLES 的匹配(matches)&lt;/h2&gt;

&lt;h3 id=&quot;one-通用匹配-可以在任何规则里&quot;&gt;One. 通用匹配: 可以在任何规则里&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -p, –protocol : 主要用来检查特定协议(TCP/UDP/ICMP等)
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -A INPUT -p tcp&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;指定协议的名称，必须在/etc/protocols里面定义，否则报错&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以指定一个整数值, 例如ICMP是1, TCP是6, UDP是17&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;另外，可以指定为ALL, ALL表示仅匹配ICMP/TCP/UDP协议，这个是默认配置,数值为0:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;iptables -A INPUT -p all -j ACCEPT&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -s, –src, –source : 主要用来匹配报文的源地址,单个IP或IP地址段(一个主机或一个网络):
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -A INPUT -s 192.168.1.1&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;单个地址: -s 192.168.1.1&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;一个网络: -s 192.168.0.0/24&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;缺省表示所有地址&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -d, –dst, –destination: 匹配报文的目的地址, 用法和源地址一致&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -i, –in-interface : 以包进入本地所使用的网络接口来匹配包.&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意:只能用于INPUT, FORWARD, PREROUTING链.&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -A INPUT -i eth0&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;指定接口名称&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;使用通配符, 即英文加号, 表示匹配所有包, 不考虑来自哪个接口, 这是不指定接口的默认行为:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;iptables -I INPUT -i +&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -o, –out-interface: 以包离开本地所使用的网络接口的匹配包, 和 -i 一样&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: -f, –fragment : ….&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;集合例子: iptables -t nat -A OUTPUT -s 10.1.0.0/24 -d 111.112.113.114 -p tcp -j ACCEPT&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;two-只能用于tcp的tcp-matches&quot;&gt;Two. 只能用于TCP的TCP matches&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –sport, –source-port : 基于TCP包的源端口来匹配包:
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -A INPUT -p tcp –sport 22&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;不指定此项，暗指所有端口.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;使用服务名或端口号, 但名字必须在/ect/services中定义, 因为iptables从这个文件查找想要的端口号.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以使用连续的端口: -p tcp –sport 22:80, 从22到80的所有端口, 包括22和80&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;连续端口可以省略第一个端口号，即从0号端口开始: -p tcp –sport :80&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;连续端口省略第二个端口号,即到65535端口为止: -p tcp –sport 22:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –dport, –destination-port: 目的端口, 和–sport用法一样&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –tcp-flags :　匹配指定的TCP标记:
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -A INPUT -p tcp –tcp-flag SYN,FIN,ACK SYN&lt;/li&gt;
          &lt;li&gt;有两个参数，它们都是列表(以,隔开), 这两个列表以空格隔开&lt;/li&gt;
          &lt;li&gt;第一个参数指定要检查的标记; 第二个标记指定”在第一个列表中出现过且必须被设为1(即状态打开)”的标记(第一个表的其他标记必须置零).&lt;/li&gt;
          &lt;li&gt;也就是，第一个参数提供检查范围，第二个参数提供被设置的条件(即哪些可以置1)&lt;/li&gt;
          &lt;li&gt;标记有: SYN, ACK, FIN, RST, URG, PSH, 还有ALL和NONE&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;表示匹配哪些SYN标记被设置而FIN和ACK标记没有设置的包: iptables -p tcp –tcp-flags SYN,FIN,ACK SYN&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;–tcp-flags ALL NONE 匹配所有标记都未置1的包&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –tcp-option : 根据选项匹配包:
        &lt;ul&gt;
          &lt;li&gt;Example: iptables -p tcp –tcp-option 16&lt;/li&gt;
          &lt;li&gt;TCP选项是TCP头中的特殊部分，有三个不同的部分:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;第一个8位组标书选项的类型&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;第二个8位组标书选项的长度(这个长度是整个选项的长度，但不包含填充部分所占的字节，而且要注意不是每个TCP选项都有这一部分)&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;第三个8位组标书选项的内容&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;three-能够用于udp的udp-matches&quot;&gt;Three. 能够用于UDP的UDP matches:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;UDP是一种无连接协议，所以它在打开、关闭连接以及发送数据时没有多少标记要设置，它也不需要任何类型的确认.&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –sport, –source-port 和 TCP 一样&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Match: –dport, –destination-port 和 TCP 一样&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;four-只能用于icmp的icmp-matches&quot;&gt;Four. 只能用于ICMP的ICMP matches&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;和UDP一样是无连接协议, 但是生存时间更短&lt;/li&gt;
  &lt;li&gt;ICMP协议主要用来错误报告和连接控制等&lt;/li&gt;
  &lt;li&gt;ICMP不是IP的子协议，而是和IP并列的一个协议，它主要用来增强IP功能和帮助IP进行错误处理.&lt;/li&gt;
  &lt;li&gt;Match: –icmp-type : 根据ICMP类型匹配包:
    &lt;ul&gt;
      &lt;li&gt;Example: iptables -A INPUT -p icmp –icmp-type 8&lt;/li&gt;
      &lt;li&gt;帮助: iptables -p icmp –help&lt;/li&gt;
      &lt;li&gt;icmp 类型 ….&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;four-1-sctp匹配matches&quot;&gt;Four. 1 SCTP匹配(matches):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;流控制传输协议(SCTP), 是一个箱单新的协议，查看问&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;five-显示匹配explicit-matches&quot;&gt;Five 显示匹配(Explicit matches):&lt;/h3&gt;

&lt;h3 id=&quot;five-一些特殊匹配-例如基于状态state-所有者owner或者限制limit等&quot;&gt;Five. 一些特殊匹配, 例如基于状态(state), 所有者(owner)或者限制(limit)等&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;显示匹配必须用-m或–match装载, 比如使用状态匹配就必须使用 -m state&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;five-1-限速匹配器match&quot;&gt;Five 1. 限速匹配器(match)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;对指定的规则的日志数量加以限制&lt;/li&gt;
  &lt;li&gt;减少Dos syn flood攻击的影响&lt;/li&gt;
  &lt;li&gt;-m –limit –limit 5/s: 限制每秒5个package，其他丢弃(每个package 1480字节); 也就是在数量超过限定后，所有的包都会被匹配.&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;-m limit –limit 5/s –limit-burst 10/s:
        &lt;ul&gt;
          &lt;li&gt;limit-burst令牌首先被初始化为10, 每一条满足这条规则的报文都会消耗一个令牌&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;…&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;five-2-mac地址匹配器match&quot;&gt;Five 2. MAC地址匹配器(match)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;能够根据报文的MAC地址匹配报文，到目前只能根据报文的源MAC进行匹配&lt;/li&gt;
  &lt;li&gt;-m mac&lt;/li&gt;
  &lt;li&gt;Match: –mac-source : 基于包的MAC源地址匹配包，地址格式XX:XX:XX:XX:XX:XX :
    &lt;ul&gt;
      &lt;li&gt;iptables -A INPUT -m mac –mac-source 00:11:22:33:44:55&lt;/li&gt;
      &lt;li&gt;注意: 因为MAC address 只能用于 Ethernet 类型的网络,所以这个match只能用于Ethernet接口, 而且，　它还只能在PREROUTING, FORWARD 和 INPUT链里使用.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;five-3-多端口匹配器match&quot;&gt;Five 3. 多端口匹配器(match):&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;不能把标准匹配和多端口匹配混用: –sport 1024:65535 -m multiport –dport 21,23,80&lt;/li&gt;
  &lt;li&gt;Match : –source-port :源端口
    &lt;ul&gt;
      &lt;li&gt;iptables -A INPUT -p tcp -m multiport –source-port 22,53,80,110&lt;/li&gt;
      &lt;li&gt;最多能匹配15个不连续端口，前提-p tcp 或 -p udp才有端口&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match : –destination-port :目的端口
    &lt;ul&gt;
      &lt;li&gt;iptables -A INPUT -p tcp -m multiport –destination-port 22,53,80&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match : –port : 同端口多端口匹配，意思是它匹配的是那种源端口和目的端口是同一个端口的包, 比如: 端口80到端口80的包:
    &lt;ul&gt;
      &lt;li&gt;iptable -A INPUT -p tcp -m multiport –port 22,53,80&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;five-4-属主匹配器macth&quot;&gt;Five 4. 属主匹配器(macth)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;基于包的生成者(也就是所有者，或称作拥有者, owner)的ID来匹配包, owner可以是启动进程的用户的ID，或用户所在的组的ID或进程的ID或会话的ID.&lt;/li&gt;
  &lt;li&gt;注意: 这个扩展只能用在OUTPUT中，原因显而易见:我们几乎不可能得到发送端程序的ID的任何信息，或者在去往真正目的地哪儿有路由.&lt;/li&gt;
  &lt;li&gt;Match: –cmd-owner : 匹配命令的数组，也就是发送这个报文的进程名称:
    &lt;ul&gt;
      &lt;li&gt;iptables -A OUTPUT -m owner –cmd-owner httpd&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –uid-owner : 按生成包的用户的ID(UID)来匹配外出的包:
    &lt;ul&gt;
      &lt;li&gt;iptables -A OUTPUT -m owner –uid-owner 500&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –gid-owner : 组ID(GID):
    &lt;ul&gt;
      &lt;li&gt;iptables -A OUTPUT -m owner –gid-owner 0&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –pid-owner : 进程ID(PID):
    &lt;ul&gt;
      &lt;li&gt;iptables -A OUTPUT -m owner –pid-owner 78&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –sid-owner : 会话ID(SID, session id)
    &lt;ul&gt;
      &lt;li&gt;iptables -A OUTPUT -m owner –sid-owner 100&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;five-5-字符匹配器match&quot;&gt;Five 5. 字符匹配器(match)&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;Match: –string pattern: 指定字符串:
    &lt;ul&gt;
      &lt;li&gt;–string “baidu.com”&lt;/li&gt;
      &lt;li&gt;Example: iptables -A INPUT -m string –string “baidu.com” –algo bm -j DROP&lt;/li&gt;
      &lt;li&gt;匹配给定字符, 必须指定–algo bm或kmp算法&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –algo bm/kmp : 指定匹配算法(bm 或 kmp):
    &lt;ul&gt;
      &lt;li&gt;Example: 同上&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –from offset :
    &lt;ul&gt;
      &lt;li&gt;设置偏移从它开始寻找任何匹配。如果没有通过，默认为0。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Match: –to offset:
    &lt;ul&gt;
      &lt;li&gt;设置偏移从它开始寻找任何匹配。如果没有通过，默认为数据包的大小。&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-iptables-的动作targets和跳转jumps&quot;&gt;3. IPTABLES 的动作(targets)和跳转(jumps)&lt;/h2&gt;

&lt;h3 id=&quot;one-跳转到自定义链&quot;&gt;One. 跳转到自定义链&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -N tcp-packets&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;iptables -A INPUT -p tcp -j tcp-packets&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;two-accept-target&quot;&gt;Two. Accept target&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;一旦满足，直接ACCEPT&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;three-dnat-target&quot;&gt;Three. DNAT target&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;用来做目的地址转换, 也就是重写报文的目的地址;&lt;/li&gt;
  &lt;li&gt;如果一个报文匹配了这个规则，而且这个规则的target是DNAT, 那么这个报文以及这条连接上的所有后续报文都会被转换地址.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: DNAT只能在 NAT 表里面的PREROUTING 和 OUTPUT链上有效，或者是被这两条链调用的链里.&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意2: 包括DNAT target的链不能被除此之外的其他链调用, 如 POSTROUTING&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Target: –to-destination :
        &lt;ul&gt;
          &lt;li&gt;iptables -t nat -A PREROUTING -p tcp -d 15.45.23.67 –dport 80 -j DNAT –to-destination 192.168.1.1-192.168.10&lt;/li&gt;
          &lt;li&gt;指定要写入IP头的地址.上面离职就是把所有发往地址15.45.23.67的包都转发到一段LAN使用的私有地址，即192.168.1.1到192.168.10.在这种情况下，每个流都会被随机分配一个要转发到的地址，但同一个流总是使用同一个地址.&lt;/li&gt;
          &lt;li&gt;也可以只指定唯一一个IP地址或端口或端口范围:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;–to-destination 192.168.1.1:80&lt;/li&gt;
          &lt;li&gt;–to-destination 192.168.1.1:80-100&lt;/li&gt;
          &lt;li&gt;注意只有-p指定TCP或UDP协议才可以使用端口&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;four-snat-target-源地址转换&quot;&gt;FOur, SNAT target: 源地址转换&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;–to-source&lt;/li&gt;
  &lt;li&gt;只能用于nat表的POSTROUTING链&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;five-drop-target&quot;&gt;Five. DROP target&lt;/h3&gt;

&lt;h3 id=&quot;six-masquerade-target&quot;&gt;Six. MASQUERADE target&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;这个target和SNAT target的作用是一样的，区别是它不需要指定–to-source&lt;/li&gt;
  &lt;li&gt;只能用于nat表的POSTROUTING链，而且它只有一个选项(不是必须的)&lt;/li&gt;
  &lt;li&gt;Options:
    &lt;ul&gt;
      &lt;li&gt;–to-ports :
        &lt;ul&gt;
          &lt;li&gt;iptables -t nat -A POSTROUTING -p tcp -j MASQUERADE –to-ports 1024-31000&lt;/li&gt;
          &lt;li&gt;在指定TCP或UDP的前提下，设置外出包能使用的端口，方式是单端口, 如–to-ports 1025, 或者端口范围, –to-ports 1024-4000.&lt;/li&gt;
          &lt;li&gt;注意，范围用连字符.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;seven-redirect-target-在防火墙所在的机子内部转发包或流到另一个端口&quot;&gt;Seven. REDIRECT target: 在防火墙所在的机子内部转发包或流到另一个端口&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;例如，可以把所有去往端口HTTP的包REDIRECT到HTTP proxy（例如squid）,当然这都发生在自己主机的内部.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意, 它只能在nat表的PREROUTING、OUTPUT链和被它们调用的自定义里.&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Options: –to-ports :
    &lt;ul&gt;
      &lt;li&gt;Example: iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-ports 8080&lt;/li&gt;
      &lt;li&gt;在指定TCP或UDP协议的前提下，定义目的端口:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;不使用这个选项，目的端口不会改变&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;指定一个端口, –to-ports 8080&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;指定端口范围, –to-ports 8080-8090&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;举栗子:
    &lt;ul&gt;
      &lt;li&gt;将外网访问本地端口8022转发到本地端口22:
        &lt;ul&gt;
          &lt;li&gt;iptables -t nat -A PREROUTING -p tcp –dport 8022 -j REDIRECT –to-ports 22&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;将内网访问本地端口8022转发到22端口:
        &lt;ul&gt;
          &lt;li&gt;iptables -t nat -A OUTPUT -p tcp –dport 8022 -j REDIRECT –to-ports 22&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;eight-reject-target&quot;&gt;Eight. REJECT target&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;REJECT 和 DROP 基本一样,区别在于它出了阻塞包之外，还向发送者返回错误信息.&lt;/li&gt;
  &lt;li&gt;只能用于 INPUT、FORWARD、OUTPUT和它们的子链(自定义链)&lt;/li&gt;
  &lt;li&gt;Option: –reject-with:
    &lt;ul&gt;
      &lt;li&gt;Example: iptables -A FORWARD -p TCP –dport 22 -j REJECT –reject-with tcp-reset&lt;/li&gt;
      &lt;li&gt;返回的信息类型:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-net-unreachable&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-host-unreachable&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-port-prohibited&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-proto-unreachable&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-bet-prohibited&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;icmp-host-prohibited&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;echo-reply&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;tcp-reset # 主要用来阻塞身份识别探针&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nine-return-target-返回上一层&quot;&gt;NINE. RETURN target: 返回上一层&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;规则的顺序: 子链 –&amp;gt; 父链 –&amp;gt; 缺省的策略:
    &lt;ul&gt;
      &lt;li&gt;即 若包在子链上遇到了RETURN, 则返回父链的下一条规则继续进行比较;&lt;/li&gt;
      &lt;li&gt;若在父链(主链，如INPUT)遇到了RETURN, 则使用缺省的策略(一般是ACCEPT或DROP).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/08/iptables-basic.html</link>
    <guid>/2015/04/08/iptables-basic</guid>
    <pubDate>Wed, 08 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux Shadowsocks 全局代理</title>
    <description>
&lt;h1 id=&quot;linux用-iptables--ss-redir-为-shadowsocks-全局代理-shell脚本下载地址&quot;&gt;Linux用 iptables + ss-redir 为 Shadowsocks 全局代理 &lt;a href=&quot;/scripts/linux-shdowsocks-global.sh&quot;&gt;Shell脚本下载地址&lt;/a&gt;&lt;/h1&gt;

&lt;h2 id=&quot;1-create-new-chain-on-nat-table&quot;&gt;1. create new chain on nat table&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;iptables -t nat -N SHADOWSOCKS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-ignore-shdowsockss-address-avoid-loop&quot;&gt;2. Ignore shdowsocks’s address, avoid loop&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d YOUR-SERVER-IP -j RETURN&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-ignore-lans-and-any-other-addresses-youd-like-to-bypass-the-proxy&quot;&gt;3. Ignore LANs and any other addresses you’d like to bypass the proxy&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN&lt;/li&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;4-anything-else-should-be-redirected-to-shadowsockss-local-port&quot;&gt;4. Anything else should be redirected to shadowsocks’s local port&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT –to-ports LOCAL-PORT&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;5-apply-the-rules&quot;&gt;5. Apply the rules&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;6-start-the-shadowsocks-redir&quot;&gt;6. Start the shadowsocks-redir&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;ss-redir -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;7-已经写好的shell脚本&quot;&gt;7. 已经写好的shell脚本&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/scripts/linux-shdowsocks-global.sh&quot;&gt;下载地址&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;参考-shadowsocks-openwrt&quot;&gt;参考: &lt;a href=&quot;https://github.com/haohaolee/shadowsocks-openwrt&quot;&gt;shadowsocks-openwrt&lt;/a&gt;&lt;/h3&gt;

</description>
    <link>/2015/04/07/shadowsocks-global-by-iptables.html</link>
    <guid>/2015/04/07/shadowsocks-global-by-iptables</guid>
    <pubDate>Tue, 07 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>为 ubuntu 14.04 上 4.0 kernel</title>
    <description>
&lt;h2 id=&quot;原因&quot;&gt;原因:&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;内核太老，强迫症，想换内核，但是又不想自己编译，毕竟对内核不了解，并且编译过程中有各种问题…所以，就从官方已经编译打包好的包来安装…&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;1-下载-需要的-image-header等文件3个&quot;&gt;1. 下载 需要的 image, header等文件(3个):&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.0-rc7-vivid/linux-headers-4.0.0-040000rc7_4.0.0-040000rc7.201504061936_all.deb&quot;&gt;linux-headers-4.0.0-040000rc7_4.0.0-040000rc7.201504061936_all.deb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.0-rc7-vivid/linux-headers-4.0.0-040000rc7-generic_4.0.0-040000rc7.201504061936_amd64.deb&quot;&gt;linux-headers-4.0.0-040000rc7-generic_4.0.0-040000rc7.201504061936_amd64.deb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.0-rc7-vivid/linux-image-4.0.0-040000rc7-generic_4.0.0-040000rc7.201504061936_amd64.deb&quot;&gt;linux-image-4.0.0-040000rc7-generic_4.0.0-040000rc7.201504061936_amd64.deb&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-安装&quot;&gt;2. 安装&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;sudo dpkg -i linux-*  // 也就是这三个deb包&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3-更新启动项理论上在上一步会自动更新&quot;&gt;3. 更新启动项，理论上在上一步会自动更新:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;sudo update-grub&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4-reboot-即可&quot;&gt;4. reboot 即可&lt;/h3&gt;
</description>
    <link>/2015/04/07/renew-ubuntu-14-04-kernel.html</link>
    <guid>/2015/04/07/renew-ubuntu-14-04-kernel</guid>
    <pubDate>Tue, 07 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>adb 简单运用之启动LinuxOnAndroid</title>
    <description>
&lt;h2 id=&quot;0-原因-linuxonandroid&quot;&gt;0. 原因: LinuxOnAndroid&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; 主要是因为自己有架Android手机主板出问题了，屏幕一直花屏，就想拿来玩玩LinuxOnAndroid, 但是屏幕花屏严重，基本看不了，但是偶尔恢复，所以就想从adb shell 来启动LinuxOnAndroid, 我用的是Ubuntu12.04版本, 适合android4.0-4.2, 可以拿来玩服务。。。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;1-手机&quot;&gt;1. 手机:&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1. 打开Debug模式，并用数据线连接电脑
* 2. 最好确保手机已经root
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-ubuntu-1404&quot;&gt;2. Ubuntu 14.04:&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1. 将/path/to/sdk/platform-tools加入/etc/profile环境变量,但是必须重启 或者 直接进入/path/to/sdk/platform-tools目录
* 2. sudo ./adb kill-server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-可能手机不识别&quot;&gt;3. 可能手机不识别:&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1. sudo vim /etc/udev/rules.d/51-android.rules (该文件一般不存在)
* 2. lsusb 查看:
    * 1. 我的usb: Bus 003 Device 003: ID `0bb4`:`0c03` HTC (High Tech Computer Corp.) 
    * 2. 需要的数据: `0bb4` 和 `0c03`
* 3. 在/etc/udev/rules.d/51-android.rules 添加:
    * `SUBSYSTEM==&quot;usb&quot;, ATTRS{idVendor}==&quot; 0bb4&quot;, ATTRS{idProduct}==&quot;0c03&quot;,MODE=&quot;0666&quot;`
    * sudo chmod a+x /etc/udev/rules.d/51-android.rules
* 4. 重启udev: sudo /etc/init.d/udev restart
* 5. 拔掉usb线重新插入
* 6. 现在大概可以识别手机了
* 7. sudo ./adb kill-server
* 8. 连接: sudo ./adb shell # 用sudo, 否则可能出现 insufficient permissions for device 问题
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;4-adb-shell-之后&quot;&gt;4. adb shell 之后:&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1. 使用root权限: su # 请确保已经root
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;5-我今天用adb-shell-的目的运行linux-on-android&quot;&gt;5. 我今天用adb shell 的目的，运行Linux On Android&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* [项目下载地址](http://sourceforge.jp/projects/sfnet_linuxonandroid/releases/)
* 下载 [bootscript.sh](http://sourceforge.jp/projects/sfnet_linuxonandroid/downloads/bootscript.sh) 适用于Android4.0, 或 [bootscript4-3.sh](http://sourceforge.jp/projects/sfnet_linuxonandroid/downloads/bootscript4-3.sh)适用于Android4.3以后
* 将 bootscript.sh 或 bootscript4-3.sh 放到和 ubuntu.img目录下
* sudo adb shell 进入 (如失败，查看上几步)
* cd /path/to/ubuntu.img
* su # 提取root权限
* sh bootscript.sh 或者 sh bootscript4-3.sh 即可启动 LinuxuOnAndroid
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;lsusb 结果:
...
Bus 001 Device 003: ID 0a5c:21e3 Broadcom Corp. HP Portable Valentine
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 0bb4:0c03 HTC &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;High Tech Computer Corp.&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 
Bus 003 Device 002: ID 1bcf:0005 Sunplus Innovation Technology Inc. 
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/04/05/linux-on-android.html</link>
    <guid>/2015/04/05/linux-on-android</guid>
    <pubDate>Sun, 05 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>PHP 面向对象</title>
    <description>
&lt;h2 id=&quot;1-面向对象object-oriented基本概念&quot;&gt;1. 面向对象(Object Oriented)基本概念&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象的定义:
        &lt;ul&gt;
          &lt;li&gt;世间万物皆对象: 可见和不可见之物&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象的基本组成, 包含两部分:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;(属性，成员变量)对象的组成元素:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;是对象的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数据模型&lt;/code&gt;，用于描述对象的数据&lt;/li&gt;
          &lt;li&gt;又被称为对象的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;属性&lt;/code&gt;，或者对象的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;成员变量&lt;/code&gt;
    * 2. (方法)对象的行为:&lt;/li&gt;
          &lt;li&gt;对象的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;行为模型&lt;/code&gt;, 用于描述对象能够做什么&lt;/li&gt;
          &lt;li&gt;又被称为对象的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;方法&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象的特点:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;每个对象都独一无二&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;对象是体格特定事物,他的职能是完成特定功能&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;对象可以重复使用&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;什么是面向对象:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;向对象就是在编程的时候一直把对象放在心上&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;面向对象编程就是在编程的时候数据结构(数据组织方式)都通过对象的结构进行存储。:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;利用属性+方法存储数据&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;为什么使用面向对象:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;认识:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;(符合行为思维习惯)对象的描述方式更加贴近真实的世界，有利于大型业务的理解&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;在程序设计的过程中用对象的视角分析世界的时候能够拉近程序设计和真实世界的距离
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;实质:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;面向对象就是把生活中要解决的问题都用对象的方式进行存储:
                &lt;ul&gt;
                  &lt;li&gt;属性 + 方法&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;对象与对象之间通过方法的调用完成互动:
                &lt;ul&gt;
                  &lt;li&gt;方法(的调用)&lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;面向对象实例解析: 打篮球球员(对象) + 球员之间的互动(方法)&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;面向对象的基本思路:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;第一步: 识别对象:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;任何实体都可以被识别为一个对象
    * 2. 第二步: 识别对象的属性:&lt;/li&gt;
          &lt;li&gt;对象里面存储的数据被识别为属性&lt;/li&gt;
          &lt;li&gt;对于不同的业务逻辑，关注的数据不同，对象里面的属性也不同
    * 3. 第三步: 识别对象的行为(方法):&lt;/li&gt;
          &lt;li&gt;对象自己属性数据的改变&lt;/li&gt;
          &lt;li&gt;对象和外部交互&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;面向对象的基本原则:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;对象内部是高内聚的:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;对象只负责一项特定的职能(职能可大可小)&lt;/li&gt;
          &lt;li&gt;所有对象相关的内容都封装到对象内部
    * 2. 对象对外是低耦合的: public, private, protected&lt;/li&gt;
          &lt;li&gt;外部世界可以看到对象的一些属性(不是全部)&lt;/li&gt;
          &lt;li&gt;外部世界可以看到对象的一些方法(并非全部)&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-php中的面向对象实践&quot;&gt;2. PHP中的面向对象实践&lt;/h2&gt;

&lt;h3 id=&quot;1-基本实践&quot;&gt;1. 基本实践&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;类的概念:
        &lt;ul&gt;
          &lt;li&gt;有共同的属性和方法, 抽象的、一般的、一类的&lt;/li&gt;
          &lt;li&gt;物理类聚, 具有相似属性&lt;/li&gt;
          &lt;li&gt;类定义了这些相似对象拥有的相同属性和方法&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;类是相似对象的描述，称为类的定义，是该类对象的蓝图或者原型&lt;/code&gt;&lt;/li&gt;
          &lt;li&gt;类的对象称为类的一个实例，具体到一个类产生的一个实际个体&lt;/li&gt;
          &lt;li&gt;类的属性和方法统称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;类成员&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;实例化概念:
        &lt;ul&gt;
          &lt;li&gt;类的实例化(Instantiate)就是通过类的定义创建一个类的对象&lt;/li&gt;
          &lt;li&gt;一个类可以很多实例, 实例是给类成员附上具体的属性值或方法体&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;2.5 类的定义和实例化:
    &lt;ul&gt;
      &lt;li&gt;可在终端执行php: php5 -f phpfile.php&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;?php&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 类的定义以以关键字class开始, 后面跟着类名，类名通常第一个字母大写。&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 类以中括号开始，中括号结束.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NbaPlayer&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;public&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Jordan&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$height&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;198cm&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$weight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;98kg&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$team&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Bull&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$playerNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;23&quot;&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;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;run&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Running&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&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;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jump&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Jumping&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&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;span class=&quot;c1&quot;&gt;// 类到对象的实例化&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 类的实例化为对象使用关键字new, new之后紧跟类的名称和一对括号&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$jordan&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;nc&quot;&gt;NbaPlayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 类的属性和方法的访问用: -&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 访问公共属性&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$jordan&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&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;nv&quot;&gt;$jordan&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;构造函数&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;析构函数&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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.1 构造函数，在对象实例化时被调用&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 1.2. php 没有重载概念，所以不能同名方法&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 1.3. 构造函数出现了，实例化时必须符合类的构造函数形式，否则奔溃&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$weight&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;In constructor&amp;lt;br /&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// $this是php里面的伪变量(我更喜欢叫它指向类自身的类变量), 表示变量自身&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 最好使用$this-&amp;gt;指明，否则不明确&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// 注意: $this-&amp;gt;name 表示 类的$name变量, 错误用法: $this-&amp;gt;$name&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;//    $this-&amp;gt;$name 是值 $name的值作为变量&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;weight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$weight&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;c1&quot;&gt;// 4. 析构函数是在对象使用完时自动调用&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 4.1 先new的类实例后destroy&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 4.2 析构函数用于释放资源，例如变量，打印机等&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__destruct&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Destroy &quot;&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br /&amp;gt;&quot;&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;c1&quot;&gt;// 类外,类实例$james&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 通过把变量设置为null, 可以触发析构函数的调用&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$james&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;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;数据访问&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象引用的概念:&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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. 引用包括: 独立引用 和　共享引用&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$james1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$james&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;c1&quot;&gt;//   不准确的说当$james = null; 时本该触发__destruct(), &lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 但是$james1 = $james; 注意这也是对象引用，只是让$jame1指向$james指向的对象&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 类似指针, 对象存在一块内存区域，$james1 和 $james都指向它&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 所以,&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 准确的说: 当对象不会再被使用使，将会调用__destruct()函数&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 对象引用类似变量的别名，实际上还是一个变量，&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//   当其中一个变量$james = null触发__destruct(),&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//  此时其他对象引用将为未定义,不能再被使用&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$james2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$james&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;nv&quot;&gt;$james&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;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\$&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;james 将被已经被结束&quot;&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;h3 id=&quot;2-高级实践&quot;&gt;2. 高级实践&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象的继承(extends):
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;共同属性和方法，继承同一个基类&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;不必再重复定义属性和方法&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;直接调用父类的方法和属性&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;子类可以修改和挑战父类定义的类成员: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;重写(Overwrite)&lt;/code&gt;&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;注意: protected 主要用于继承，子类可见，类外不可见&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;只能单继承，不支持多继承&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Human&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;mf&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 子类继承父类是，可以直接访问父类public和protected属性和方法&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NbaPlayer&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Human&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;mf&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;对象的访问控制:
        &lt;ul&gt;
          &lt;li&gt;public : 公有的类成员，可以在任何地方被访问:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;定义该成员的类(自身)、该类的子类、其他类
    * protected : 受保护的类成员，可以被自身及其子类访问
    * private : 私有的类成员，职能被自身访问&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Static(静态)关键字: public static $president=”Me”;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;静态属性用于保存类的公有数据&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;静态方法里面只能访问静态属性&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;静态成员不需要实例化对象就可以访问&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;类的内部可以通过self或者static关键字访问&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以通过parent关键字访问父类静态属性和方法&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以通过类名在外部访问类的静态成员&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NbaPlayer&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Human&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$president&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;David&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;changePresident&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$newPresident&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;c1&quot;&gt;// 注意，如果类内想访问静态成员属性&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    1. 声明静态方法&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//    2. self::静态变量&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$president&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$newPresident&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;parent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$humanStatic&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$newPresident&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;span class=&quot;c1&quot;&gt;// 调用静态方法&lt;/span&gt;
&lt;span class=&quot;nc&quot;&gt;NbaPlayer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;changePresident&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Adam&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;NbaPlayer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$president&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br /&amp;gt;&quot;&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;重写&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Final 关键字: public final 成员变量;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;相当于声明常量，一经定义不允许修改&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;方法支持缺省参数&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;重写Overwrite, 只要方法名一样即可，参数随意&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;final class ClassName: 不允许被继承&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;数据访问补充:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;parent 关键字可以访问父类中被重写的成员变量&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;self关键字可以用于访问类自身的成员方法，也可以用于访问自己的静态成员和类常量；不能用于访问类自身的属性;使用常量的时候不需要在常量(const CONST-VALUE = “A”;)前面添加$符号&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;static 关键字用于访问类自身的静态成员，访问静态属性时需要在属性前面添加$符号;&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;const CONST_VALUE =  “ABC”;&lt;/li&gt;
          &lt;li&gt;self::CONST_VALUE;&lt;/li&gt;
          &lt;li&gt;static::$staticValue;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;接口:
        &lt;ul&gt;
          &lt;li&gt;接口就是把不同类的共同行为进行定义，然后在不同的类里面实现不同的功能&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;interface – implements&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;?php&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// interface 关键字用于定义接口&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;interface&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ICanEat&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;public&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&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;c1&quot;&gt;// implements关键字用于表示类实现某个接口&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Human&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;implements&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ICanEat&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;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&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;c1&quot;&gt;// TODO: Implement eat() method.&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Human is eating &quot;&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br /&amp;gt;&quot;&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;span class=&quot;nv&quot;&gt;$obj&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;nc&quot;&gt;Human&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$obj&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Banana&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;var_dump($obj instanceof ICanEat) :
        &lt;ul&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;可以用instanceof关键字来判断某个对象是否实现了某个接&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;interface ICanPee extends ICanEat {} : 接口可以继承接口
        &lt;ul&gt;
          &lt;li&gt;类实现接口时，要实现接口的所有方法，包括接口继承的接口&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;多态:
        &lt;ul&gt;
          &lt;li&gt;不用类对接口的同一方的具体实现是不同的，这叫&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;多态&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;抽象类 abstract class:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;接口里面的方法是没有实现的，二类里面的方法都是有实现的, 抽象类: 只有一部分要实现&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;比较:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;abstract 用于定义抽象类，在方法前加abstract关键字，则该方法不需要实现&lt;/li&gt;
          &lt;li&gt;在抽象类中可以包含普通方法&lt;/li&gt;
          &lt;li&gt;继承抽象类: extends&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;abstract&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ACanEat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;breath&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Breath air&amp;lt;br /&amp;gt;&quot;&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;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Human&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ACanEat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Human eats &quot;&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br /&amp;gt;&quot;&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;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Animal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ACanEat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&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;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Animal eats &quot;&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$food&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br /&amp;gt;&quot;&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;h3 id=&quot;3-特殊实践-php的魔术方法&quot;&gt;3. 特殊实践: PHP的魔术方法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__construct(), __destruct()&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__tostring():
        &lt;ul&gt;
          &lt;li&gt;当对象被当做String使用时，这个方法被自动调用.&lt;/li&gt;
          &lt;li&gt;echo $obj;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__invoke($var):
        &lt;ul&gt;
          &lt;li&gt;当对象被当初方法方法调用是，这个方法被自动调用&lt;/li&gt;
          &lt;li&gt;$obj(4);&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__call(), __callStatic(): 这两个方法可以被重载(overloading is not overriding)
        &lt;ul&gt;
          &lt;li&gt;__call($funcName, $funcArgumentsArray):&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;当对象访问不存在的方法是被自动调用&lt;/li&gt;
          &lt;li&gt;implode(“, “, $arrayVar): 把数组用”,”合并成字符串
    * static __callStatic($funcName, $funcArgumentsArray):&lt;/li&gt;
          &lt;li&gt;当对象访问不存在的静态方法时被自动调用&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__get($name), __set($name, $value), __isset($obj-&amp;gt;attributeName), __unset():
        &lt;ul&gt;
          &lt;li&gt;在给不可访问属性&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;赋值&lt;/code&gt;是，__set()会被调用&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;读取&lt;/code&gt;不可访问属性的值是，__get()会被调用&lt;/li&gt;
          &lt;li&gt;当对不可访问属性调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isset()&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;empty()&lt;/code&gt;是，__isset()被调用&lt;/li&gt;
          &lt;li&gt;当对不可访问属性调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unset()&lt;/code&gt;是, __unset()被调用&lt;/li&gt;
          &lt;li&gt;所谓不可访问属性，实际上就是在调用某个属性时发现没被定义&lt;/li&gt;
          &lt;li&gt;这几个方法称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;属性重载&lt;/code&gt;的魔术方法&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;__clone():
        &lt;ul&gt;
          &lt;li&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
    <link>/2015/04/04/PHP-Object-Oriented.html</link>
    <guid>/2015/04/04/PHP-Object-Oriented</guid>
    <pubDate>Sat, 04 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Ubuntu Server 配置 LAMP</title>
    <description>
&lt;h2 id=&quot;1-environment&quot;&gt;1. Environment&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Ubuntu 14.10 Server&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;LAMP = Linux + Apache + Mysql/MariaDB + PHP&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-installation&quot;&gt;2. INSTALLATION&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Apache:
        &lt;ul&gt;
          &lt;li&gt;sudo apt-get install apache2&lt;/li&gt;
          &lt;li&gt;查看版本: apache2 -v # 这里已经上 2.4版本，和2.2不同&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Php :
        &lt;ul&gt;
          &lt;li&gt;sudo apt-get install php5&lt;/li&gt;
          &lt;li&gt;查看是否被加载: cat /etc/apache2/mods-enabled/php5.load 证明被加载&lt;/li&gt;
          &lt;li&gt;查看版本: php5 -v&lt;/li&gt;
          &lt;li&gt;如果未被加载, 可使用 sudo a2enmod php5&lt;/li&gt;
          &lt;li&gt;如果/etc/apache2/mod-available/下没有php5相关mod:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;sudo apt-get install libapache2-mod-php5&lt;/li&gt;
          &lt;li&gt;sudo a2enmod php5&lt;/li&gt;
          &lt;li&gt;sudo service apache2 restart 即可&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Mysql:
        &lt;ul&gt;
          &lt;li&gt;sudo apt-get install mysql-server&lt;/li&gt;
          &lt;li&gt;查看mysql是否被php加载: cat /etc/php5/conf.d/mysql.ini :&lt;/li&gt;
          &lt;li&gt;查看mysql是否被php加载 或者: cat /etc/php5//mods-available/mysql.ini :&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;php默认没有mysql扩展，为了加载 mysql.so : sudo apt-get install php5-mysql&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;apache2 php5 mysql php5-mysql
更简单的方法: &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;tasksel &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;lamp-server&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;注意: tasksel 提供 LAMP / DNS server / Mail server .. 的安装&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-make-sure-them-work-correctly&quot;&gt;3. Make sure them work correctly.&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;sudo service mysql restart&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;sudo service apache2 restart&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;4-创建phpinfo服务器探针&quot;&gt;4. 创建phpinfo服务器探针&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;cd /var/www/html&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;sudo vim info.php&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;?php&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;mysql_connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;localhost&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;root&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;root&apos;&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;s1&quot;&gt;&apos;It works.&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;It doesn\&apos;t work&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;phpinfo&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;检查是否成功: 访问 http://服务器IP/info.php&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;5-给php添加常用扩展&quot;&gt;5. 给PHP添加常用扩展&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;php5-gd curl libcurl3 libcurl3-dev php5-curl :
        &lt;ul&gt;
          &lt;li&gt;sudo apt-get install php5-gd curl libcurl3 libcurl3-dev php5-curl&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;gd :&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;curl :&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;重启服务，使模块生效:sudo service apache2 restart&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查看模块是否生效:&lt;/li&gt;
      &lt;li&gt;查看: cat /etc/php5/mods-available/…&lt;/li&gt;
      &lt;li&gt;或者 浏览器访问: http://服务器IP/info.php, 搜索 gd, curl&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;sftp 命令&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;vsftpd —- FTP 服务器&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;或者用 FileZilla 配置客户端&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;6-lamp环境文件目录概述&quot;&gt;6. LAMP环境文件目录概述&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Linux系统配置文件目录: /etc :
        &lt;ul&gt;
          &lt;li&gt;Apache : /ect/apache2&lt;/li&gt;
          &lt;li&gt;mysql : /etc/mysql&lt;/li&gt;
          &lt;li&gt;php : /etc/php5&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Apache2 配置 (/ect/apache2):
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;加载流程:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;首先加载 apache2.conf&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;然后在apache2.conf 通过Include 加载其他文件/模块:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;conf-enabled/*&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;httpd.conf&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;ports.conf&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;mods-enabled/*&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;sites-enabled/*&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;核心配置:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;mods-*** Apache模块&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;sites-*** 虚拟主机
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;关键字:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;available 可用; enabled 已经启用.&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;(创建需要启用的mod, 软连接available到enabled) :
                &lt;ul&gt;
                  &lt;li&gt;enabled —-&amp;gt; available: ln -s 命令 建立软连接&lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;4, 虚拟主机配置(Virtual-Host):&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;客户端模拟DNS解析, 配置DNS, 即修改客户端hosts(Linux: /etc/hosts)文件:
                &lt;ul&gt;
                  &lt;li&gt;192.168.1.106 video.cc.com&lt;/li&gt;
                  &lt;li&gt;192.168.1.106 bbs.cc.com&lt;/li&gt;
                  &lt;li&gt;192.168.1.106 oa.cc.com&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;在服务器创建三个目录，分别用于三个url:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;cd /&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;sudo mkdir -p /wwwroot/{video,bbs,oa} # 注意: shell 不要随便空格, big problem.&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;分别在三个子目录创建index.html, 内容仅作标识 , 例如 Here is xx Directory.&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;Apache2 中配置虚拟主机:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;配置文件: cd /etc/apache2/sites-available/000-default.conf&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;复制三个配置文件(最好以.conf结尾):&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;cp 000-default.conf video.conf&lt;/li&gt;
                  &lt;li&gt;cp 000-default.conf bbs.conf&lt;/li&gt;
                  &lt;li&gt;cp 000-default.conf oa.conf
    * 3. 分别配置(例video.conf):&lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;设置服务器根目录: DocumentRoot 目录: 将DocumentRoot /var/www/html 改为 DocumentRoot /wwwroot/video&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;设置ServerName对应域名, 让Apache服务器自动区分域名: ServerName video.cc.com&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;配置Directory, 拒绝403Forbidden: &amp;lt;Directory /var/www/&amp;gt; 改为 &amp;lt;Directory /wwwroot/video/&amp;gt; , 可能添加以下代码&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;Directory /&amp;gt;
        Options FollowSymLinks
        AllowOverride None
    &amp;lt;/Dorectory&amp;gt;

    &amp;lt;Directory /wwwroot/video/&amp;gt;
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        &lt;span class=&quot;c&quot;&gt;# Order allow, deny # Apache2 2.2&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# allow from all&lt;/span&gt;
        Require all granted &lt;span class=&quot;c&quot;&gt;# Apache2 2.4 &lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# 详情查看: [Apache2 2.4 升级变化](http://httpd.apache.org/docs/2.4/upgrading.html)&lt;/span&gt;
    &amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;            * 4. 启用site配置: ln 软连接sites-available到sites-enabled:
                * cd sites-enabled; sudo ln -s ../sites-available/video video.conf 
                * &amp;gt; 注意：这里必须是.conf结尾的文件，否则服务器可能不识别
            * 5. 在/etc/apache2/apache2.conf配置文件中添加 ServerName cc.com, 否则可能警告没有全局ServerName
            * 6. 在/etc/apache2/apache2.conf配置文件中注释&amp;lt;Directory &amp;gt;相关
            * 7. 注意如果访问域名不存在，默认不一定是default.conf文件，而是按顺序，在/etc/apache2/sites-enabled文件夹中的第一个配置文件，所以就是为什么sites-available有000-default.conf了，所以在ln到sites-enabled时注意default配置文件应该数字字母排在第一个,例如 ln -s ../sites-available/000-default.conf 000-default.conf
            * 8. 重启Apache服务器, 就可以访问 video.cc.com了: sudo service apache2 restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Mysql 配置 (/etc/Mysql/my.conf):
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;Mysql数据存储目录迁移:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;先停止MySQL服务，杜绝数据迁移产生的不良后果: sudo service mysql stop&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;创建数据迁移的目标文件夹(注意权限和默认配置要一直), MySQL默认数据存储目录在/var/lib/mysql中:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;cd /&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;sudo mkidir /mysqldata&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;修改用户组和所属用户为mysql: sudo chown -vR mysql:mysql /mysqldata&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;修改权限为700: sudo chmod -vR 700 /mysqldata&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;迁移数据，即复制/var/lib/mysql到/mysqldata:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
                &lt;ul&gt;
                  &lt;li&gt;sudo su&lt;/li&gt;
                  &lt;li&gt;cp -av /var/lib/mysql /mysqldata # -a表示保存原文件权限等
    * 6. 修改MySQL配置文件/etc/mysql/my.cnf:&lt;/li&gt;
                  &lt;li&gt;修改datadir(指定数据存储目录)的值: /var/lib/mysql 改为 /mysqldata
    * 7. 这步很重要: 修改apparmor对mysql的保护配置:&lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;sudo vim /etc/apparmor.d/usr.sbin.mysqld&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;修改有关/var/lib/mysql的配置:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash 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;# /var/log/mysql/ r,&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# /var/log/mysql/** rwk,&lt;/span&gt;
/mysqldata/ r,
/mysqldata/&lt;span class=&quot;k&quot;&gt;**&lt;/span&gt; rwk,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        * 8. 重启 apparmor 服务: sudo service apparmor reload:
            * ubuntu 14.10 上报错: reload: Unknown instance:,是软件本身bug=-=, 重启系统也行
        * 9. 重启 mysql 服务: sudo service mysql start
        * 10. 测试数据迁移是否成功:
            * 1. mysql创建新的数据库时会在datadir目录下创建同名文件夹
            * 2. mysql -uroot -p
            * 3. create database cole;
            * 4. show database cole;
            * 5. quit
            * 6. 查看 /mysqldata下有没有创建新目录cole
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Php 配置 (/etc/php5/apache2/php.ini)
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;PHPMyAdmin的安装:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;sudo apt-get install phpmyadmin&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;看安装过程说明，配置&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;不一定必要: sudo ln -s /usr/share/phpmyadmin/ /var/www/pma ()&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;访问: 192.168.1.106/phpmyadmin
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;开启MySQL的remote access:&lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;修改配置: sudo vim /etc/mysql/my.cnf&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;找到 bind-address, 注释掉 或者 修改为 0.0.0.0&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;在数据库名为mysql的user表单中添加一个公网可以访问的用户, 终端打开或者phpmyadmin打开添加均可&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;Insert 一条数据: (如果看不懂英文, PHPMyAdmin可以选择中文)
                &lt;ul&gt;
                  &lt;li&gt;Host : %  // % 代表任意IP&lt;/li&gt;
                  &lt;li&gt;User : remote&lt;/li&gt;
                  &lt;li&gt;Password : 123456&lt;/li&gt;
                  &lt;li&gt;权限自己看情况选择开启: 默认全关闭&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;重启mysql: sudo service mysql restart&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;了解一种简单的LAMP集群:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;负载均衡Nginx + Apache + PHP + MySQL&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/02/Ubuntu-LAMP.html</link>
    <guid>/2015/04/02/Ubuntu-LAMP</guid>
    <pubDate>Thu, 02 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux Tar</title>
    <description>
&lt;h2 id=&quot;tar-用法&quot;&gt;Tar 用法:&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 虽然一直都在用这个命令，但是一般也只是解压、压缩，并没有用到其他
* 今天好好写点常用的的用法
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;先讲讲常用选项&quot;&gt;先讲讲常用选项:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* -c 创建一个新归档，也就是压缩啦
* -x 从归档中抽取文件，也就是解压整个压缩包所有文件
* -C 指定文件被解压文件存放的文件夹(必须已存在)，一般和-x一起使用; 可选项
* -v 显示文件归档进度，也就是压缩／解压等过程
* -f (用于指定压缩或解压等具体文件名, 一般不独立使用):
    * 当与-c一起使用时，-f用于指定常见压缩文件的文件名，没有-f或报错: 压缩文件不存在
    * 当与-x一起使用时，-f指定要被压缩的文件名, 否则没文件怎么解压
* -t 显示包括在tar文件中的文件列表
* -u 向压缩文档中添加新文件，或更新文件
* --delete 删除某个/某些文件
* 3种压缩格式:
    * -z : 最常用之一, 使用gzip来压缩/解压tar文件, 文件名: .tar.gz, .tgz
    * -j : 最常用之一，使用bzip2来压缩/解压tar文件, 文件名: tar.bz2 等
    * -J : 使用xz方式压缩解压tar文件, 比较少用，但是压缩率非常高，kernel.org的内核源文件一般都是这种压缩格式, 文件名: .tar.xz等
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;常用的几种&quot;&gt;常用的几种:&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1. 解压文件:
    * tar.gz，tgz文件: tar -zxvf filename.tar.gz/filename.tgz -C 指定被解压的文件夹
      * `-C 是可选项`, 如果没-C则默认是当前文件夹
    * tar.bz2等文件: tar -jxvf filename.tar.bz2
    * tar.xz等文件: tar -Jxvf filename.tar.xz
* 2. 压缩文件:
    * tar.gz, tgz文件: tar -zcvf 压缩后的文件名.tar.gz 要被压缩的文件或文件夹
      * `压缩后，原文件/文件夹都还在`
    * tar.bz2 : ... -j
    * tar.zx : ... -J
* 3. 只查看压缩文件，不解压:
    * 查看所有: tar -ztvf filename.tar.gz
    * 查看关键字文件: 借助 grep: tar -ztvf filename.tar.gz | grep -i keyword
* 4. 向已存在的文档中添加新文件(不一定不存在，更新也可以, 记得指明压缩文件中的相对路劲)
  * tar -uvf filename.tar file1 \[ file2... \]
* 5. 删除某个或某个文档中的文件:
    * tar --delete -vf file.tar 必须指明归档文件中要被删除的具体的路径的文件
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;注意: 归档: 只是把文件打包, tarball, &lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-cvf&lt;/span&gt; file.tar &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;注意是tar格式&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      压缩: 有多中压缩方式 &lt;span class=&quot;nb&quot;&gt;gzip&lt;/span&gt; / bzip2 / xz等
      其实: tar.gz &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; + gz，也就是 先打包成tar文件，再压缩:
          &lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; 1. &lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-cvf&lt;/span&gt; file.tar file1 file2 directory1
          &lt;span class=&quot;o&quot;&gt;==&amp;gt;&lt;/span&gt; 2. &lt;span class=&quot;nb&quot;&gt;gzip&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; file.tar &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; file.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 6. 提取单个文件:
    * tar -zxvf file.tar.gz &quot;./new/abc.txt&quot;
* 7. 提取多个文件:
    * tar -zxvf file.tar.gz &quot;./new/abx.txt&quot; &quot;./new/ccc.txt&quot;
* 8. 使用通配符解压多个文件:
    * tar -zxvf filename.tar.gz --wildcards &quot;*.txt&quot;
* 9. `通过tar进行备份`:
    * `tar -zcvf backup-file-$(date +%Y%m%d).tar.gz filesOrDirectories`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/04/01/linux-tar.html</link>
    <guid>/2015/04/01/linux-tar</guid>
    <pubDate>Wed, 01 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Gitcafe Pages</title>
    <description>&lt;h2 id=&quot;将博客搬到-gitcafe&quot;&gt;将博客搬到 gitcafe&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;在gitcafe创建一个项目: 和用户名一样, 我的是 whatwewant&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;必须提交到GitCafe的 gitcafe-pages分支:
        &lt;ul&gt;
          &lt;li&gt;git push -u origin master:gitcafe-pages&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;访问: whatwewant.gitcafe.io 即可&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;一个项目同时使用两个或多个远程仓库&quot;&gt;一个项目同时使用两个或多个远程仓库&lt;/h2&gt;

&lt;div class=&quot;language-bash 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;remote &lt;span class=&quot;s2&quot;&gt;&quot;gitcafe&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    fetch &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; +refs/heads/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;:refs/remotes/gitcafe/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;
    url &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@gitcafe.com:whatwewant/whatwewant.git
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;remote &lt;span class=&quot;s2&quot;&gt;&quot;github&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    fetch &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; +refs/heads/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;:refs/remotes/github/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;
    url &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; git@github.com:whatwewant/whatwewant.github.io.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git push -u gitcafe master:gitcafe-pages&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git push -u github master&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/04/01/gitcafe-pages.html</link>
    <guid>/2015/04/01/gitcafe-pages</guid>
    <pubDate>Wed, 01 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Head First Sql</title>
    <description>
&lt;h2 id=&quot;1-sql-创建篇&quot;&gt;1. SQL 创建篇&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;创建数据库: CREATE DATABASE dbname;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;使用数据库: USE dbname&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;创建表:&lt;/li&gt;
    &lt;/ol&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;   CREATE TABLE tableName
   &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
      name VARCHAR&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;10&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;,
      weight DEC&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;5, 2&lt;span class=&quot;o&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;数据类型: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CHAR, VARCHAR, BLOB, INT, DEC, DATE, DATETIME&lt;/code&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;列出某表的所有字段详细情况: DESC tableName;
        &lt;ul&gt;
          &lt;li&gt;DESC　是 DESCRIBE 的缩写&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;删除表: DROP TABLE tableName;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;补充:
        &lt;ul&gt;
          &lt;li&gt;显示mysql中的所有数据库: show databases;&lt;/li&gt;
          &lt;li&gt;显示某个数据库中的所有表: show tables;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-sql-数据处理篇&quot;&gt;2. SQL 数据处理篇&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;插入数据:&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    INSERT INTO tableName 
    &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;column_name1, column_name2, ...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    VALUES
    &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;value1, value2, ...&lt;span class=&quot;o&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;查询所有数据: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT * FROM tableName&lt;/code&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;设置字段非空NOT NULL属性:
        &lt;ul&gt;
          &lt;li&gt;注意: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULL != NULL; NULL != BLANK&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    CREATE TABLE tableName 
    &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        lastname VARCHAR&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;30&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; NOT NULL
    &lt;span class=&quot;o&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;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;缺省/默认属性: DEFAULT:&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    CREATE TABLE tableName
    &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        cost DEC&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;3, 2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; NOT NULL DEFAULT 1.00
    &lt;span class=&quot;o&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;
</description>
    <link>/2015/04/01/Head-First-SQL.html</link>
    <guid>/2015/04/01/Head-First-SQL</guid>
    <pubDate>Wed, 01 Apr 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Phpstorm Install And Use</title>
    <description>&lt;h2 id=&quot;ubuntu1404-下-phpstorm-的安装与使用&quot;&gt;Ubuntu14.04 下 PHPStorm 的安装与使用&lt;/h2&gt;

&lt;h2 id=&quot;1-下载安装包&quot;&gt;1. 下载安装包:&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;官网: https://www.jetbrains.com/phpstorm/&lt;/li&gt;
  &lt;li&gt;Version: 8.0.3&lt;/li&gt;
  &lt;li&gt;Tar.gz address: http://120.192.76.118/cache/download.jetbrains.com/webide/PhpStorm-8.0.3.tar.gz?ich_args=9fd2851c9cfc749a6559bc79da0a2afd_1_0_0_2_9f03a674e5a343c018824d475fe8fee3f0d70d2696fcc53137cc8baa4a1bdc88_cc554e7620bff0a435beff2603e2ee3d_1_0&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;2-解压并使用&quot;&gt;2. 解压并使用&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;tar -xcf PhpStorm-8.0.3.tar&lt;/li&gt;
  &lt;li&gt;cd PhpStorm-8.0.3&lt;/li&gt;
  &lt;li&gt;./phpstorm.sh&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3-php-server&quot;&gt;3. php server&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;sudo apt-get install php5 php5-fpm php5-cgi&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;4-配置phpstorm-php-server&quot;&gt;4. 配置phpstorm php server&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;-&amp;gt; File -&amp;gt; Settings -&amp;gt; Languages &amp;amp; Frameworks
  -&amp;gt; PHP -&amp;gt; Servers -&amp;gt; +（绿色+号添加新服务器）
  -&amp;gt; Name: phpserver
  -&amp;gt; Host: localhost 或者 127.0.0.1
  -&amp;gt; Port: 9090
  -&amp;gt; Debugger: Xdebug&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;5-ok-现在可以写完代码然后直接在浏览器执行了&quot;&gt;5. OK, 现在可以写完代码然后直接在浏览器执行了！&lt;/h2&gt;
</description>
    <link>/2015/03/30/phpstorm-install-and-use.html</link>
    <guid>/2015/03/30/phpstorm-install-and-use</guid>
    <pubDate>Mon, 30 Mar 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Php Start Note</title>
    <description>
&lt;h2 id=&quot;php-入门篇&quot;&gt;PHP 入门篇&lt;/h2&gt;

&lt;h3 id=&quot;1语法&quot;&gt;1.语法&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;PHP代码卸载&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;?php&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&amp;gt;&lt;/code&gt;之间, 但注意后面的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&amp;gt;&lt;/code&gt; 是可以省略的;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;Echo 语句: 注意&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;php语句以 ; 结束&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;作用: 1. 输出字符串: echo “Hello”; 2. 输出表达式结果: echo 23+56;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;字符串:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;可以用单引号，也可以用双引号 “Hello” ‘world’&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;把两个字符链接起来: 连接符. : echo “hi”.”Cole”; (其他语言都是+)&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;PHP语句结束符: 分号(;)&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;注释: //, 注意:　注释语句必须在&amp;lt;?php ?&amp;gt;之间&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-变量&quot;&gt;2. 变量&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;以$开头&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;var_dump 函数: 显示变量类型, 例如var_dump($n) // 去掉 \&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;变量命名规则:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;以 $ 进行标识(开始)&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;以 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;字母&lt;/code&gt; 或 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;下划线&lt;/code&gt;开头: $name, $_name // 去掉\, vim下md 显示问题&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;只能由&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;下划线&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;字母&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数字&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;汉字&lt;/code&gt;组成&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;不允许包含空格&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;区分大小写&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;变量的数据类型:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;memory_get_usage() 获取当前 PHP 销号的内存&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;$m1 = memory_get_usage(); // 当前内存:&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;$n = 123;&lt;/li&gt;
          &lt;li&gt;$m2 = memory_get_usage() - $m1; // 获取 $n 数据类型占用的内存&lt;/li&gt;
          &lt;li&gt;字符串 272; 整形和浮点型272; 数组576&lt;/li&gt;
          &lt;li&gt;数组: $vararray = array(“123”);
    * 3. 在PHP中, 支持８中原始类型，其中包括四种标量类型、两种复合类型和两种特殊类型。PHP是一门松散类型的语言，不必向PHP声明变量的数据类型，PHP会自动把变量转换为自动的数据类型。&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;标量类型1: 布尔类型:
        &lt;ul&gt;
          &lt;li&gt;两个值：　TRUE，　FALSE;&lt;/li&gt;
          &lt;li&gt;不区分大小写: TRUE == true;&lt;/li&gt;
          &lt;li&gt;注意: echo TRUE; 结果: 1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;标量类型2: 整型(integer):
        &lt;ul&gt;
          &lt;li&gt;可以用十进制、八进制、十六进制、十进制&lt;/li&gt;
          &lt;li&gt;八进制：数字前必须加上”0”, $data_int = 0123;&lt;/li&gt;
          &lt;li&gt;十六进制: “0x”, $data_int = 0x1a;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;标量类型3: 浮点型
        &lt;ul&gt;
          &lt;li&gt;$num_float = 1.234;&lt;/li&gt;
          &lt;li&gt;$num_float = 1.2e3; // 科学计数法, 小写e&lt;/li&gt;
          &lt;li&gt;$num_float = 1.0E-10; // 大写E&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;标量类型４: 字符串:
        &lt;ul&gt;
          &lt;li&gt;单引号或双引号&lt;/li&gt;
          &lt;li&gt;单引号(双引号)中嵌入双引号(单引号): $say = ‘A say: “I hate you.”;’;&lt;/li&gt;
          &lt;li&gt;转移字符转移单双引号&lt;/li&gt;
          &lt;li&gt;遇到 $, $var=”love”:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;双引号: 输出$var存储的字符串, 结果: love&lt;/li&gt;
          &lt;li&gt;单引号: 输出’$var’, 结果: $var
      * 长字符串处理:&lt;/li&gt;
          &lt;li&gt;首先使用定界符表示字符串(«&amp;lt;), 接着在”«&amp;lt;”后提供一个标识符GOD(标识符不是固定的，自定义, 例如DOG, GO都行), 然后是字符串，　最后以GOD结束字符串;&lt;/li&gt;
          &lt;li&gt;注意: «&amp;lt;GOD 无空格, 并且«&amp;lt;GOD 和 GOD;各独占一行&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-php 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;nv&quot;&gt;$string1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&amp;lt;&amp;lt;&amp;lt;GO
我有一只小毛驴，我从来也不骑。
有一天我心血来潮，骑着去赶集。
我手里拿着小皮鞭，我心里正得意。
不知怎么哗啦啦啦啦，我摔了一身泥.
GO;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;第一种特殊的类型: 资源(resource):
        &lt;ul&gt;
          &lt;li&gt;资源：室友专门的函数来建立和使用。例如: 打开文件、数据连接、图形画布。我们可以对资源进行操作(创建、使用和释放)。任何资源，在不需要时应该及时释放。如果忘记释放资源，系体自动启用垃圾回收机制，在页面执行完毕后回收资源，以避免内存被消耗殆尽。
```php
&amp;lt;?php
$file_handle = fopen(“f.txt”, “r”); // 打开文件
$con = mysql_connect(“localhost”, “root”, “root”); // 简历数据库链接
$img = imagecreate(100, 100); // 图形画布&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;if ($file_handle) {
  // 采用while循环读取文件
  while (!feof($file_handle)) {
    $line = fgets($file_handle);
    echo $line;
    echo “&lt;br /&gt;”;
  }
}
fclose($file_handle); // 关闭文件句柄
?&amp;gt;
```&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;第二种特殊类型: 空类型(NULL):
        &lt;ul&gt;
          &lt;li&gt;NULL or null, 对大小写不敏感&lt;/li&gt;
          &lt;li&gt;表示变量没有值, 情况:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;赋值NULL&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;未被赋值&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;unset($var),
     * &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error_reporting(0); // 禁止显示PHP警告&lt;/code&gt;&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;4-常量&quot;&gt;4. 常量:&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;定义:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;自定义常量：&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;bool define(string $constant_name, mixed $value[, $case_sensitive = true]);&lt;/li&gt;
          &lt;li&gt;define(“PI”, 3.14);echo PI;&lt;/li&gt;
          &lt;li&gt;$p=”PII”; define($p, “123”); echo PII;&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;echo &quot;面积是: &quot;.(PI*3*3);&lt;/code&gt;
      * 2. 系统常量:&lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;strong&gt;FILE&lt;/strong&gt;: php程序文件名, 可以帮助获取当前文件在服务器的物理位置&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;&lt;strong&gt;LINE&lt;/strong&gt;: PHP程序文件行数，　当前代码在第几行&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;PHP_VERSION&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;PHP_OS: 操作系统名字&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;获取常量的值:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;直接使用 PI&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;mixed constant(string constant_name); // constant(“PI”);&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;如何判断常量是否被定义:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;bool defined(string constants_name); // 存在返回true, 不存在返回false; // 例如: $exist = define(“PI”);&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;5-运算符&quot;&gt;5. 运算符:&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;===: 全等，即值相等，并且类型相同&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;!==: 非全等, 即如果$a不等于$b，或者它们的类型不同，返回TRUE&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;三元运算符: ? :
        &lt;ul&gt;
          &lt;li&gt;$b = $a &amp;gt;= 0 ? 1 : 2;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;逻辑运算符:
        &lt;ul&gt;
          &lt;li&gt;逻辑与: $a and $b == $a &amp;amp;&amp;amp; $b&lt;/li&gt;
          &lt;li&gt;
            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;逻辑或: $a or $b == $a&lt;/td&gt;
                  &lt;td&gt; &lt;/td&gt;
                  &lt;td&gt;$b&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/li&gt;
          &lt;li&gt;逻辑非: ! $a&lt;/li&gt;
          &lt;li&gt;逻辑异或: $a xor $b&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;字符串连接运算符:
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;链接运算符(“.”)&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;连接赋值运算符(“.=”)&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;错误控制运算符:
        &lt;ul&gt;
          &lt;li&gt;PHP提供了一个错误控制运算符”@”, 将@放置在一个PHP表达式之前，该表达式可能产生错误的信息都被忽略&lt;/li&gt;
          &lt;li&gt;如果激活了track_error(在php.ini中设置)特性, 表达式所产生的任何错误信息都被存放在变量$php_errormsg中，此变量在每次出错时都会被覆盖，所以如果想用他的话必须尽早检查.&lt;/li&gt;
          &lt;li&gt;注意: 错误控制前缀”@”不会屏蔽解析错误的信息，不能把他放在函数或者类的定义之前，也不能用于条件结构&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$conn = @mysql_connect(&quot;localhost&quot;,&quot;username&quot;,&quot;password&quot;);&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;ceil($var): 取大于$var的最小整数&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;6-语言结构语句&quot;&gt;6. 语言结构语句&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;if; else if; else&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;switch 类C&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;foreach :
        &lt;ul&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;只取值，不取下标: foreach (数组 as 值) {}&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;ol&gt;
              &lt;li&gt;同时取下标和值: foreach (数组 as 下标 =&amp;gt; 值) {}&lt;/li&gt;
            &lt;/ol&gt;
          &lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;数组: $a=array(&quot;as&quot;); $b=array(&quot;211&quot;=&amp;gt;array(&quot;a&quot;, &quot;b&quot;), &quot;212&quot;=&amp;gt;array(&quot;c&quot;));&lt;/code&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
    <link>/2015/03/29/php-start-note.html</link>
    <guid>/2015/03/29/php-start-note</guid>
    <pubDate>Sun, 29 Mar 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Android 封装getpost</title>
    <description>
&lt;h3 id=&quot;为了方便自己封装了一个&quot;&gt;为了方便，自己封装了一个&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Google 好像有更好的，还没用起来，先用用自己封装的, 以下是源码&lt;/li&gt;
&lt;/ul&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;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;android.annotation.TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;android.os.Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.HttpEntity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.HttpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.client.CookieStore&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.client.HttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.client.entity.UrlEncodedFormEntity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.client.methods.HttpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.client.methods.HttpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.cookie.Cookie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.impl.client.DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.message.BasicNameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.params.CoreConnectionPNames&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.protocol.HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;org.apache.http.util.EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.io.IOException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.io.InputStream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.io.UnsupportedEncodingException&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;java.util.List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * Created by potter on 14-12-12.
 */&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;HttpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;HttpPost&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpPost&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;nc&quot;&gt;HttpGet&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpGet&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;nc&quot;&gt;HttpEntity&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpEntity&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;nc&quot;&gt;HttpResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpResponse&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;returnResult&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCookies&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;private&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpCookies&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;static&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlString&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;nc&quot;&gt;HttpClient&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;HttpGet&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpGet&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;nc&quot;&gt;HttpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept-Encoding&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;gzip,deflate,sdch&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept-Language&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/x-www-form-urlencoded; charset=UTF-8&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getParams&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setParameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CoreConnectionPNames&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CONNECTION_TIMEOUT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;HttpResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpResponse&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;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpGet&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;printStackTrace&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;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;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceHtml&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;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sourceHtml&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;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;o&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sourceHtml&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&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;kc&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&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;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;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;nd&quot;&gt;@TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;GINGERBREAD&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlString&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;httpGet&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;nc&quot;&gt;HttpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlString&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;httpCookies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&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;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cookie&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpCookies&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;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/x-www-form-urlencoded; charset=UTF-8&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getParams&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setParameter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CoreConnectionPNames&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CONNECTION_TIMEOUT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpGet&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;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;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;returnResult&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;CookieStore&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookieStore&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getCookieStore&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Cookie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookieStore&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getCookies&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;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCookies&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Cookie&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookies&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;tmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&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;nc&quot;&gt;BasicNameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&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;n&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()));&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;httpCookies&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;httpCookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;each&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;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;each&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getValue&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;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;n&quot;&gt;myCookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;returnResult&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;kc&quot;&gt;null&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;@TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;GINGERBREAD&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;nc&quot;&gt;InputStream&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getImgInputStream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlString&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;httpGet&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;nc&quot;&gt;HttpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlString&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;httpCookies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&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;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cookie&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpCookies&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;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//httpGet.addHeader(&quot;Accept-Encoding&quot;, &quot;gzip,deflate,sdch&quot;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//httpGet.addHeader(&quot;Accept-Language&quot;, &quot;en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4&quot;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/x-www-form-urlencoded; charset=GBK&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpGet&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;printStackTrace&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;null&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;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;nc&quot;&gt;InputStream&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;imgStream&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;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;imgStream&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getContent&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;// System.out.println(&quot;In MyHttpClient getStatic&quot;);&lt;/span&gt;

            &lt;span class=&quot;nc&quot;&gt;CookieStore&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookieStore&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getCookieStore&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Cookie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookieStore&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getCookies&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;kc&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myCookies&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Cookie&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cookies&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;tmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;add&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;nc&quot;&gt;BasicNameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&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;n&quot;&gt;each&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()));&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;httpCookies&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;httpCookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;each&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;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;each&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getValue&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;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;n&quot;&gt;myCookies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&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;imgStream&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;kc&quot;&gt;null&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;@TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;GINGERBREAD&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getStatic&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;urlString&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;nc&quot;&gt;HttpGet&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpGet&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;nc&quot;&gt;HttpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;urlString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// httpGet.addHeader(&quot;Accept-Encoding&quot;, &quot;gzip,deflate,sdch&quot;);&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;//httpGet.addHeader(&quot;Accept-Language&quot;, &quot;en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4&quot;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpGet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/x-www-form-urlencoded; charset=UTF-8&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;nc&quot;&gt;HttpClient&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;nc&quot;&gt;HttpResponse&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpResponse&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;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpGet&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;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;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;returnResult&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;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;returnResult&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;nc&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;In MyHttpClient getStatic&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;returnResult&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;returnResult&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;网络错误&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;@TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;GINGERBREAD&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ArrayList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;NameValuePair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;postParams&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;httpPost&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;nc&quot;&gt;HttpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&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;httpCookies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&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;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cookie&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpCookies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//System.out.println(&quot;HttpCookies: &quot; + httpCookies);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, application/x-www-form-urlencoded, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Host&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;192.168.3.11:7001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Origin&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://192.168.3.11:7001&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Referer&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://192.168.3.11:7001/QDHWSingle/login.jsp&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setEntity&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;nc&quot;&gt;UrlEncodedFormEntity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;postParams&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;UTF_8&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;UnsupportedEncodingException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpPost&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;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;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;returnResult&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;//System.out.println(&quot;In Http Post: &quot; + returnResult);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;returnResult&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;网络请求异常，请检查网络&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;@TargetApi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Build&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;VERSION_CODES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;GINGERBREAD&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;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;url&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;httpPost&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;nc&quot;&gt;HttpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&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;httpCookies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;isEmpty&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;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cookie&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpCookies&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;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;User-Agent&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Connection&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;keep-alive&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;httpPost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Accept&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;application/json, text/javascript, */*; q=0.01&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;httpClient&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;nc&quot;&gt;DefaultHttpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpPost&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;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;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusLine&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getStatusCode&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;nc&quot;&gt;HttpStatus&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;SC_OK&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;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;returnResult&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;EntityUtils&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpResponse&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getEntity&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;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;IOException&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;k&quot;&gt;return&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;o&quot;&gt;}&lt;/span&gt;
            
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;returnResult&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;网络请求异常，请检查网络&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;
</description>
    <link>/2015/03/29/android-%E5%B0%81%E8%A3%85GetPost.html</link>
    <guid>/2015/03/29/android-封装GetPost</guid>
    <pubDate>Sun, 29 Mar 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Cole Smith</title>
    <description>
&lt;h2 id=&quot;home-for-cole-smith&quot;&gt;Home For Cole Smith&lt;/h2&gt;
</description>
    <link>/2015/03/28/cole-smith.html</link>
    <guid>/2015/03/28/cole-smith</guid>
    <pubDate>Sat, 28 Mar 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Iptables Useage</title>
    <description>
&lt;h3 id=&quot;将来自-104143024-的tcp数据指向-641119638&quot;&gt;将来自 10.4.143.0/24 的tcp数据指向 64.111.96.38&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; nat &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; PREROUTING &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 10.4.143.0/24 &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DNAT &lt;span class=&quot;nt&quot;&gt;--to-destin&lt;/span&gt;
ation 64.111.96.38
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;将来自-104143024-的tcp的http数据指向-12358180106&quot;&gt;将来自 10.4.143.0/24 的tcp的http数据指向 123.58.180.106&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; nat &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; PREROUTING &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 10.4.143.0/24 &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;--dport&lt;/span&gt; 80 &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DNAT &lt;span class=&quot;nt&quot;&gt;--to-destination&lt;/span&gt; 123.58.180.106
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;禁用访问域名-与-string-匹配&quot;&gt;禁用访问域名, 与 –string 匹配&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; OUTPUT &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 10.4.143.0/24 &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; string &lt;span class=&quot;nt&quot;&gt;--string&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;baidu.com&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--algo&lt;/span&gt; bm &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;重定向&quot;&gt;重定向&lt;/h3&gt;
&lt;div class=&quot;language-bash 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;nb&quot;&gt;sudo &lt;/span&gt;iptables &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; nat &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; PREROUTING &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; tcp &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DNAT &lt;span class=&quot;nt&quot;&gt;--to-destination&lt;/span&gt; 204.79.197.200
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;限制速度&quot;&gt;限制速度&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MTU: 1500Bytes ~= 1.46KB = 1 package
 --limit 1/s # 每秒限制一个package ~= 1 * 1.46 KB
 --limit-burst 1 # 允许触发 limit 限制的最大次数为1 (默认为5)

 限制最大速度 1kB/s 左右
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;限制来自 10.4.156.0/24的速度, 也就是上传速度&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; FORWARD 1 &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 10.4.156.0/24 &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; limit &lt;span class=&quot;nt&quot;&gt;--limit&lt;/span&gt; 1/s &lt;span class=&quot;nt&quot;&gt;--limit-burst&lt;/span&gt; 1 &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; ACCEPT
iptables &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; FORWARD 2 &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 10.4.156.0/24 &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DROP &lt;span class=&quot;c&quot;&gt;# 不满足上一项，直接丢弃&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;限制去到 10.4.156.0/24的速度,也就是下载速度, 
这里限制1package/s, 大约1KB/s, 由 limit后的参数决定&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; FORWARD 1 &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; 10.4.156.0/24 &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; limit &lt;span class=&quot;nt&quot;&gt;--limit&lt;/span&gt; 1/s &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; ACCEPT
iptables &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; FORWARD 2 &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; 10.4.156.0/24 &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DROP &lt;span class=&quot;c&quot;&gt;# 不满足上一项，直接丢弃&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;使来自内网19216812024的网能连山外网-其中ppp0可上网&quot;&gt;使来自内网192.168.12.0/24的网能连山外网, 其中ppp0可上网&lt;/h3&gt;

&lt;div class=&quot;language-bash 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;nb&quot;&gt;sudo &lt;/span&gt;iptables &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; nat &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; POSTROUTING &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; 192.168.12.0/24 &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; ppp0 &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; MASQUERADE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
    <link>/2015/03/26/iptables-useage.html</link>
    <guid>/2015/03/26/iptables-useage</guid>
    <pubDate>Thu, 26 Mar 2015 00:00:00 +0800</pubDate>
  </item>

  <item>
    <title>Linux Scanning Technique</title>
    <description>
&lt;h2 id=&quot;扫描技术&quot;&gt;扫描技术&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://imooc.com/video/6629&quot;&gt;Study Address&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;1-概述&quot;&gt;1. 概述&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;1.互联网安全: 数据的真实、可靠、完整、可控&lt;/li&gt;
  &lt;li&gt;
    &lt;ol&gt;
      &lt;li&gt;命令:
        &lt;ul&gt;
          &lt;li&gt;tracert&lt;/li&gt;
          &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;traceroute&lt;/code&gt;:&lt;/li&gt;
        &lt;/ul&gt;
        &lt;ul&gt;
          &lt;li&gt;扫描到达目的网络的路由&lt;/li&gt;
          &lt;li&gt;例如: traceroute www.baidu.com #　将可以看到所经过的路由
    * &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nmap&lt;/code&gt;:&lt;/li&gt;
          &lt;li&gt;端口范围扫描, 批量主机服务扫描
    * &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nc&lt;/code&gt;:&lt;/li&gt;
          &lt;li&gt;任意IP地址端口扫描&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;3.网络入侵方式:
    &lt;ul&gt;
      &lt;li&gt;踩点－网络扫描－查点－提权等&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2主机扫描&quot;&gt;2.主机扫描&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;命令:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fping&lt;/code&gt; (ping增强版):
        &lt;ul&gt;
          &lt;li&gt;作用: 批量的给目标主机发送ping请求，测试主机的存活情况&lt;/li&gt;
          &lt;li&gt;特点: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;并行发送&lt;/code&gt;、结果易读&lt;/li&gt;
          &lt;li&gt;参数:
            &lt;ul&gt;
              &lt;li&gt;h: help (详细信息: man)&lt;/li&gt;
              &lt;li&gt;a: 只显示出存货的主机(相反参数 -u)&lt;/li&gt;
              &lt;li&gt;g 支持主机段的方式: 192.168.1.1 192.168.1.255或者192.168.1.0/24&lt;/li&gt;
              &lt;li&gt;q: 安静,不输出不显示每个ping的结果&lt;/li&gt;
              &lt;li&gt;f: 通过读取一个文件中Ip的内容: fping -f filename&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;例子:
            &lt;ul&gt;
              &lt;li&gt;1.通过标准输入方式 fping + IP1 + IP2 + IP3 …&lt;/li&gt;
              &lt;li&gt;
                &lt;ol&gt;
                  &lt;li&gt;批量扫描主机段:
                    &lt;ul&gt;
                      &lt;li&gt;fping -g 192.168.1.1 192.168.1.255&lt;/li&gt;
                      &lt;li&gt;fping -g 192.168.1.0/24&lt;/li&gt;
                      &lt;li&gt;fping -agq 192.168.0/24&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ol&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hping&lt;/code&gt; :
        &lt;ul&gt;
          &lt;li&gt;特点: 支持使用的TCP/IP数据包组装、分析工具
            &lt;ul&gt;
              &lt;li&gt;即当ICMP数据包被服务器丢弃时，这个命令就很好用了&lt;/li&gt;
              &lt;li&gt;Github: hping&lt;/li&gt;
              &lt;li&gt;安装(ubuntu): sudo apt-get install hping3&lt;/li&gt;
              &lt;li&gt;依赖:
                &lt;ul&gt;
                  &lt;li&gt;libpcap-devel&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;参数:
                &lt;ul&gt;
                  &lt;li&gt;h: help&lt;/li&gt;
                  &lt;li&gt;v: version&lt;/li&gt;
                  &lt;li&gt;p: 端口&lt;/li&gt;
                  &lt;li&gt;S: 设置TCP模式SYN包(三次握手包的同步包)&lt;/li&gt;
                  &lt;li&gt;a: 伪造IP地址&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;用法:
                &lt;ul&gt;
                  &lt;li&gt;
                    &lt;ol&gt;
                      &lt;li&gt;对指定目标端口发起tcp探测:
                        &lt;ul&gt;
                          &lt;li&gt;hping3 -p 80 -S 192.168.1.1&lt;/li&gt;
                        &lt;/ul&gt;
                      &lt;/li&gt;
                    &lt;/ol&gt;
                  &lt;/li&gt;
                  &lt;li&gt;2伪造来源IP，模拟Ddos攻击:
                    &lt;ul&gt;
                      &lt;li&gt;hping3 -p 80 -S 192.168.1.1 -a 10.10.163.123&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;扩展:
                &lt;ul&gt;
                  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netstat&lt;/code&gt;:
                    &lt;ul&gt;
                      &lt;li&gt;l : 查看本机监听端口&lt;/li&gt;
                      &lt;li&gt;t : 查看tcp的协议&lt;/li&gt;
                      &lt;li&gt;n : 不做主机名解析,即只显示IP地址不显示主机名&lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                  &lt;li&gt;sysctl -w net.ipv4-icmp_echo_ignore_all=1 (去掉)
                    &lt;ul&gt;
                      &lt;li&gt;写入内核，禁用icmp echo; 更好的方式用iptables&lt;/li&gt;
                      &lt;li&gt;iptables -A INPUT -p icmp –icmp-type 8 -j DROP
                        &lt;ul&gt;
                          &lt;li&gt;icmp-type:
                            &lt;ul&gt;
                              &lt;li&gt;8 : 禁止echo&lt;/li&gt;
                            &lt;/ul&gt;
                          &lt;/li&gt;
                        &lt;/ul&gt;
                      &lt;/li&gt;
                      &lt;li&gt;tcpdump:
                        &lt;ul&gt;
                          &lt;li&gt;tcpdump -np ieth0 (eth0是网卡)&lt;/li&gt;
                          &lt;li&gt;tcpdump -np -ieth0 src host 10.10.163.123 # 只把来自host10.10.163.123的主机的包过滤出来&lt;/li&gt;
                        &lt;/ul&gt;
                      &lt;/li&gt;
                    &lt;/ul&gt;
                  &lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;3路由扫描&quot;&gt;3.路由扫描&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;作用: 查询一个主机到另一个主机的经过的路由的跳数、以及数据的延迟情况&lt;/li&gt;
  &lt;li&gt;常用工具:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;traceroute&lt;/code&gt;
        &lt;ul&gt;
          &lt;li&gt;默认使用的是UDP协议(30000上的端口)&lt;/li&gt;
          &lt;li&gt;使用TCO协议 -T(tcp协议) -p(端口)&lt;/li&gt;
          &lt;li&gt;使用ICMP协议 -I&lt;/li&gt;
          &lt;li&gt;不显示域名解析,只显示IP: -n&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mtr&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;man mtr&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;4批量服务扫描&quot;&gt;4.批量服务扫描&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;目的:
    &lt;ul&gt;
      &lt;li&gt;1.批量主机存活扫描&lt;/li&gt;
      &lt;li&gt;2.针对主机服务扫描&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;作用:
    &lt;ul&gt;
      &lt;li&gt;1.能更方便快捷获取网络中主机的存活状态&lt;/li&gt;
      &lt;li&gt;2.更加细致、智能获取主机服务侦查情况&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;命令:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nmap&lt;/code&gt; 命令&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;扫描类型&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;描述&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;特点&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ICMP协议类型(-sP)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;ping扫描&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;简单、快速、有效&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;TCP SYN扫描(-sS)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;TCP半开放扫描&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;高效、不易被检测、通用&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;TCP connect()扫描(-sT)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;TCP全开放扫描&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;真实、结果可靠&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;UDP扫描(-sU)&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;UDP协议扫描&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;有效透过防火墙策略&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;命令:
    &lt;ul&gt;
      &lt;li&gt;nmap:
        &lt;ul&gt;
          &lt;li&gt;用ICMP协议主机段扫描: nmap -sP 10.1.21.0/24&lt;/li&gt;
          &lt;li&gt;TCP SYN半开放: nmap -sS 127.0.0.1&lt;/li&gt;
          &lt;li&gt;TCP SYN半开放: nmap -sS -p 0-2048 127.0.0.1 # -p + 端口范围&lt;/li&gt;
          &lt;li&gt;TCP SYN全开放: nmap -sT -p 0-2048 127.0.0.1 # -p + 端口范围&lt;/li&gt;
          &lt;li&gt;UDP扫描: nmap -sU 127.0.0.1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ncat&lt;/code&gt;:
        &lt;ul&gt;
          &lt;li&gt;组合参数:
            &lt;ul&gt;
              &lt;li&gt;w : 设置的超时时间&lt;/li&gt;
              &lt;li&gt;z : 一个输入输出模式&lt;/li&gt;
              &lt;li&gt;v : 显示命令执行过程&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
          &lt;li&gt;应用:
            &lt;ul&gt;
              &lt;li&gt;基于tcp协议(默认): nc -v -z -w2 10.1.21.254 1-50&lt;/li&gt;
              &lt;li&gt;基于udp协议 -u : nc -v -z -w2 -u 10.1.21.254 1-50&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;5linux防范恶意扫描安全策略&quot;&gt;5.linux防范恶意扫描安全策略&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;常见的攻击方法:
    &lt;ul&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;SYN攻击:
            &lt;ul&gt;
              &lt;li&gt;定义: 录用TCP协议缺陷进行，导致系统服务停止响应，网络带宽跑满或者响应缓慢&lt;/li&gt;
              &lt;li&gt;原理:&lt;/li&gt;
            &lt;/ul&gt;
            &lt;ul&gt;
              &lt;li&gt;伪造IP地址
     * 防范:&lt;/li&gt;
              &lt;li&gt;1.减少发送sny+ack包时重试次数:
                &lt;ul&gt;
                  &lt;li&gt;sysctl -w net.ipv4.tcp_synack_retries==3 (去掉)&lt;/li&gt;
                  &lt;li&gt;sysctl -w net.ipv4.tcp_syn_retries=3&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;2.SYN cookies技术:
                &lt;ul&gt;
                  &lt;li&gt;sysctl -w net.ipv4.tcp_syncookies=1&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li&gt;3.增加backlog队列，即增加backlog队列长度:
                &lt;ul&gt;
                  &lt;li&gt;sysctl -w net.ipv4.tcp_max_syn_backlog=2048 (默认512)&lt;/li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;DDOS攻击:
            &lt;ul&gt;
              &lt;li&gt;定义: 分布式访问拒绝服务攻击&lt;/li&gt;
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;ol&gt;
          &lt;li&gt;恶意扫描&lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Linux其他安全策略:
    &lt;ul&gt;
      &lt;li&gt;1.关闭ICMP协议请求:
        &lt;ul&gt;
          &lt;li&gt;sysctl -w net.ipv4.icmp_echo_ignore_all=1&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;2.通过iptables防止扫描:
        &lt;ul&gt;
          &lt;li&gt;iptables -A FORWARD -p tcp –syn -m limit –limit 1/s –limit-burst 5 -j ACCEPT&lt;/li&gt;
          &lt;li&gt;iptables -A FORWARD -p tcp –tcp-flags SYN,ACK,FIN,RST RST -m limit –limit 1/s -j ACCEPT&lt;/li&gt;
          &lt;li&gt;iptables -A FORWARD -p icmp –icmp-type echo-request -m limit –limit 1/s -j ACCEPT&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
    <link>/2015/03/26/Linux-Scanning-Technique.html</link>
    <guid>/2015/03/26/Linux-Scanning-Technique</guid>
    <pubDate>Thu, 26 Mar 2015 00:00:00 +0800</pubDate>
  </item>


</channel>
</rss>
