1. 下载ZooKeeper。官网:http://zookeeper.apache.org

下载后解压,假定zookeeper程序目录为/home/test/zookeeper,为陈述方便此目录记为 $ZOOKEEPER_HOME

可以直接启动:

[bin]$./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /Users/beef_in_jp/Documents/ebuyProjects/courier/tool/zookeeper-3.4./bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

没有配置过多服务器的话,此时是standalone模式:

[bin]$./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /Users/beef_in_jp/Documents/ebuyProjects/courier/tool/zookeeper-3.4./bin/../conf/zoo.cfg
Mode: standalone

默认的监听端口:

[bin]$netstat -an | grep LISTEN
tcp46 *. *.* LISTEN

2. Java代码测试Watcher

2.1 代码(编译需引入这些jar包:jline-0.9.94.jar,log4j-1.2.16.jar,slf4j-api-1.6.1.jar,slf4j-log4j12-1.6.1.jar,zookeeper-3.4.7.jar):

package com.ebuy.courier.testzookeeper.client;

import org.apache.log4j.Logger;
import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat; import com.beef.util.HexUtil; import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean; public class TestZooKeeperWatcher implements Runnable {
private final static Logger logger = Logger.getLogger(TestZooKeeperWatcher.class); private String _pathToWatch;
private ZooKeeper _zooKeeper;
private Watcher _watcher;
private AsyncCallback.StatCallback _existsStatCallback;
private AsyncCallback.ChildrenCallback _childrenCallback; private AtomicBoolean _runFlg = new AtomicBoolean(false);
private String _threadId; public static void main(String[] args) {
try {
//{host}:{port},{host}:{port},{host}:{port}
String connectString = null;
if(args.length > 0) {
connectString = args[0];
} else {
//default test
connectString = "127.0.0.1:2181";
} TestZooKeeperWatcher watcher = new TestZooKeeperWatcher(connectString, "/test");
watcher.run();
} catch(Throwable e) {
logger.error(null, e);
}
} public TestZooKeeperWatcher(String connectString, String pathToWatch) throws IOException, KeeperException, InterruptedException {
int sessionTimeout = 30*1000; _pathToWatch = pathToWatch;
_watcher = new MyWatcher();
_zooKeeper = new ZooKeeper(
connectString, sessionTimeout,
_watcher
);
_existsStatCallback = new MyExistsStatCallBack();
_childrenCallback = new MyChildrenCallback(); UUID uuid = UUID.randomUUID();
_threadId = HexUtil.toHexString(uuid.getMostSignificantBits()) + HexUtil.toHexString(uuid.getLeastSignificantBits());
} @Override
public void run() {
_runFlg.set(true); logger.info("run() start -----> " + _threadId);
try {
synchronized (this) {
while (_runFlg.get()) {
logger.info("run() wait...");
wait();
}
}
} catch (InterruptedException e) {
logger.info("TestZooKeeperWatcher interrupted");
} try {
_zooKeeper.close();
logger.info("_zooKeeper closed");
} catch (Throwable e) {
e.printStackTrace();
} logger.info("run() end -----> " + _threadId);
} public void stop() {
synchronized (this) {
_runFlg.set(false);
notifyAll();
}
} private class MyWatcher implements Watcher { @Override
public void process(WatchedEvent event) {
try {
logger.debug("process() event."
+ " type:" + event.getType()
+ " state:" + event.getState()
+ " path:" + event.getPath()
); Event.EventType eventType = event.getType();
Event.KeeperState keeperState = event.getState();
String path = event.getPath(); if(eventType == Event.EventType.None) {
if(keeperState == Event.KeeperState.Expired) {
stop();
} else if(keeperState == Event.KeeperState.SyncConnected) {
//_zooKeeper.exists("/", _watcher);
//_zooKeeper.exists(_pathToWatch, true, _existsStatCallback, null);
_zooKeeper.exists(_pathToWatch, true);
logger.debug("add async callback of exists to " + _pathToWatch); // _zooKeeper.getChildren(_pathToWatch, true, _childrenCallback, null);
_zooKeeper.getChildren(_pathToWatch, true);
logger.debug("add async callback of getChildren to " + _pathToWatch);
}
} else {
//Node changed
//_zooKeeper.exists(event.getPath(), );
if(eventType == Event.EventType.NodeCreated) {
} else if(eventType == Event.EventType.NodeChildrenChanged) {
} else if(eventType == Event.EventType.NodeDataChanged) {
} else if(eventType == Event.EventType.NodeDeleted) {
}
}
} catch(Throwable e) {
logger.error(null, e);
}
}
} private class MyExistsStatCallBack implements AsyncCallback.StatCallback { @Override
public void processResult(int rc, String path, Object ctx, Stat stat) {
logger.debug("MyExistsStatCallBack processResult()"
+ " rc:" + rc
+ " path:" + path
); if(rc == KeeperException.Code.OK.intValue()) {
} else if(rc == KeeperException.Code.NONODE.intValue()) {
} else if(rc == KeeperException.Code.SESSIONEXPIRED.intValue()) {
//stop the main loop
stop();
} else {
}
}
} private class MyChildrenCallback implements AsyncCallback.ChildrenCallback { @Override
public void processResult(int rc, String path, Object ctx,
List<String> children) {
logger.debug("MyChildrenCallback processResult()"
+ " rc:" + rc
+ " path:" + path
+ " children:[" + toCommaStrings(children) + "]"
); } } private static String toCommaStrings(List<String> list) {
StringBuilder sb = new StringBuilder();
int size = list.size();
for(int i = 0; i < size; i++) {
if(i != 0) {
sb.append(",");
}
sb.append(list.get(i));
} return sb.toString();
} }

2.2 测试自动重连

zookeeper启动后,停止,再启动,测试代码的日志:

2015-12-30 09:20:25,684  INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:zookeeper.version=3.4.7-1713338, built on 11/09/2015 04:32 GMT
2015-12-30 09:20:25,686 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:host.name=10.10.10.242
2015-12-30 09:20:25,686 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.version=1.6.0_65
2015-12-30 09:20:25,686 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.vendor=Apple Inc.
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.home=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.class.path=/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/bin:/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/lib/log4j-1.2.16.jar:/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/lib/zookeeper-3.4.7.jar:/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/lib/jline-0.9.94.jar:/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/lib/slf4j-api-1.6.1.jar:/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient/lib/slf4j-log4j12-1.6.1.jar
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.io.tmpdir=/var/folders/c1/r1htsxps7r5f0rgjysszxd7r0000gn/T/
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:java.compiler=<NA>
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:os.name=Mac OS X
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:os.arch=x86_64
2015-12-30 09:20:25,689 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:os.version=10.10.5
2015-12-30 09:20:25,690 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:user.name=beef_in_jp
2015-12-30 09:20:25,690 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:user.home=/Users/beef_in_jp
2015-12-30 09:20:25,690 INFO (org.apache.zookeeper.ZooKeeper:100) - Client environment:user.dir=/Users/beef_in_jp/Documents/ebuyProjects/courier/srcCourier/TestZooKeeperClient
2015-12-30 09:20:25,691 INFO (org.apache.zookeeper.ZooKeeper:438) - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=com.ebuy.courier.testzookeeper.client.TestZooKeeperWatcher$MyWatcher@2c641e9a
2015-12-30 09:20:25,720 DEBUG (com.ebuy.courier.testzookeeper.client.TestZooKeeperWatcher:52) - run() wait...
2015-12-30 09:20:25,726 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 09:20:25,738 INFO (org.apache.zookeeper.ClientCnxn:876) - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2015-12-30 09:20:25,752 INFO (org.apache.zookeeper.ClientCnxn:1299) - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x151f0701a870001, negotiated timeout = 30000
2015-12-30 09:20:25,754 DEBUG (com.ebuy.courier.testzookeeper.client.TestZooKeeperWatcher:78) - process() event. type:None state:SyncConnected path:null
2015-12-30 10:41:41,124 INFO (org.apache.zookeeper.ClientCnxn:1158) - Unable to read additional data from server sessionid 0x151f0701a870001, likely server has closed socket, closing socket connection and attempting reconnect
2015-12-30 10:41:41,227 DEBUG (com.ebuy.courier.testzookeeper.client.TestZooKeeperWatcher:78) - process() event. type:None state:Disconnected path:null
2015-12-30 10:41:42,255 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:42,259 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:44,206 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:44,207 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:46,023 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:46,024 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:47,441 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:47,441 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:49,454 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:49,455 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:51,245 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:51,246 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:52,944 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:52,945 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:54,048 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:54,049 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:55,816 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:55,817 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:57,349 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:57,349 WARN (org.apache.zookeeper.ClientCnxn:1162) - Session 0x151f0701a870001 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2015-12-30 10:41:58,758 INFO (org.apache.zookeeper.ClientCnxn:1032) - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: 无法定位登录配置)
2015-12-30 10:41:58,758 INFO (org.apache.zookeeper.ClientCnxn:876) - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2015-12-30 10:41:58,776 INFO (org.apache.zookeeper.ClientCnxn:1299) - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x151f0701a870001, negotiated timeout = 30000
2015-12-30 10:41:58,776 DEBUG (com.ebuy.courier.testzookeeper.client.TestZooKeeperWatcher:78) - process() event. type:None state:SyncConnected path:null

可以看到,zookeeper的客户端自带了自动重连功能。

在连接成功时,会触发SyncConnected事件,日志:process() event. type:None state:SyncConnected path:null

在连接断开时,会触发Disconnected事件,日志:process() event. type:None state:Disconnected path:null

2.3 测试节点创建、变更内容、添加子节点,变更自节点内容,删除子节点,删除父节点

zookeeper客户端启动:

[bin]$./zkCli.sh -server 127.0.0.1:

经过测试,ZooKeeper的exists, getChildren调用后,只会触发一次。

exists只在指定的路径触发。

getChildren只触发子节点的增加,子节点的内容变更和删除不会触发。

ZooKeeper测试笔记的更多相关文章

  1. ZooKeeper学习笔记一:集群搭建

    作者:Grey 原文地址:ZooKeeper学习笔记一:集群搭建 说明 单机版的zk安装和运行参考:https://zookeeper.apache.org/doc/r3.6.3/zookeeperS ...

  2. ZooKeeper 学习笔记

    ZooKeeper学习笔记 1.   zookeeper基本概念 zookeeper是一个分布式的,开放源码的分布式应用程序协调服务,是hadoop和Habase的重要组件,是为分布式应用提供一致性服 ...

  3. RGMII_PHY测试笔记1 基于开发板MiS603-X25

    RGMII_PHY测试笔记1 基于开发板MiS603-X25 作者:汤金元 日期:20150817 公司:南京米联电子科技有限公司 博客:http://blog.chinaaet.com/detail ...

  4. 【Zookeeper】Zookeeper部署笔记

    Zookeeper部署笔记 .上传zk安装包 .解压 .配置(先在一台节点上配置) .1添加一个zoo.cfg配置文件 $ZOOKEEPER/conf mv zoo_sample.cfg zoo.cf ...

  5. ZooKeeper读书笔记

    <ZooKeeper读书笔记> 1.Zookeeper是什么?Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用可以基于它实现诸如数据发布/订阅.负载均衡.命名服务.分布 ...

  6. ZooKeeper学习笔记(二)——内部原理

    zookeeper学习笔记(二)--内部原理 1. zookeeper的节点的类型 总的来说可以分为持久型和短暂型,主要区别如下: 持久:客户端与服务器端断开连接的以后,创建的节点不会被删除: 持久化 ...

  7. ZooKeeper学习笔记(一)——概述

    zookeeper学习笔记(一)--概述 1. 概述 Zookeeper是一个开源的分布式的,为分布式应用提供协调服务的Apache项目.zookeeper从设计模式的角度来理解:是一个基于观察者设计 ...

  8. Zookeeper学习笔记(中)

    Zookeeper学习笔记(中) Zookeeper的基本原理和基本实现 深入了解ZK的基本原理 ZK的一致性: ZAB 协议: Zookeeper 原子消息广播协议 ZK通过选举保证 leader ...

  9. Zookeeper学习笔记(上)

    Zookeeper学习笔记 本篇主要是一些基本的介绍和API的使用介绍, 有些只是记录了知识点,而没有完全在笔记中详细解释, 需要自行查找资料补充相关概念 主要参考了课程中的内容: Zookeeper ...

随机推荐

  1. 自动化服务安装部署工具-Ansible

    自动化运维工具Ansible详细部署 ================================================================================= ...

  2. css绘制特殊图形,meida查询,display inline-box间隙问题以及calc()函数

    本文同时发表于本人个人网站 www.yaoxiaowen.com 距离上一篇文章已经一个月了,相比于写代码,发现写文章的确是更需要坚持的事情.言归正传,梳理一下这一个月来,在写ife任务时,有必要记录 ...

  3. 视觉机器学习读书笔记--------SVM方法

    SVM是一种二类分类模型,有监督的统计学习方法,能够最小化经验误差和最大化几何边缘,被称为最大间隔分类器,可用于分类和回归分析.支持向量机的学习策略就是间隔最大化,可形式化为一个求解凸二次规划的问题, ...

  4. DataTable数据赋值给Model通用方法

    注:该文属本人原创,今后项目中发现该方法存在BUG会实时更新,转载记得附上原文出处,方便大家获得最新代码. 相信大家在做项目中,经常会根据不同的表new各种不同的Model,当需要对Model进行实例 ...

  5. django小结

    初始化项目 python manage.py runserver python manage.py runserver 127.0.0.1:8080 python manage.py startapp ...

  6. bash里面的一些符号说明

    $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参 ...

  7. php页面如何增加下载软件功能

    php <?php $array = parse_ini_file("sample.ini"); ?> <a id="btnDownloadFull&q ...

  8. java字典序全排列

    import java.util.Arrays; /** *字典序全排列 *字符串的全排列 *比如单词"too" 它的全排列是"oot","oto&q ...

  9. Python学习笔记(基本功能的使用)

    整理了以前使用的几个笔记:上传到了github; python_notes 以后在慢慢更新吧:

  10. AD10的PCB设计规则

    PCB布线规则,布板需要注意的点很多,但是基本上注意到了下面的这此规则,LAYOUT PCB应该会比较好,不管是高速还是低频电路,都基本如此. 1. 一般规则 1.1 PCB板上预划分数字.模拟.DA ...