<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    有機(jī)肥

    綠色

    2012年3月20日

    mysql 查看表的創(chuàng)建時間的語句

    select * from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'DBNAME' order by create_time desc;

    posted @ 2018-07-25 17:36 有機(jī)肥 閱讀(298) | 評論 (0)編輯 收藏

    進(jìn)程

    ps -ef|grep java
    kill -9 1231

    posted @ 2018-07-17 11:09 有機(jī)肥 閱讀(145) | 評論 (0)編輯 收藏

    database-mysql

    導(dǎo)出數(shù)據(jù)庫

    直接使用命令:

    mysqldump -u root -p abc >abc.sql

    然后回車輸入密碼就可以了;

    mysqldump -u 數(shù)據(jù)庫鏈接用戶名 -p  目標(biāo)數(shù)據(jù)庫 > 存儲的文件名

    文件會導(dǎo)出到當(dāng)前目錄下

    導(dǎo)入數(shù)據(jù)庫(sql文件)

    mysql -u 用戶名 -p  數(shù)據(jù)庫名 < 數(shù)據(jù)庫名.sql
    mysql -u abc -p abc < abc.sql

    注意sql文件必須在當(dāng)前目錄下,如果不在當(dāng)前目錄下需要在< 之后加上具體sql文件路徑

    GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

    UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

    posted @ 2018-06-25 22:45 有機(jī)肥 閱讀(160) | 評論 (0)編輯 收藏

    mysql 存儲過程

    DELIMITER //
    CREATE PROCEDURE proc_tmp()
    BEGIN
    DECLARE done INT DEFAULT 0;  
    DECLARE product_Id VARCHAR(255);
    DECLARE yuanliao VARCHAR(255);
    DECLARE miaoshu VARCHAR(255);
    DECLARE shazhi VARCHAR(255);
    DECLARE midu VARCHAR(255);
    DECLARE mf VARCHAR(255);
    DECLARE zuzhi VARCHAR(255);
    DECLARE quality VARCHAR(255);
    DECLARE shuliang VARCHAR(255);
    DECLARE jiage VARCHAR(255);
    DECLARE price_date VARCHAR(255);

    DECLARE idCur CURSOR FOR SELECT productId,yl,ylms,sz,md,fk,zz,qa,amount,price,pricedate FROM sheet1;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    OPEN idCur;  

    REPEAT
    FETCH idCur INTO product_Id,yuanliao,miaoshu,shazhi,midu,mf,zuzhi,quality,shuliang,jiage,price_date;
    IF NOT done THEN  
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'yl',yuanliao,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'ylms',miaoshu,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'sz',shazhi,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'md',midu,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'fk',mf,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'zz',zuzhi,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'qa',quality,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'amount',shuliang,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'price',jiage,product_Id);
    INSERT INTO static_data(model_id,dataKey,dataVal,product_id) VALUES(3,'pricedate',price_date,product_Id);
    END IF;
    UNTIL done END REPEAT;

    CLOSE idCur;
    END//
    DELIMITER ;

    CALL proc_tmp();
    DROP PROCEDURE proc_tmp;

    DELETE FROM sheet1;
    定義的變量不能和select里的同名

    posted @ 2018-06-08 11:04 有機(jī)肥 閱讀(162) | 評論 (0)編輯 收藏

    采摘2

         摘要: 小編整理的“宜興市主要鄉(xiāng)村旅游點(diǎn)瓜果采摘攻略”,希望能成為您瓜果采摘的好幫手!!!農(nóng)家樂聯(lián)系人手機(jī)采摘項目籬笆園農(nóng)家樂黃亞云13815118337草莓5月-11月挖筍 野菜 采茶 制烏米飯3-5月桑葚 4月油桃 5月 楊梅 6月下旬-7月中下旬 葡萄 7月-9月 挖百合 8月 板栗 9月底-10月份 綠緣生態(tài)農(nóng)業(yè)有限公司陳慶元13701539886挖筍 挖野菜 3-4月 ...  閱讀全文

    posted @ 2017-10-30 16:47 有機(jī)肥 閱讀(135) | 評論 (0)編輯 收藏

    采摘1

    桑葚采

    好去處

    芳橋

    1、綠大地果桑種植基地 13063669929

    2、碧園春生態(tài)園 13771359607

    3、張慕果園 13812203223

    4、金沙灘蔬果園 13585035093

    建議采摘路線:市區(qū)→東氿大道→百合大道→芳塍路往北(詳見地圖指示)

    西渚

    ◆【1】甲有農(nóng)林生態(tài)園

    地址:宜興市西渚鎮(zhèn)張戴公路白塔村部旁(近振元南路)

    ◆【2】白塔云芯林果專業(yè)合作社桑葚采摘園

    地址:白塔村委入口斜對面張戴公路邊

    ◆【3】小杭采摘園

    自駕線路: 宜興——橫山水庫

    ◆【4】白塔瓜果基地

    自駕線路:導(dǎo)航即到

    徐舍

    ◆ 蘇合農(nóng)產(chǎn)品銷售專業(yè)合作聯(lián)社

    自駕線路:麥德龍——G104(行駛16.6公里)——徐舍鎮(zhèn)潘東村

    湖?

    ◆【1】籬笆園農(nóng)家樂

    地址:宜興市湖?鎮(zhèn)洑西村

    ◆【2】金沙灣農(nóng)莊

    地址:宜興市湖?鎮(zhèn)東興村

    posted @ 2017-10-30 16:45 有機(jī)肥 閱讀(134) | 評論 (0)編輯 收藏

    戶外燒烤必備的燒烤菜單

    【燒烤清單】

    1‘.燒烤工具:

    燒烤架、網(wǎng)架、木炭、燒烤叉、小毛刷、打火機(jī)、助燃劑、竹簽、牙簽、水果刀、報紙、
    一次性筷、一次性碗、一次性盤、一次性隔熱手套、紙杯、餐巾紙、濕巾紙、桌布、燒烤圍裙、垃圾袋燒烤夾(夾取生食)





    2.調(diào)料:

    調(diào)和油、鹽、醬油、燒烤醬(汁)、辣椒粉(老干媽)、孜然、五香粉、番茄醬、芝麻、胡蘿卜醬、甜面醬、海鮮調(diào)料、大蒜、姜、蔥花、蜂蜜、



    3、食品:
    葷菜:雞翅、排骨、香腸、火腿腸、牛肉、羊肉、五花肉、各式魚丸肉丸、雞珍、黃花魚、秋刀魚、鯽魚、魷魚、墨魚仔、蝦等



    素菜:玉米、韭菜、蘑菇、茄子、土豆、青椒、生菜(生菜包肉)、花菜、香干、臭干子、小鏝頭、年糕、面包片、棉花糖、皮蛋、胡蘿卜/黃瓜、藕片、等



    水果:香蕉、木瓜、蘋果、梨、菠蘿、哈密瓜等

     4、飲料:礦泉水、可樂(去油膩)、涼茶(降火)、橙汁、啤酒等


    posted @ 2017-10-27 17:08 有機(jī)肥 閱讀(125) | 評論 (0)編輯 收藏

    jquery xml

    $.ajax({
                url:"${base}/bosImg.xml",
                dataType:"xml",
                success:function(data){
                    $(data).find("bosPicture[wlbh='"+wlbh+"'][size='800']").find("imgs").each(function (i){
                        $('#showbox').empty();
                        $(this).children('img').each(function (ii){
                            $('#showbox').append('<img src="'+$(this).text()+'" width="280" height="280" />');
                        })
                    });
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                     alert(XMLHttpRequest.status);
                     alert(XMLHttpRequest.readyState);
                     alert(textStatus);
                }

    posted @ 2017-10-04 01:06 有機(jī)肥 閱讀(121) | 評論 (0)編輯 收藏

    linux order

    grep -rn "2002675" ./catalina.out

    posted @ 2017-09-12 15:35 有機(jī)肥 閱讀(203) | 評論 (0)編輯 收藏

    在Freemarker中,如果要判斷序列中是否包含某個指定的元素

    在Freemarker中,如果要判斷序列中是否包含某個指定的元素,可以使用freemarker的內(nèi)建函數(shù)seq_contains。

    注:seq_contains這個內(nèi)建函數(shù)從FreeMarker 2.3.1 版本開始可用。而在2.3 版本中不存在

     

    使用示例:

    Freemarker代碼  收藏代碼
    1. <#--聲明一個序列,包含若干個元素-->  
    2. <#assign x = ["red", 16, "blue", "cyan"]>  
    3. <#--使用seq_contains判斷序列中的元素是否存在-->  
    4. "blue": ${x?seq_contains("blue")?string("yes", "no")}  
    5. "yellow": ${x?seq_contains("yellow")?string("yes", "no")}  
    6. 16: ${x?seq_contains(16)?string("yes", "no")}  
    7. "16": ${x?seq_contains("16")?string("yes", "no")}  

    輸出結(jié)果:

    Freemarker代碼  收藏代碼
    1. "blue": yes  
    2. "yellow": no  
    3. 16: yes  
    4. "16": no  

    附:seq_前綴在這個內(nèi)建函數(shù)中是需要的,用來和contains 區(qū)分開。contains函數(shù)用來在字符串中查找子串(因為變量可以同時當(dāng)作字符串和序列)。

    posted @ 2017-09-10 10:39 有機(jī)肥 閱讀(527) | 評論 (0)編輯 收藏

    dump

    Mysql導(dǎo)出表結(jié)構(gòu)及表數(shù)據(jù) mysqldump用法

        命令行下具體用法如下:  mysqldump -u用戶名 -p密碼 -d 數(shù)據(jù)庫名 表名 腳本名;

        1、導(dǎo)出數(shù)據(jù)庫為dbname的表結(jié)構(gòu)(其中用戶名為root,密碼為dbpasswd,生成的腳本名為db.sql)
        mysqldump -uroot -pdbpasswd -d dbname >db.sql;

        2、導(dǎo)出數(shù)據(jù)庫為dbname某張表(test)結(jié)構(gòu)
        mysqldump -uroot -pdbpasswd -d dbname test>db.sql;

        3、導(dǎo)出數(shù)據(jù)庫為dbname所有表結(jié)構(gòu)及表數(shù)據(jù)(不加-d)
        mysqldump -uroot -pdbpasswd  dbname >db.sql;

        4、導(dǎo)出數(shù)據(jù)庫為dbname某張表(test)結(jié)構(gòu)及表數(shù)據(jù)(不加-d)
        mysqldump -uroot -pdbpasswd dbname test>db.sql;

    D:\MyDrivers\software\mysql-5.6.26-winx64\bin>mysqldump -h192.168.2.4 -uroot -p -d dy cotton>ee.sql

    posted @ 2017-09-04 09:38 有機(jī)肥 閱讀(220) | 評論 (0)編輯 收藏

    solr常用命令

    查看幫助
    bin/solr -help     
            可以看到solr有哪些子命令,如 start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version
    啟動start
    bin/solr start  -help    查看start幫助
    bin/solr start        啟動單機(jī)版
    bin/solr start -f           前臺啟動
    bin/solr start -p 8984        指定端口啟動
    bin/solr start -cloud        啟動分布式版本
    bin/solr start -e cloud -noprompt         -e表示要啟動一個現(xiàn)有的例子,例子名稱是cloud,cloud這個例子是以SolrCloud方式啟動的
    bin/solr restart          重啟項目

    create
    如果是單機(jī)版要創(chuàng)建core,如果是分布式的要創(chuàng)建collection
    bin/solr create -help     查看create幫助
    bin/solr create -c abc
            abc是core或collection的名字,取決于solr是單機(jī)版還是cloud版本;刷新http://localhost:8983/solr ,可以看到core selector中多了一個abc
            abc目錄的位置創(chuàng)建在solr.solr.home(默認(rèn)是solr的server/solr目錄目錄下

    post提交數(shù)據(jù)生成索引
    bin/post -c abc docs/
            向名為abccore或collection提交數(shù)據(jù),數(shù)據(jù)源在docs/目錄中

    刪除
    bin/solr delete -c abc     刪除一個core或collection

    刪除索引
    bin/post -c abc  -d "<delete><id>/home/matthewi/software/solr-5.4.1/docs/solr-morphlines-core/allclasses-noframe.html</id></delete>"
    重新執(zhí)行上面的搜索可以看到搜索結(jié)果的數(shù)量少了一條:numFound列

    bin/post -c abc -d "<delete><query>*:*</query></delete>"
    刪除所有數(shù)據(jù)

    停止solr
    bin/solr stop -all

    狀態(tài)
    bin/solr status

    posted @ 2017-08-08 17:28 有機(jī)肥 閱讀(138) | 評論 (0)編輯 收藏

    使用Nginx后如何在web應(yīng)用中獲取用戶ip及原理解釋(轉(zhuǎn))

         摘要: nginx.conf配置:location / { proxy_pass http://127.0.0.1:8080/myweb/;proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_ad...  閱讀全文

    posted @ 2017-08-02 14:41 有機(jī)肥 閱讀(118) | 評論 (0)編輯 收藏

    HttpClient4.4.1模擬登錄知乎(轉(zhuǎn)自http://blog.csdn.net/gaopu12345/article/details/45509387)

         摘要: 一,登錄要Post的表單數(shù)據(jù)是什么這部分可以使用Wireshark工具來抓包就可以了,發(fā)現(xiàn)需要以下數(shù)據(jù):“_xsrf” = xxxx(這是一個變動的數(shù)據(jù),需要先活取獲取知乎首頁源碼來獲得) “email” = 郵箱 “password” = 密碼 “rememberme” ...  閱讀全文

    posted @ 2017-07-10 17:50 有機(jī)肥| 編輯 收藏

    CloseableHttpResponse的使用

    public class ClientFormLogin {
     
        public static void main(String[] args) throws Exception {
            BasicCookieStore cookieStore = new BasicCookieStore();
            CloseableHttpClient httpclient = HttpClients.custom()
                    .setDefaultCookieStore(cookieStore)
                    .build();
            try {
                HttpGet httpget = new HttpGet("http://...");
                CloseableHttpResponse response1 = httpclient.execute(httpget);
                try {
                    HttpEntity entity = response1.getEntity();
     
                    System.out.println("Login form get: " + response1.getStatusLine());
     
                    System.out.println("Initial set of cookies:");
                    List<Cookie> cookies = cookieStore.getCookies();
                    if (cookies.isEmpty()) {
                        System.out.println("None");
                    } else {
                        for (int i = 0; i < cookies.size(); i++) {
                            System.out.println("- " + cookies.get(i).toString());
                        }
                    }
                     
                    //輸出網(wǎng)頁源碼          
                    String result = EntityUtils.toString(response1.getEntity(), "utf-8"); 
                    System.out.println(result);                   
                        EntityUtils.consume(entity);
                        } finally {
                    response1.close();
                    }
                      }           
                   }

    posted @ 2017-07-10 17:39 有機(jī)肥 閱讀(2075) | 評論 (0)編輯 收藏

    HttpClient4.X的代理添加實現(xiàn)(轉(zhuǎn)自http://blog.csdn.net/hblfyla/article/details/54962898)

    package org.yla.test;

    import java.net.URI;
    import java.util.ArrayList;
    import java.util.List;

    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.http.Header;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHost;
    import org.apache.http.auth.AuthScope;
    import org.apache.http.auth.Credentials;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.client.CredentialsProvider;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.CloseableHttpResponse;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.BasicCredentialsProvider;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.impl.client.HttpClients;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.util.EntityUtils;
    import org.junit.Test;

    public class HttpClientTest {
        String url = "xxxxxxxxxxxxxxxxxxxxxxxxx";
        String ip = "202.107.233.85";
        int port = 8080;
        String username = "";
        String password = "";

        /**
         * 使用HttpClient4實現(xiàn)代理 202.107.233.85 8080
         *
         * @throws Exception
         */
        @Test
        public void test1() throws Exception {
            HttpClientBuilder build = HttpClients.custom();
            HttpHost proxy = new HttpHost(ip, port);
            CloseableHttpClient client = build.setProxy(proxy).build();
            HttpGet request = new HttpGet(url);
            CloseableHttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            System.out.println(EntityUtils.toString(entity));
        }

        /**
         * 使用httpclient3實現(xiàn)代理
         *
         * @throws Exception
         */
        @Test
        public void test2() throws Exception {
            HttpClient httpClient = new HttpClient();
            httpClient.getHostConfiguration().setProxy(ip, port);
            GetMethod method = new GetMethod(url);
            httpClient.executeMethod(method);
            String result = new String(method.getResponseBody());
            System.out.println(result);
        }

        /**
         * 使用httpclient4實現(xiàn)代理(帶密碼的代理)
         *
         * @throws Exception
         */
        @Test
        public void test3() throws Exception {
            HttpClientBuilder build = HttpClients.custom();
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            AuthScope authscope = new AuthScope(ip, port);
            Credentials credentials = new UsernamePasswordCredentials(username,
                    password);
            credentialsProvider.setCredentials(authscope, credentials);
            CloseableHttpClient client = build.setDefaultCredentialsProvider(
                    credentialsProvider).build();
            HttpGet request = new HttpGet(url);
            CloseableHttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            System.out.println(EntityUtils.toString(entity));
        }

        /**
         * 使用httpclient3實現(xiàn)代理(帶密碼的代理)
         *
         * @throws Exception
         */
        @Test
        public void test4() throws Exception {
            HttpClient httpClient = new HttpClient();
            org.apache.commons.httpclient.auth.AuthScope authscope = new org.apache.commons.httpclient.auth.AuthScope(
                    ip, port);
            org.apache.commons.httpclient.Credentials credentials = new org.apache.commons.httpclient.UsernamePasswordCredentials(
                    username, password);
            httpClient.getState().setProxyCredentials(authscope, credentials);
            GetMethod method = new GetMethod(url);
            httpClient.executeMethod(method);
            String result = new String(method.getResponseBody());
            System.out.println(result);
        }

        /**
         * 模擬登錄官網(wǎng)(http://mis.pyc.com.cn??
         *
         * @throws Exception
         */
        @Test
        public void testLogin() throws Exception {
            HttpClientBuilder build = HttpClients.custom();
            CloseableHttpClient client = build.build();
            HttpPost post = new HttpPost("http://mis.pyc.com.cn/login.aspx");
            List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("__VIEWSTATE",
                    "/wEPDwUJNjUwNzE0MTM4ZGQzh+vF2xGjdG8Q15kIqgR0CpxhmPucdCqZOPcglRZr/w=="));
            params.add(new BasicNameValuePair(
                    "__EVENTVALIDATION",
                    "/wEWBQLYtKSdCALEhISFCwKd+7qdDgKC3IeGDAK7q7GGCOqhJpRD8S8yy3ZAlPTSsmPzRUoXMK0mQvGgzlk6hm+G"));
            params.add(new BasicNameValuePair("txtName", "xxxxx"));
            params.add(new BasicNameValuePair("txtPwd", "xxxxxx"));
            params.add(new BasicNameValuePair("btnLogin", "xxxx"));
            HttpEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
            post.setEntity(entity);
            CloseableHttpResponse response = client.execute(post);
            int statusCode = response.getStatusLine().getStatusCode();
            System.err.println("狀態(tài)" + statusCode);
            if (statusCode == 302) {
                Header[] location = response.getHeaders("location");
                String rediretUrl = null;
                if (location.length == 1) {
                    rediretUrl = "http://mis.pyc.com.cn" + location[0].getValue();
                    System.err.println("跳轉(zhuǎn)地址: " + rediretUrl);
                }
                Header[] allHeaders = response.getAllHeaders();
                System.out.println("==================response===================");
                for (Header header : allHeaders) {
                    System.err.println(header.getName() + ": " + header.getValue());
                }
                Header cookieHeader = response.getFirstHeader("Set-Cookie");
                String cookie = cookieHeader.getValue();
                System.out.println("cookie: " + cookie);
                HttpGet httpGet = new HttpGet(rediretUrl);
                httpGet.addHeader("Accept",
                        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                // httpGet.addHeader("Accept-Encoding", "gzip, deflate, sdch");
                // httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
                httpGet.addHeader("Connection", "keep-alive");
                httpGet.addHeader("Cookie", cookie);
                httpGet.addHeader("Host", "mis.pyc.com.cn");
                httpGet.addHeader("Referer", "http://mis.pyc.com.cn/login.aspx");
                httpGet.addHeader(
                        "User-Agent",
                        "ozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36");
                response = client.execute(httpGet);
                HttpEntity entity2 = response.getEntity();
                System.out
                        .println("----------------------------------------------");
                System.out.println(EntityUtils.toString(entity2));
            }
        }
    }

    posted @ 2017-07-10 17:27 有機(jī)肥| 編輯 收藏

    centos7 mysql數(shù)據(jù)庫安裝和配置(轉(zhuǎn)http://www.cnblogs.com/starof/p/4680083.html)

    一、系統(tǒng)環(huán)境

    yum update升級以后的系統(tǒng)版本為

    [root@yl-web yl]# cat /etc/redhat-release  CentOS Linux release 7.1.1503 (Core) 

    二、mysql安裝

    # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm # yum install mysql-community-server

    安裝成功后重啟mysql服務(wù)。

    # service mysqld restart

    初次安裝mysql,root賬戶沒有密碼。

    復(fù)制代碼
    [root@yl-web yl]# mysql -u root  Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.26 MySQL Community Server (GPL)  Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.  Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | test               | +--------------------+ 4 rows in set (0.01 sec)  mysql> 
    復(fù)制代碼

    設(shè)置密碼

    mysql> set password for 'root'@'localhost' =password('password'); Query OK, 0 rows affected (0.00 sec)  mysql> 

    不需要重啟數(shù)據(jù)庫即可生效。

    三、配置mysql

    1、編碼

    mysql配置文件為/etc/my.cnf

    最后加上編碼配置

    [mysql] default-character-set =utf8

    這里的字符編碼必須和/usr/share/mysql/charsets/Index.xml中一致。

    2、遠(yuǎn)程連接設(shè)置

    把在所有數(shù)據(jù)庫的所有表的所有權(quán)限賦值給位于所有IP地址的root用戶。

    mysql> grant all privileges on *.* to root@'%'identified by 'password';

    如果是新用戶而不是root,則要先新建用戶

    mysql>create user 'username'@'%' identified by 'password';  

    此時就可以進(jìn)行遠(yuǎn)程連接了。

    posted @ 2017-03-01 10:20 有機(jī)肥 閱讀(163) | 評論 (0)編輯 收藏

    linux zip

    linux zip命令

    zip -r myfile.zip ./*
    將當(dāng)前目錄下的所有文件和文件夾全部壓縮成myfile.zip文件,-r表示遞歸壓縮子目錄下所有文件.

    2.unzip
    unzip -o -d /home/sunny myfile.zip
    把myfile.zip文件解壓到 /home/sunny/
    -o:不提示的情況下覆蓋文件;
    -d:-d /home/sunny 指明將文件解壓縮到/home/sunny目錄下;

    3.其他
    zip -d myfile.zip smart.txt
    刪除壓縮文件中smart.txt文件
    zip -m myfile.zip ./rpm_info.txt
    向壓縮文件中myfile.zip中添加rpm_info.txt文件
    -------------------------------------------------------------------------------

    要使用 zip 來壓縮文件,在 shell 提示下鍵入下面的命令:

    zip -r filename.zip filesdir
     

    在這個例子里,filename.zip 代表你創(chuàng)建的文件,filesdir 代表你想放置新 zip 文件的目錄。-r 選項指定你想遞歸地(recursively)包括所有包括在 filesdir 目錄中的文件。

    要抽取 zip 文件的內(nèi)容,鍵入以下命令:

    unzip filename.zip
     

    你可以使用 zip 命令同時處理多個文件和目錄,方法是將它們逐一列出,并用空格間隔:

    zip -r filename.zip file1 file2 file3 /usr/work/school
     

    上面的命令把 file1、file2、 file3、以及 /usr/work/school 目錄的內(nèi)容(假設(shè)這個目錄存在)壓縮起來,然后放入 filename.zip 文件中。

    posted @ 2016-12-07 14:39 有機(jī)肥 閱讀(113) | 評論 (0)編輯 收藏

    jquery 對 Json 的各種遍歷

    原文鏈接:http://caibaojian.com/jquery-each-json.html

    概述

    JSON(javascript Object Notation) 是一種輕量級的數(shù)據(jù)交換格式,采用完全獨(dú)立于語言的文本格式,是理想的數(shù)據(jù)交換格式。同時,JSON是 JavaScript 原生格式,這意味著在 JavaScript 中處理 JSON數(shù)據(jù)不須要任何特殊的 API 或工具包。

    via在JSON中,有兩種結(jié)構(gòu):對象和數(shù)組。

    1.對象

    一個對象以“{”開始,“}”結(jié)束。每個“key”后跟一“:”,“‘key/value’ 對”之間運(yùn)用 “,”分隔。

    packJson = {"name":"caibaojian.com", "password":"111"}

    2.數(shù)組

    packJson = [{"name":"caibaojian.com", "password":"111"}, {"name":"tony", "password":"111"}];

    數(shù)組是值的有序集合。一個數(shù)組以“[”開始,“]”結(jié)束。值之間運(yùn)用 “,”分隔。

    JSON對象和JSON字符串的轉(zhuǎn)換

    在數(shù)據(jù)傳輸流程中,json是以文本,即字符串的形式傳遞的,而JS操作的是JSON對象,所以,JSON對象和JSON字符串之間的相互轉(zhuǎn)換是關(guān)鍵。例如:

    JSON字符串:

    var jsonStr = '{"name":"caibaojian", "password":"1111"}';

    JSON對象:

    var jsonObj = {"name":"caibaojian.com", "password":"1111"};

    1、String轉(zhuǎn)換為Json對象

    var jsonObj = eval('(' + jsonStr + ')');

    2.Json對象轉(zhuǎn)換為String字符串

    var jsonStr = jsonObj.toJSONString();

    jQuery遍歷json對象

    grep

    <script type='text/javascript' src="/jquery.js"></script> <script type="text/javascript"> $().ready( function(){ var array = [1,2,3,4,5,6,7,8,9]; var filterarray = $.grep(array,function(value){ return value > 5;//篩選出大于5的 }); for(var i=0;i<filterarray.length;i++){ alert(filterarray[i]); } for (key in filterarray){ alert(filterarray[key]); } } ); </script>

    each

    <script type='text/javascript' src="/jquery.js"></script> <script type="text/javascript"> $().ready( function(){ var anObject = {one:1,two:2,three:3};//對json數(shù)組each $.each(anObject,function(name,value) { alert(name); alert(value); }); var anArray = ['one','two','three']; $.each(anArray,function(n,value){ alert(n); alert(value); } ); } ); </script>

    inArray

    <script type='text/javascript' src="/jquery.js"></script> <script type="text/javascript"> $().ready( function(){ var anArray = ['one','two','three']; var index = $.inArray('two',anArray); alert(index);//返回該值在數(shù)組中的鍵值,返回1 alert(anArray[index]);//value is two } ); </script>

    map

    <script type='text/javascript' src="/jquery.js"></script> <script type="text/javascript"> $().ready( function(){ var strings = ['0','1','2','3','4','S','6']; var values = $.map(strings,function(value){ var result = new Number(value); return isNaN(result) ? null:result;//isNaN:is Not a Number的縮寫 } ); for (key in values) { alert(values[key]); } } ); </script>

    原生js遍歷json對象

    遍歷json對象

    無規(guī)律:

    <script> var json = [{dd:'SB',AA:'東東',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i=0,l=json.length;i<l;i++){ for(var key in json[i]){ alert(key+':'+json[i][key]); } } </script>

    有規(guī)律:

    packJson = [  {"name":"nikita", "password":"1111"},  {"name":"tony", "password":"2222"}  ];  for(var p in packJson){//遍歷json數(shù)組時,這么寫p為索引,0,1     alert(packJson[p].name + " " + packJson[p].password);  }

    也可以用這個:

    for(var i = 0; i < packJson.length; i++){     alert(packJson[i].name + " " + packJson[i].password);  }

    遍歷json對象

    myJson = {"name":"caibaojian", "password":"1111"};  for(var p in myJson){//遍歷json對象的每個key/value對,p為key     alert(p + " " + myJson[p]);  }
    //code from http://caibaojian.com/jquery-each-json.html 有如下 json對象: var obj ={"name":"馮娟","password":"123456","department":"技術(shù)部","sex":"女","old":30}; 遍歷方法: for(var p in obj){ str = str+obj[p]+’,'; return str; }
    zhuan:前端開發(fā)博客 (http://caibaojian.com/jquery-each-json.html)

    posted @ 2016-09-26 15:04 有機(jī)肥| 編輯 收藏

    linux 局域網(wǎng)內(nèi)文件傳送

    Linux scp命令用于Linux之間復(fù)制文件和目錄,具體如何使用這里好好介紹一下,從本地復(fù)制到遠(yuǎn)程、從遠(yuǎn)程復(fù)制到本地是兩種使用方式。這里有具體舉例:

    ==================

    Linux scp 命令

    ==================

    scp 可以在 2個 linux 主機(jī)間復(fù)制文件;

    命令基本格式:

    scp [可選參數(shù)] file_source file_target

    ======

    從 本地 復(fù)制到 遠(yuǎn)程

    ======

    * 復(fù)制文件:

    * 命令格式:

    scp local_file remote_username@remote_ip:remote_folder

    或者

    scp local_file remote_username@remote_ip:remote_file

    或者

    scp local_file remote_ip:remote_folder

    或者

    scp local_file remote_ip:remote_file

    第1,2個指定了用戶名,命令執(zhí)行后需要再輸入密碼,第1個僅指定了遠(yuǎn)程的目錄,文件名字不變,第2個指定了文件名;

    第3,4個沒有指定用戶名,命令執(zhí)行后需要輸入用戶名和密碼,第3個僅指定了遠(yuǎn)程的目錄,文件名字不變,第4個指定了文件名;

    * 例子:

    scp /home/space/music/1.mp3 root@www.cumt.edu.cn:/home/root/others/music

    scp /home/space/music/1.mp3 root@www.cumt.edu.cn:/home/root/others/music/001.mp3

    scp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root/others/music

    scp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root/others/music/001.mp3

    * 復(fù)制目錄:

    * 命令格式:

    scp -r local_folder remote_username@remote_ip:remote_folder

    或者

    scp -r local_folder remote_ip:remote_folder

    第1個指定了用戶名,命令執(zhí)行后需要再輸入密碼;

    第2個沒有指定用戶名,命令執(zhí)行后需要輸入用戶名和密碼;

    * 例子:

    scp -r /home/space/music/ root@www.cumt.edu.cn:/home/root/others/

    scp -r /home/space/music/ www.cumt.edu.cn:/home/root/others/

    上面 命令 將 本地 music 目錄 復(fù)制 到 遠(yuǎn)程 others 目錄下,即復(fù)制后有 遠(yuǎn)程 有 ../others/music/ 目錄

    ======

    從 遠(yuǎn)程 復(fù)制到 本地

    ======

    從 遠(yuǎn)程 復(fù)制到 本地,只要將 從 本地 復(fù)制到 遠(yuǎn)程 的命令 的 后2個參數(shù) 調(diào)換順序 即可;

    例如:

    scp root@www.cumt.edu.cn:/home/root/others/music /home/space/music/1.mp3

    scp -r www.cumt.edu.cn:/home/root/others/ /home/space/music/

    最簡單的應(yīng)用如下 :

    scp 本地用戶名 @IP 地址 : 文件名 1 遠(yuǎn)程用戶名 @IP 地址 : 文件名 2

    [ 本地用戶名 @IP 地址 :] 可以不輸入 , 可能需要輸入遠(yuǎn)程用戶名所對應(yīng)的密碼 .

    可能有用的幾個參數(shù) :

    -v 和大多數(shù) linux 命令中的 -v 意思一樣 , 用來顯示進(jìn)度 . 可以用來查看連接 , 認(rèn)證 , 或是配置錯誤 .

    -C 使能壓縮選項 .

    -P 選擇端口 . 注意 -p 已經(jīng)被 rcp 使用 .

    -4 強(qiáng)行使用 IPV4 地址 .

    -6 強(qiáng)行使用 IPV6 地址 .

    Linux scp命令的使用方法應(yīng)該可以滿足大家對Linux文件和目錄的復(fù)制使用了。

    posted @ 2016-09-18 17:53 有機(jī)肥| 編輯 收藏

    JSON字符串轉(zhuǎn)換JAVA對象例子。

    package com.demo.json;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;

    import org.json.simple.JSONValue;

    public class JsonTest
    {
        public static void main(String[] args)
        {
            // -----------------------------------------------------------------------------
            // Object 2 JSON
            List<Peoper> peopers = new ArrayList<Peoper>();
            Peoper p1 = new Peoper("001", "Taki", "中國");
            Peoper p2 = new Peoper("002", "DSM", "China");
            peopers.add(p1);
            peopers.add(p2);
            String result = JsonTool.getJsonString("Peopers", peopers);
            System.out.println("JSON: " + result);

            // 解析PHP json_encode 字符串
            String jsonStr = "{\"Name\":\"\u5e0c\u4e9a\",\"Age\":20}";
            Object obj = JSONValue.parse(jsonStr);
            System.out.println(obj);
            System.out.println();

            // -----------------------------------------------------------------------------
            // JSON 2 Object
            String jsonString = "["
                    + "{\"author\":\"7\",\"id\":358,\"title\":\"Japan\",\"pictures\":[{\"description\":\"001\",\"imgPath\":\"/cms/u/cms/www/201203/05150720ii68.jpg\"},{\"description\":\"002\",\"imgPath\":\"/cms/u/cms/www/201203/05150720ii67.jpg\"}],\"path\":\"ip\"},"
                    + "{\"author\":\"8\",\"id\":359,\"title\":\"China\",\"pictures\":[{\"description\":\"101\",\"imgPath\":\"/cms/u/cms/www/201203/111111111111.jpg\"},{\"description\":\"102\",\"imgPath\":\"/cms/u/cms/www/201203/222222222222.jpg\"}],\"path\":\"ip\"}]";
            JSONArray array = JSONArray.fromObject(jsonString);

            // Content.class包含pictures.class,需要設(shè)置這個參數(shù)
            Map<String, Class<pictures>> classMap = new HashMap<String, Class<pictures>>();
            classMap.put("pictures", pictures.class);

            Object[] objs = new Object[array.size()];
            for (int i = 0; i < array.size(); i++)
            {
                JSONObject jsonObject = array.getJSONObject(i);
                objs[i] = (Content) JSONObject.toBean(jsonObject, Content.class, classMap);
            }
            // 轉(zhuǎn)換Content,循環(huán)輸出所有content
            for (int i = 0; i < objs.length; i++)
            {
                Content content = (Content) objs[i];
                System.out.println("author:" + content.getAuthor() + " ID:"
                        + content.getId() + " Title:" + content.getTitle() + " Path:" + content.getPath());

                // 轉(zhuǎn)換pictures,循環(huán)輸出所有picture
                List<pictures> pictures = content.getPictures();
                for (int n = 0; n < pictures.size(); n++)
                    System.out.println("description:"
                            + pictures.get(n).getDescription() + " imgPath:" + pictures.get(n).getImgPath());
            }
        }
    }
    package com.demo.json;

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    import net.sf.json.JSONObject;


    public class JsonTool
    {
        public static String getJsonString(Object key, Object value)
        {
            //System.out.println("key: " + key);
            //System.out.println("value: " + value.toString());
            JSONObject obj = new JSONObject();
            obj.put(key, value);    //添加物件
            return obj.toString();    //轉(zhuǎn)換為字符串并返回
        }
        
        //解析PHP json_encode 字符串
        public static String unescapeUnicode(String str)
        {
            StringBuffer b=new StringBuffer();
            Matcher m = Pattern.compile("\\\\u([0-9a-fA-F]{4})").matcher(str);
            while(m.find())
            {
                b.append((char)Integer.parseInt(m.group(1),16));
            }
            return b.toString();
        }
    }
    package com.demo.json;

    public class People
    {
        public People()
        {                
        }
        
        public People(String id, String name, String address)
        {        
            this.id = id;
            this.name = name;
            this.address = address;
        }

        private String id;
        private String name;
        private String address;
        
        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }
        
        public String toString()
        {
            return "ID:" + this.id + " Name:" + this.name + " Address:" + this.address;
        }
    }
    package com.demo.json;

    import java.util.List;

    public class Content {
        
        private String author;
        private String id;
        private String title;
        private List<pictures> pictures;
        private String path;

        public String getAuthor() {
            return author;
        }

        public void setAuthor(String author) {
            this.author = author;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public List<pictures> getPictures() {
            return pictures;
        }

        public void setPictures(List<pictures> pictures) {
            this.pictures = pictures;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }
    }

    package com.demo.json;

    public class pictures {
        private String description;
        private String imgPath;

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getImgPath() {
            return imgPath;
        }

        public void setImgPath(String imgPath) {
            this.imgPath = imgPath;
        }
    }

    posted @ 2016-09-18 17:52 有機(jī)肥| 編輯 收藏

    【譯】用jQuery 處理XML-- jQuery與XML

    使用jQuery進(jìn)行DOM元素的操作和遍歷

     

    首先確定妳在頁面引用的jQuery庫,才能使用它。然后簡單地使用jQuery()或者它的簡化形式$(), 傳遞一個選擇器作為它的第一個參數(shù)。選擇器通常是一個指定了一個或多個元素的字符串。清單20展示了一些基本的jQuery選擇器的使用。

    Listing 20. Basic jQuery selectors

     

    <script type="text/javascript">

    var allImages = $("img"); // all IMG elements

    var allPhotos = $("img.photo"); // all IMG elements with class "photo"

    var curPhoto = $("img#currentPhoto"); // IMG element with id "currentPhoto"

    </script>

     

    需要記住的一點(diǎn)是jQuery方法返回的始終是一個jQuery對象。這種對象支持鏈?zhǔn)讲僮鳎ㄒ娗鍐?1)。這一特性在其他JavaScript框架中也是通用的。

     

    Listing 21. Basic jQuery operation with chained method calls

     

    <script type="text/javascript">

    $("img").css({"padding":"1px", "border": "1px solid #333"})

    .wrap("<div class='img-wrap'/>");

    </script>

     

    上述代碼選中頁面中所有img元素并設(shè)置padding和border, 然后用一個帶img-wrap class div 來包裹所有這些img.

     

    清單22則展示了jQuery 是如何將前面章節(jié)的一個例子進(jìn)行簡化。

     

    Listing 22. Creating and injecting a DOM node with jQuery

     

    <script type="text/javascript">

    alert($("h1:first").html()); // .text() also works and might be better suited here

     

    $("#auth").text("Sign Out");

     

    var $li = $("<li>List Item Text</li>");

    // $ is used as var prefix to indicate jQuery object

    $("ul#nav").append($li);

    </script>

     

    使用jQuery 處理XML

     

    之前有提到過傳遞給jQuery $()的第一個參數(shù)是一個字符串形式的選擇器。第二個不起眼的參數(shù)則允許你設(shè)置context,或者開始一個jQuery節(jié)點(diǎn),抑或把當(dāng)前選擇的元素當(dāng)作 一個根節(jié)點(diǎn)來使用。默認(rèn)jQuery會把Document作為當(dāng)前的Context, 但更好的做法是把context指定得更詳細(xì)更一些,具體到某個特定的元素身上。在進(jìn)行XML處理時,需要把context設(shè)置為XML的根節(jié)點(diǎn)(見清單 23)。

     

    Listing 23. Retrieving values from an XML document with jQuery

     

    <script type="text/javascript">

    // get value of single node (with jQuery)

    var description = $("description", xmlData).text();

    // xmlData was defined in previous section

     

    // get values of nodes from a set (with jQuery)

    var relatedItems = $("related_item", xmlData);

    var relatedItemVals = [];

    $.each(relatedItems, function(i, curItem){

    relatedItemVals.push(curItem.text());

    });

    </script>

     

    上述代碼使表示變得相當(dāng)簡潔。通過向jQuery傳遞節(jié)點(diǎn)名稱和設(shè)置它的context為xmlData,可以很方便地獲取想要的節(jié)點(diǎn)。取得元素的值,剛需要一翻周折了。

    因為innerHTML 對 于非HTML元素不管用,所以就不能使用jQuery的html()方法來獲取節(jié)點(diǎn)的值。jQuery 雖然提供了一個跨瀏覽器的方法innerText 來獲取元素的值,但當(dāng)用來處理XML時在瀏覽器間仍有些差異。比如IE會把包含空值(空格,Tab點(diǎn)位 符,換行)的節(jié)點(diǎn)給忽略掉,而處理這樣的情況時,F(xiàn)ireFox則會把這些節(jié)點(diǎn)當(dāng)作正常節(jié)點(diǎn)。為了避免這點(diǎn)不一致性,可以創(chuàng)建一個函數(shù)來處理。這個函數(shù)里 需要用到一些jQuery函數(shù): contents()filter()  trim()

     

    Listing 24. Cross-browser JavaScript functions for accurate text value retrieval of a node

     

    <script type="text/javascript">

    /**

    * Retrieves non-empty text nodes which are children of passed XML node.

    * Ignores child nodes and comments. Strings which contain only blank spaces

    * or only newline characters are ignored as well.

    * @param node {Object} XML DOM object

    * @return jQuery collection of text nodes

    */

    function getTextNodes(node){

    return $(node).contents().filter(function(){

    return (

    // text node, or CDATA node

    ((this.nodeName=="#text" && this.nodeType=="3")

    || this.nodeType=="4") &&

    // and not empty

    ($.trim(this.nodeValue.replace("\n","")) !== "")

    );

    });

    }

     

    /**

    * Retrieves (text) node value

    * @param node {Object}

    * @return {String}

    */

    function getNodeValue(node){

    var textNodes = getTextNodes(node);

    var textValue = (node && isNodeComment(node)) ?

    // isNodeComment is defined above

    node.nodeValue : (textNodes[0]) ? $.trim(textNodes[0].textContent) : "";

    return textValue;

    }

    </script>

     

    現(xiàn)在來看看如何設(shè)置節(jié)點(diǎn)的值(見清單25)。示例代碼中有兩點(diǎn)需要注意:一是設(shè)置根結(jié)果的文本值會重寫所有子節(jié)點(diǎn)。另外就是如果一個節(jié)點(diǎn)之前是沒有值的,那么就用 node["textContent"]而不是node.textContent。因為在IE中空節(jié)點(diǎn)根本就沒有textContent屬性。

     

    Listing 25. Cross-browser JavaScript function for accurate setting of the text value of a node

     

    <script type="text/javascript">

    function setNodeValue(node, value){

    var textNodes = getTextNodes(node);

    if (textNodes.get(0)){

    textNodes.get(0).nodeValue = value;

    }

    else {

    node["textContent"] = value;

    }

    }

    </script>

     

    DOM屬性與jQuery

     

    在之前的一些例子中已經(jīng)展示了即使用最原始的JavaScript來處理DOM中的屬性也是非常直觀明了的了。同樣地,jQuery也提供了相應(yīng)的簡化方式。更重要的是,屬性可以用在選擇器中,非常的強(qiáng)大。

    Listing 26. Getting and setting DOM element attributes with jQuery

     

    <script type="text/javascript">

    var item = $("item[content_id='1']", xmlData);

    // select item node with content_id attribute set to 1

    var pubDate = item.attr("date_published");

    // get value of date_published attribute

    item.attr("archive", "true");

    // set new attribute called archive, with value set to true

    </script>

     

    從代碼中可以看出,jQuery的attr()方法即可以設(shè)置設(shè)置也可以返回屬性值。更強(qiáng)大的是jQuery允許在選擇器中提供屬性來返回特定的元素。下如上面的代碼所展示的那樣,我們獲取到了content_id1的元素。

     

    通過jQuery的Ajax來裝載XML

     

    或許你已經(jīng)有所了解,Ajax是用JavaScript來異步從服務(wù)器獲取XML的一種Web技術(shù)。Ajax本身是依賴XMLHttpRequest (XHR) 所提供的API來向服務(wù)器發(fā)送請求和從服務(wù)器獲取響應(yīng)的。jQuery除了提供強(qiáng)大的用于遍歷和處理DOM元素的方法外,還提供了跨瀏覽器的Ajax支持。也就是說通過Ajax獲取XML簡單得就是調(diào)用Ajax的get方法。清單27展示了這樣的例子。

    Listing 27. Loading an external XML file with jQuery's Ajax method

     

    <script type="text/javascript">

    $.ajax({

    type : "GET",

    url : "/path/to/data.xml",

    dataType : "xml",

    success : function(xmlData){

    var totalNodes = $('*',xmlData).length; // count XML nodes

    alert("This XML file has " + totalNodes);

    },

    error : function(){

    alert("Could not retrieve XML file.");

    }

    });

    </script>

     

    $.ajax()方法有一系列豐富的選項設(shè)置,并且可以通過其他一些簡化的變形方式來調(diào)用,比如$.getScript()會導(dǎo)入JavaScript腳本并執(zhí)行,$.getJSON()會獲取JSON數(shù)據(jù)然后可以在Success回調(diào)中使用。當(dāng)裝載XML文件時,妳需要了解一下Ajax的基本語法。如上面代碼所示,我們設(shè)置類型為geturl設(shè)置為從"/path/to/data.xml"這個路徑獲取XML文件,然后還指明文件類型為XML。當(dāng)從服務(wù)器獲取了數(shù)據(jù)后,success error中的一個方法會被觸發(fā)。本例中,裝載成功的話會彈出窗口顯示所有節(jié)點(diǎn)數(shù)目。jQuery的星號選擇器表示匹配所有元素。最重要的一點(diǎn)是在回調(diào)函數(shù)中,第一個參數(shù)用來接收從服務(wù)器返回的數(shù)據(jù)。這個參數(shù)的名字隨便起,接下來的Context就被設(shè)置成了這個返回的數(shù)據(jù)。

    在處理Ajax相關(guān)的請求時需要注意跨域問題,出于安全性考慮一般不允許從不同的域獲取文件。所以上述例子中的代碼可能在妳實際的程序中有所不同。

     

    像處理XML一樣處理外部的XHTML

     

    因為XHTML是XML的一個子集,所以像XML一樣處理XHTML是完全沒有問題的。至于為什么妳有處理XHTML的需求是另一回事,但事實是妳確實可以這樣做。比如,導(dǎo)入一個XHTML頁面然后從中解析數(shù)據(jù)是可行的,雖然我會建議用另外更強(qiáng)健的方法來實現(xiàn)。

    盡管之前講述了DOM元素的遍歷和處理,jQuery同時也可以用來處理XML,雖然需要先將XML文件破費(fèi)周折地裝載進(jìn)代碼中。本節(jié)的內(nèi)容包含了不同的方法和基本的用于完成XML處理的例子。

    posted @ 2016-09-18 17:50 有機(jī)肥| 編輯 收藏

    用Jquery解析中國所有省市區(qū)的XML文檔(轉(zhuǎn))

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>省市區(qū)三級級聯(lián)</title>
    <script src="jquery-1.8.0.js"></script>
    <script>
    var d;
    $(document).ready(function (){
     
       $.ajax({
            url:"city.xml",
            dataType:"xml",
            success:function(data){
                d = data;
                $(data).find("province").each(function (i){
                    //往province中添加值
                    $("<option></option>").html($(this).attr("name")).attr("value",$(this).attr("name")).appendTo("#province");
                });
                chpro($("#province").attr("value"));  //選中的值傳給chpro函數(shù)
            }
        });
    });

    var c;
    function chpro(val){
        $("#city").empty();  //清空
        //遍歷province的name為val下的city
        $(d).find("province[name='"+val+"']").find("city").each(function (i){
            //往city中添加值  設(shè)置屬性value的值為當(dāng)前對象的屬性name的值
            $("<option></option>").html($(this).attr("name")).attr("value",$(this).attr("name")).appendTo("#city");
            c = val;
            chcity($("#city").attr("value"));
        });
    }

    function chcity(val){
        $("#area").empty();
        //遍歷province的name為c下的city的name為val下的area
        $(d).find("province[name='"+c+"']").find("city[name='"+val+"']").find("area").each(function (i){
            $("<option></option>").html($(this).attr("name")).attr("value",$(this).attr("name")).appendTo("#area");
        });
    }
    </script>
    </head>

    <body>
    <form id="myform">
    地址:<select id="province" onchange="chpro(this.value)" style="width:150px"></select>
    <select id="city" onchange="chcity(this.value)" style="width:150px"></select>
    <select id="area" style="width:150px"></select>
    </form>
    </body>
    </html>

    posted @ 2016-09-18 17:48 有機(jī)肥| 編輯 收藏

    手機(jī)web——自適應(yīng)網(wǎng)頁設(shè)計(轉(zhuǎn))

    文章主要參考于:http://www.ruanyifeng.com/blog/2012/05/responsive_web_design.html(阮一峰的網(wǎng)絡(luò)日志)


    在這篇文章的基礎(chǔ)上加上了寫自己的理解(文章藍(lán)色部分)。


    一. 允許網(wǎng)頁寬度自動調(diào)整:

    "自適應(yīng)網(wǎng)頁設(shè)計"到底是怎么做到的?其實并不難。

    首先,在網(wǎng)頁代碼的頭部,加入一行viewport元標(biāo)簽。


    <meta name="viewport" content="width=device-width, initial-scale=1" />


    viewport是網(wǎng)頁默認(rèn)的寬度和高度,上面這行代碼的意思是,網(wǎng)頁寬度默認(rèn)等于屏幕寬度(width=device-width),原始縮放比例(initial-scale=1)為1.0,即網(wǎng)頁初始大小占屏幕面積的100%。


    對于viewport屬性,我是真正在接觸移動web開發(fā)是才遇到的,一般的pc布局都是固定的960px,1000px這種。

    下面三篇文章是對viewport屬性詳細(xì)的解釋:

    Viewport(視區(qū)概念)——pc端的理解

    Viewport(視區(qū)概念)——移動端的應(yīng)用

    viewport ——視區(qū)概念(轉(zhuǎn))


    對于老式IE6,7,8瀏覽器需要js處理,由于主要平臺是ios和安卓,所以可以暫時不考慮


    二. 不使用絕對寬度

    由于網(wǎng)頁會根據(jù)屏幕寬度調(diào)整布局,所以不能使用絕對寬度的布局,也不能使用具有絕對寬度的元素。這一條非常重要。

    具體說,CSS代碼不能指定像素寬度:

    width:xxx px;

    只能指定百分比寬度:

    width: xx%; 

    或者:

    width:auto;


    這里開發(fā)是指一個網(wǎng)頁不僅能用在pc上,也能同時用于移動端,但是對于webapp這種還是需要單獨(dú)做一個webapp使用的頁面。

    對于這個知識點(diǎn),對于我目前做的項目有用處,主要用于控制限定數(shù)據(jù)庫里讀出來的圖片寬度。

    詳見:手機(jī)webapp的jquery mobile初次使用心得和解決圖片自適應(yīng)大小問題


    三. 相對大小的字體

    字體也不能使用絕對大小(px),而只能使用相對大小(em)。
      body {
        font: normal 100% Helvetica, Arial, sans-serif;
      }
    上面的代碼指定,字體大小是頁面默認(rèn)大小的100%,即16像素。
      h1 {
        font-size: 1.5em; 
      }
    然后,h1的大小是默認(rèn)大小的1.5倍,即24像素(24/16=1.5)。
      small {
        font-size: 0.875em;
      }
    small元素的大小是默認(rèn)大小的0.875倍,即14像素(14/16=0.875)。


    四. 流動布局(fluid grid)
    "流動布局"的含義是,各個區(qū)塊的位置都是浮動的,不是固定不變的。
      .main {
        float: right;
        width: 70%; 
      }
      .leftBar {
        float: left;
        width: 25%;
      }
    float的好處是,如果寬度太小,放不下兩個元素,后面的元素會自動滾動到前面元素的下方,不會在水平方向overflow(溢出),避免了水平滾動條的出現(xiàn)。
    另外,絕對定位(position: absolute)的使用,也要非常小心。


    五. "自適應(yīng)網(wǎng)頁設(shè)計"的核心,就是CSS3引入的Media Query模塊。
    它的意思就是,自動探測屏幕寬度,然后加載相應(yīng)的CSS文件。
      <link rel="stylesheet" type="text/css"
        media="screen and (max-device-width: 400px)"
        href="tinyScreen.css" />
    上面的代碼意思是,如果屏幕寬度小于400像素(max-device-width: 400px),就加載tinyScreen.css文件。
      <link rel="stylesheet" type="text/css"
        media="screen and (min-width: 400px) and (max-device-width: 600px)"
        href="smallScreen.css" />
    如果屏幕寬度在400像素到600像素之間,則加載smallScreen.css文件。
    除了用html標(biāo)簽加載CSS文件,還可以在現(xiàn)有CSS文件中加載。
      @import url("tinyScreen.css") screen and (max-device-width: 400px);


    六. CSS的@media規(guī)則
    同一個CSS文件中,也可以根據(jù)不同的屏幕分辨率,選擇應(yīng)用不同的CSS規(guī)則。
      @media screen and (max-device-width: 400px) {
        .column {
          float: none;
          width:auto;
        }
        #sidebar {
          display:none;
        }
      }
    上面的代碼意思是,如果屏幕寬度小于400像素,則column塊取消浮動(float:none)、寬度自動調(diào)節(jié)(width:auto),sidebar塊不顯示(display:none)。

    這篇文章有詳細(xì)的講解:手機(jī)web——自適應(yīng)網(wǎng)頁設(shè)計(@media使用)


    七. 圖片的自適應(yīng)(fluid image)
    除了布局和文本,"自適應(yīng)網(wǎng)頁設(shè)計"還必須實現(xiàn)圖片的自動縮放。
    這只要一行CSS代碼:
      img { max-width: 100%;}
    這行代碼對于大多數(shù)嵌入網(wǎng)頁的視頻也有效,所以可以寫成:
      img, object { max-width: 100%;}
    老版本的IE不支持max-width,所以只好寫成:
      img { width: 100%; }
    此外,windows平臺縮放圖片時,可能出現(xiàn)圖像失真現(xiàn)象。這時,可以嘗試使用IE的專有命令:
      img { -ms-interpolation-mode: bicubic; }
    或者,Ethan Marcotte的imgSizer.js。
      addLoadEvent(function() {
        var imgs = document.getElementById("content").getElementsByTagName("img");
        imgSizer.collate(imgs);
      });
    不過,有條件的話,最好還是根據(jù)不同大小的屏幕,加載不同分辨率的圖片。有很多方法可以做到這一條,服務(wù)器端和客戶端都可以實現(xiàn)。

    posted @ 2013-09-10 15:21 有機(jī)肥 閱讀(118) | 評論 (0)編輯 收藏

    flex event(zhuan)

    1. package com.montage.vo  

    2.     public class User  
    3.     {  
    4.         public function User() {}  
    5.         public var name:String;  
    6.         public var country:String; 
    7.     }  
    8. }  
    package com.montage.events  
    1. {  
    2.     import com.montage.vo.User;       
    3.     import flash.events.Event;  
    4.     public class UserEvent extends Event  
    5.     {  
    6.         public static var SELECTED_USER:String = "selectedUser";           
    7.         public var user:User;           
    8.         public function UserEvent(type:String,   bubbles:Boolean=false, cancelable:Boolean=false)  
    9.         {  
    10.             super(type, bubbles, cancelable);  
    11.         }  
    12.     }  
    13. }  

    1. package com.montage.model  
    2. {  
    3.     import flash.events.Event;  
    4.     import flash.events.EventDispatcher;
    5.  
    6.     [Event(name="selectedUser", type="com.montage.events.UserEvent")]
    7.     public class EventMessage extends EventDispatcher  
    8.     { 
    9.         private static var instance:EventMessage = null;  
    10.         public function EventMessage()  
    11.         {  
    12.             if( instance != null )  
    13.             {  
    14.                 throw new Error("EventMessage是一個單件類,只能被實例化一次!");  
    15.             }  
    16.         }  
    17.           
    18.         public static function getInstance():EventMessage  
    19.         {  
    20.             if( instance == null )  
    21.             {  
    22.                 instance = new EventMessage();  
    23.             }  
    24.             return instance;  
    25.         }      
    26.         public function send( event:Event ):void  
    27.         {  
    28.             dispatchEvent( event );  
    29.         }  
    30.     }  
    31. }  

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="選擇用戶">  
    3.     <mx:Script>  
    4.         <![CDATA[ 
    5.             import mx.controls.Alert; 
    6.             import com.montage.events.UserEvent; 
    7.             import com.montage.vo.User; 
    8.             import com.montage.model.EventMessage; 
    9.             import mx.managers.PopUpManager; 
    10.              
    11.             private var eMessage:EventMessage = EventMessage.getInstance(); 
    12.              
    13.             private function submitHandler():void 
    14.             { 
    15.                 if( grid.selectedIndex > -1 ) 
    16.                 { 
    17.                     var item:XML = XML( grid.selectedItem );
    18.                     var user:User = new User(); 
    19.                     user.name = item.@name; 
    20.                     user.country = item.@country;
    21.                     var event:UserEvent = new UserEvent( UserEvent.SELECTED_USER ); 
    22.                     event.user = user;
    23.                     eMessage.send( event ); 
    24.                     cancelHandler(); 
    25.                 } 
    26.                 else  { 
    27.                     Alert.show("請選擇一個用戶!"); 
    28.                 } 
    29.             } 
    30.              
    31.             private function cancelHandler():void 
    32.             { 
    33.                 PopUpManager.removePopUp( this ); 
    34.             } 
    35.         ]]>  
    36.     </mx:Script>  
    37.     <mx:XML id="users" source="user.xml"/>  
    38.     <mx:DataGrid id="grid" width="100%" height="100%" dataProvider="{users.User}">  
    39.         <mx:columns>  
    40.             <mx:DataGridColumn headerText="姓名" dataField="@name"/>  
    41.             <mx:DataGridColumn headerText="國家" dataField="@country"/>  
    42.         </mx:columns>  
    43.     </mx:DataGrid>  
    44.     <mx:ControlBar width="100%">  
    45.         <mx:Spacer width="100%"/>  
    46.         <mx:Button label="確定" click="submitHandler()"/>  
    47.         <mx:Button label="取消" click="cancelHandler()"/>  
    48.     </mx:ControlBar>  
    49. </mx:TitleWindow>  
               <root>  
    1.     <User name="David" country="America"/>  
    2.     <User name="Tome" country="Canada"/>  
    3.     <User name="Montage" country="China"/>  
    4. </root>
            <?xml version="1.0" encoding="utf-8"?>  
    1. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()" fontSize="12">  
    2.     <mx:Script>  
    3.         <![CDATA[ 
    4.             import com.montage.events.UserEvent; 
    5.             import com.montage.model.EventMessage; 
    6.             import mx.managers.PopUpManager; 
    7.             import com.montage.view.user.UserList; 
    8.              
    9.             private var eMessage:EventMessage = EventMessage.getInstance(); 
    10.              
    11.             private function init():void 
    12.             { 
    13.                 eMessage.addEventListener(UserEvent.SELECTED_USER, selectedUserHandler); 
    14.             } 
    15.              
    16.            
    17.             private function selectedUserHandler( event:UserEvent ):void 
    18.             { 
    19.                 textArea.htmlText = "你選擇了:<b>" + event.user.name + "</b>("+ event.user.country +")"; 
    20.             } 
    21.            
    22.             private function clickHandler():void 
    23.             { 
    24.                 var userList:UserList = UserList( PopUpManager.createPopUp(this, UserList, true) ); 
    25.                 userList.x = ( width - userList.width ) / 2; 
    26.                 userList.y = ( height - userList.height ) / 2; 
    27.             } 
    28.              
    29.         ]]>  
    30.     </mx:Script>  
    31.     <mx:Panel width="400" height="300" layout="vertical" paddingLeft="5" paddingRight="5" paddingTop="5">  
    32.         <mx:TextArea id="textArea" width="100%"/>  
    33.         <mx:Button label="選擇用戶" click="clickHandler()"/>  
    34.     </mx:Panel>  
    35. </mx:Application>

    posted @ 2012-03-20 11:17 有機(jī)肥 閱讀(250) | 評論 (0)編輯 收藏

    <2012年3月>
    26272829123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導(dǎo)航

    統(tǒng)計

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 最新亚洲成av人免费看| 亚洲av丰满熟妇在线播放| 亚洲AV无码一区二区二三区软件| 亚洲三级视频在线观看| 特黄特色的大片观看免费视频| 久久精品成人免费观看| 日韩免费观看一级毛片看看| 亚洲精品V欧洲精品V日韩精品| 亚洲精品日韩一区二区小说| a级日本高清免费看| 在线视频免费观看www动漫| 久久久久久久尹人综合网亚洲| 亚洲AV综合永久无码精品天堂| 国产成人久久AV免费| 免费v片在线观看无遮挡| 亚洲精品无码久久毛片波多野吉衣| 免费在线观看自拍性爱视频| 国产国产人免费视频成69堂| 浮力影院亚洲国产第一页| 亚洲国产乱码最新视频| 免费91最新地址永久入口 | 亚洲色图在线观看| 在线看亚洲十八禁网站| 亚洲视频在线免费播放| 在线播放亚洲第一字幕| 99亚洲乱人伦aⅴ精品| 日韩免费精品视频| 国产国拍亚洲精品mv在线观看| 精品亚洲视频在线| 国产精品免费观看| 亚洲国产精品lv| 中文字幕免费在线看| 国产成人3p视频免费观看| 亚洲人成网网址在线看| 一级毛片免费毛片一级毛片免费| 国产一级一片免费播放| 精品国产日韩久久亚洲| 午夜影院免费观看| 亚洲欧洲日产国码无码网站| 无套内射无矿码免费看黄| 女人毛片a级大学毛片免费|