leisure

          JAVA - exceed,helloworld
          隨筆 - 50, 文章 - 0, 評(píng)論 - 11, 引用 - 0
          數(shù)據(jù)加載中……

          2011年9月17日

          flash調(diào)用javascript

          flash.external.ExternalInterface.call("pop")

          posted @ 2013-01-11 10:34 leisure 閱讀(523) | 評(píng)論 (0)編輯 收藏

          spring2 JNDI

                <bean id= "myjndi" class= "org.springframework.jndi.JndiObjectFactoryBean" >
                       <property name ="jndiName" value= "java:comp/env/jdbc/myjndi" />
                </bean >

          posted @ 2013-01-11 10:33 leisure 閱讀(514) | 評(píng)論 (0)編輯 收藏

          兩個(gè)div在同一行

          <style>
          .b,.c{float:left; margin-right:10px;}
          </style>
          <div class="a">
            <div class="b">
                test
            </div>
            <div class="c">
                 testc
            </div>
          </div>

          posted @ 2013-01-11 10:32 leisure 閱讀(931) | 評(píng)論 (0)編輯 收藏

          Javascriptz格式化數(shù)字

          <script>
              
          /*** 格式化數(shù)字顯示方式
                  * 用法
                  * formatNumber(12345.999,'#,##0.00');
                  * formatNumber(12345.999,'#,##0.##');
                  * formatNumber(123,'000000');
                  * @param num* @param pattern
              
          */
              
          function formatNumber(num,pattern){
                  num 
          = Number(num);
                  
          var strarr = num?num.toString().split('.'):['0'];
                  
          var fmtarr = pattern?pattern.split('.'):[''];
                  
          var retstr='';    // 整數(shù)部分
                  var str = strarr[0];
                  
          var fmt = fmtarr[0];
                  
          var i = str.length-1;
                  
          var comma = false;
                  
          for(var f=fmt.length-1;f>=0;f--){
                      
          switch(fmt.substr(f,1)) {
                          
          case '#':
                              
          if(i>=0 ) retstr = str.substr(i--,1+ retstr;
                              
          break;
                          
          case '0':
                              
          if(i>=0) retstr = str.substr(i--,1+ retstr;else retstr = '0+ retstr;
                              
          break;
                          
          case ',':
                              comma 
          = true;
                              retstr
          =','+retstr;
                              
          break;
                      }
                  }
                  
          if(i>=0){
                      
          if(comma){
                          
          var l = str.length;
                          
          for(;i>=0;i--){
                              retstr 
          = str.substr(i,1+ retstr;
                              
          if(i>0 && ((l-i)%3)==0) retstr = ',' + retstr;
                          }
                      } 
          else 
                          retstr 
          = str.substr(0,i+1+ retstr;
                  }
                      retstr 
          = retstr+'.';// 處理小數(shù)部分
                      str=strarr.length>1?strarr[1]:'';
                      fmt
          =fmtarr.length>1?fmtarr[1]:'';
                      i
          =0;
                      
          for(var f=0;f<fmt.length;f++){
                          
          switch(fmt.substr(f,1)){
                              
          case '#':
                                  
          if(i<str.length) retstr+=str.substr(i++,1);
                                  
          break;
                              
          case '0':
                                  
          if(i<str.length) retstr+= str.substr(i++,1);
                                  
          else retstr+='0';
                                  
          break;
                              }
                      } 
                      
          return retstr.replace(/^,+/,'').replace(/\.$/,'');
              }
              
              document.write(
          "formatNumber('','')=" + formatNumber('',''));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(123456789012.129,null)=" + formatNumber(123456789012.129,null));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(null,null)=" + formatNumber(null,null));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(123456789012.129,'#,##0.00')=" + formatNumber(123456789012.129,'#,##0.00'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(123456789012.129,'#,##0.##')=" + formatNumber(123456789012.129,'#,##0.##'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(123456789012.129,'#0.00')=" + formatNumber(123456789012.129,'#,##0.00'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(123456789012.129,'#0.##')=" + formatNumber(123456789012.129,'#,##0.##'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(12.129,'0.00')=" + formatNumber(12.129,'0.00'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(12.129,'0.##')=" + formatNumber(12.129,'0.##'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(12,'00000')=" + formatNumber(12,'00000'));document.write("<br/>");
              document.write(
          "formatNumber(12,'#.##')=" + formatNumber(12,'#.##'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(12,'#.00')=" + formatNumber(12,'#.00'));
              document.write(
          "<br/>");
              document.write(
          "formatNumber(1080.0,'#.##')=" + formatNumber(1100.0,'#,###.##'));
              document.write(
          "<br/>");
          </script>

          posted @ 2013-01-11 10:30 leisure 閱讀(286) | 評(píng)論 (0)編輯 收藏

          去掉eclipse的validate

          困擾了好幾天,與大家共享

          1,在project名稱(chēng)上右鍵選擇properties,打開(kāi)屬性窗口,選擇左邊的validation

          2,勾選enable project specific setting;

          3,點(diǎn)擊Disable all,點(diǎn)擊OK關(guān)閉窗口

          4,在project名稱(chēng)上右鍵validate

          備注:suspend all validators勾選沒(méi)有效果,另外第4步很重要

          posted @ 2013-01-11 10:20 leisure 閱讀(7088) | 評(píng)論 (0)編輯 收藏

          spring method interceptor

          spring method interceptor

          -author: leisure.xu

          首先dao里面有find和save方法,本實(shí)例以攔截find方法為主,并改變find的返回值。

          package com.leisure;

          public class Dao {

               public String find() {

                    System. out.println( "dao: find()");

                    return "student";

               }

               public void save() {

                    System. out.println( "dao: save()");

               }

          }

          一、新增一個(gè)DaoInterceptor,如下

          package com.leisure;

          import org.aopalliance.intercept.MethodInterceptor;

          import org.aopalliance.intercept.MethodInvocation;

          /**

           * class description goes here

           * @author leisure.xu

           * @version 1.0.0, 2012 -6 -29

           */

          public class DaoInterceptor implements MethodInterceptor {

               @Override

               public Object invoke(MethodInvocation invocation) throws Throwable {

                    String methodName = invocation.getMethod().getName();

                    if( "find".equals(methodName)) {

                         System. out.println( "invocation modify the return result to 'teacher'");

                         return "teacher";

                    }

                    return invocation.proceed();

               } 

          }

               DaoInterceptor實(shí)現(xiàn)了MethodInterceptor的invoke方法,在這里,MethodInvocation參數(shù)可以獲取到getArguments等數(shù)據(jù),至于能做什么,你懂的。

          二、Dao跟DaoInterceptor還是沒(méi)扯上關(guān)系,這時(shí)需要修改applicationContext.xml

               原來(lái):

               <bean id = "dao" class= "com.leisure.Dao"/>

          修改為:

                    <!--

                <bean id=" dao" class="com.leiusre.Dao"/>

               -->

               <bean id ="daoInterceptor" class="com.leisure.DaoInterceptor"/>

               <bean id ="dao" class= "org.springframework.aop.framework.ProxyFactoryBean" >

                    <property name ="target">

                         <bean class ="com.leisure.Dao" />

                    </property >

                    <property name ="interceptorNames">

                         <list >

                              <value >daoInterceptor </value >

                         </list >

                    </property >

               </bean >

          三、運(yùn)行看效果!

               ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml" );

               Dao dao = context.getBean(Dao. class);

               System. out.println(dao.find());

               dao.save();

          結(jié)果:

          invocation modify the return result to 'teacher'

          teacher

          dao: save()

          從結(jié)果可以看出invocation攔截了find方法,并且修改了其返回結(jié)果,而對(duì)象的find方法并沒(méi)有執(zhí)行到。

          該實(shí)例引用到的jar包:




          posted @ 2012-07-11 09:14 leisure 閱讀(998) | 評(píng)論 (0)編輯 收藏

          spring2.0的jndi配置

          <!--
           <jee:jndi-lookup id="application" jndi-name="java:comp/env/app-name"/>
              -->
          改成
          <bean id="application" class="org.springframework.jndi.JndiObjectFactoryBean">
          <property name="jndiName" value="java:comp/env/app-name" />
          </bean>

          posted @ 2012-06-27 16:30 leisure 閱讀(309) | 評(píng)論 (0)編輯 收藏

          Caused by: java.lang.IllegalArgumentException: null source 解決

          1 Caused by: java.lang.IllegalArgumentException: null source
          2     at java.util.EventObject.<init>(EventObject.java:38)
          3     at javax.sql.StatementEvent.<init>(StatementEvent.java:39)
          4     at com.mysql.jdbc.jdbc2.optional.JDBC4PreparedStatementWrapper.close(JDBC4PreparedStatementWrapper.java:70)
          5     at com.caucho.sql.UserStatement.close(UserStatement.java:163)
          6     at com.caucho.sql.UserPreparedStatement.close(UserPreparedStatement.java:727)

          開(kāi)始使用的是:mysql-connector-java-5.1.6-bin
          更換新的mysql驅(qū)動(dòng)包就沒(méi)問(wèn)題了(mysql-connector-java-5.1.11-bin)

          posted @ 2012-06-15 12:10 leisure 閱讀(3380) | 評(píng)論 (0)編輯 收藏

          redis五天親密旅程

          FIRST DAY
          redis介紹、安裝使用(win、linux)
          redis數(shù)據(jù)類(lèi)型
          redis-twitter實(shí)例分析
          驅(qū)動(dòng)選材-Jedis
          初探spring data - redis

          SECOND DAY
          項(xiàng)目架構(gòu)搭建 spring + spring data redis + jedis
          redisTemplate、jedis常用的API熟悉
          spring data - redis源碼解剖

          THIRD DAY
          redis數(shù)據(jù)庫(kù)設(shè)計(jì)理念及應(yīng)用場(chǎng)景分析
          深入探究數(shù)據(jù)類(lèi)型

          FOURTH Day
           項(xiàng)目實(shí)戰(zhàn)

          FIFTH DAY
          內(nèi)存優(yōu)化,設(shè)計(jì)優(yōu)化
           分布式集群方案

          posted @ 2012-04-12 10:10 leisure 閱讀(530) | 評(píng)論 (0)編輯 收藏

          游戲數(shù)據(jù)庫(kù)上線拉

          新應(yīng)用,游戲數(shù)據(jù)庫(kù),為你提供詳盡的游戲資料。


          posted @ 2012-04-11 08:54 leisure 閱讀(329) | 評(píng)論 (0)編輯 收藏

          應(yīng)用啟動(dòng)時(shí),attempting to get SockIO from uninitialized pool!

          在spring配置文件中,沒(méi)有將實(shí)例名稱(chēng)對(duì)應(yīng)上,導(dǎo)致mc client無(wú)法從一個(gè)未初始化的池里獲取數(shù)據(jù)。

              <bean id="sockIOPool" class="com.danga.MemCached.SockIOPool"
                  factory-method
          ="getInstance" init-method="initialize" destroy-method="shutDown"
                  p:initConn
          ="${memcached.initConn}"
                  p:minConn
          ="${memcached.minConn}"
                  p:maxConn
          ="${memcached.maxConn}"
                  p:maintSleep
          ="${memcached.maintSleep}"
                  p:nagle
          ="${memcached.nagle}"
                  p:socketTO
          ="${memcached.socketTO}"
                  p:servers
          ="${memcached.servers}">
                  <constructor-arg value="myName"/>
              </bean>
              
              <bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
                  <constructor-arg value="myName"/> 
                  <property name="sanitizeKeys" value="false"/>
                  <property name="compressEnable"   value="true"/>
                  <property name="compressThreshold" value="1024"/>
              </bean>

          注意<constructor-arg value="myName"/> 中的myName要保持一致。

          posted @ 2012-02-17 14:44 leisure 閱讀(3464) | 評(píng)論 (1)編輯 收藏

          eclipse安裝svn客戶(hù)端

          下載相應(yīng)的插件版本
          把解壓的內(nèi)容放置eclipse\dropins\svn\目錄下(svn目錄不存在則創(chuàng)建)
          完成后,重啟eclipse,重啟完后,提示安裝svn connector,選擇一個(gè)安裝即可,安裝完后,再一次重啟。
          window - show view - other - svn 下即可以看到svn控制視圖

          posted @ 2012-01-25 10:59 leisure 閱讀(310) | 評(píng)論 (0)編輯 收藏

          hello,spring3

          spring很早就更新了3.0版本,可是由于項(xiàng)目要求穩(wěn)定,卻一直沒(méi)有使用到,最近有個(gè)新項(xiàng)目,打算采用spring3了。

          項(xiàng)目整個(gè)結(jié)構(gòu)如下:


           1 <?xml version="1.0" encoding="UTF-8"?>
           2 <beans xmlns="http://www.springframework.org/schema/beans"
           3      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           4      xmlns:p="http://www.springframework.org/schema/p"
           5      xsi:schemaLocation="http://www.springframework.org/schema/beans
           6      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
           7      
           8     <bean id="dao" class="Dao"/>
           9     
          10 </beans>

          1 
          2 public class Dao {
          3     public void find() {
          4         System.out.println("dao: find()");
          5     }
          6 }
          7 

           1 import org.springframework.context.ApplicationContext;
           2 import org.springframework.context.support.ClassPathXmlApplicationContext;
           3 
           4 public class Client {
           5 
           6     public static void main(String[] args) {
           7         ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
           8         Dao dao = context.getBean(Dao.class);
           9         dao.find();
          10     }
          11 }
          12 

          posted @ 2011-12-29 16:02 leisure 閱讀(211) | 評(píng)論 (0)編輯 收藏

          java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

          獲取泛型參數(shù)的類(lèi)型
                  
          Class<TentityClass = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];

          出現(xiàn):
          java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType

          使用以下工具類(lèi)方法獲取~
           1 package cn.pconline.prolib.util;
           2 import java.lang.reflect.ParameterizedType;  
           3 import java.lang.reflect.Type;  
           4   
           5 public class GenericsUtils {  
           6     /**   
           7      * 通過(guò)反射,獲得定義Class時(shí)聲明的父類(lèi)的范型參數(shù)的類(lèi)型.   
           8      * 如public BookManager extends GenricManager<Book>   
           9      *   
          10      * @param clazz The class to introspect   
          11      * @return the first generic declaration, or <code>Object.class</code> if cannot be determined   
          12      */  
          13     public static Class getSuperClassGenricType(Class clazz) {  
          14         return getSuperClassGenricType(clazz, 0);  
          15     }  
          16   
          17     /**   
          18      * 通過(guò)反射,獲得定義Class時(shí)聲明的父類(lèi)的范型參數(shù)的類(lèi)型.   
          19      * 如public BookManager extends GenricManager<Book>   
          20      *   
          21      * @param clazz clazz The class to introspect   
          22      * @param index the Index of the generic ddeclaration,start from 0.   
          23      */  
          24     public static Class getSuperClassGenricType(Class clazz, int index) throws IndexOutOfBoundsException {  
          25   
          26         Type genType = clazz.getGenericSuperclass();  
          27   
          28         if (!(genType instanceof ParameterizedType)) {  
          29             return Object.class;  
          30         }  
          31   
          32         Type[] params = ((ParameterizedType) genType).getActualTypeArguments();  
          33   
          34         if (index >= params.length || index < 0) {  
          35             return Object.class;  
          36         }  
          37         if (!(params[index] instanceof Class)) {  
          38             return Object.class;  
          39         }  
          40         return (Class) params[index];  
          41     }  
          42 }  

                  
          Class<TentityClass = GenericsUtils.getSuperClassGenricType(BasicService.class0);

          posted @ 2011-12-26 14:37 leisure 閱讀(17896) | 評(píng)論 (4)編輯 收藏

          淺淡Java代理模式之秘書(shū)MM

          代理對(duì)象一般定義了一個(gè)與目標(biāo)對(duì)象相似或相近的行為。代理對(duì)象負(fù)責(zé)對(duì)真實(shí)模塊調(diào)用,這使得調(diào)用者與被調(diào)用者之間建立了一個(gè)隔離帶。
          場(chǎng)景示例說(shuō)明:老總說(shuō)話(huà)都是很精簡(jiǎn),每次發(fā)布一個(gè)消息時(shí),總是先將簡(jiǎn)要內(nèi)容交給秘書(shū)MM,秘書(shū)MM經(jīng)過(guò)一番美化后,把消息公布出來(lái)。

          設(shè)老總=Boss,秘書(shū)MM=MMProxy

          于是簡(jiǎn)單的代理就有
          1 public class Boss {
          2     public void anounce(String content) {
          3         System.out.println(content);
          4     }
          5 }

          1 public class MMProxy {
          2     public void anounce(String content) {
          3         System.out.print("boss: 大家請(qǐng)注意了!");
          4         new Boss().anounce(content);
          5     }
          6 }

          new MMProxy().anounce("我請(qǐng)大家吃飯。");

          結(jié)果出來(lái)的是:
          boss: 大家請(qǐng)注意了!我請(qǐng)大家吃飯。

          通過(guò)上面發(fā)現(xiàn),這種代理比較呆板,比如說(shuō),Boss口渴了,又得重新寫(xiě)一個(gè)代理方法,這個(gè)時(shí)候,可以使用動(dòng)態(tài)代理來(lái)進(jìn)行:

          添加一個(gè)接口IBoss
          1 public interface IBoss {
          2     public void anounce(String content);
          3     public void drink();
          4 }

          修改Boss
          1 public class Boss implements IBoss {
          2     public void anounce(String content) {
          3         System.out.println(content);
          4     }
          5 
          6     public void drink() {
          7         System.out.println("boss: 拿起杯子,喝水");
          8     }
          9 }

          這時(shí)秘書(shū)MM變?yōu)?/div>
           1 import java.lang.reflect.InvocationHandler;
           2 import java.lang.reflect.Method;
           3 
           4 public class MMProxy implements InvocationHandler {
           5 
           6     private Object obj;
           7 
           8     public MMProxy(Object obj) {
           9         this.obj = obj;
          10     }
          11 
          12     public static Object newInstance(Object obj) {
          13         return java.lang.reflect.Proxy.newProxyInstance(
          14             obj.getClass().getClassLoader(),
          15             obj.getClass().getInterfaces(),
          16             new MMProxy(obj));
          17     }
          18     
          19     @Override
          20     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
          21         if("drink".equals(method.getName())) {
          22             System.out.println("秘書(shū)MM: 看到boss想喝水了,于是 把水倒進(jìn)boss的杯子里。");
          23         } else if("anounce".equals(method.getName())) {
          24             System.out.print("boss: 大家請(qǐng)注意!");
          25         }
          26         method.invoke(obj, args);
          27         return null;
          28     }
          29 }

                  IBoss boss = (IBoss) MMProxy.newInstance(new Boss());
                  boss.anounce(
          "我請(qǐng)大家吃飯。");
                  boss.drink();

          boss: 大家請(qǐng)注意!我請(qǐng)大家吃飯。
          秘書(shū)MM: 看到boss想喝水了,于是 把水倒進(jìn)boss的杯子里。
          boss: 拿起杯子,喝水

          現(xiàn)在發(fā)現(xiàn)了吧,秘書(shū)MM真是服務(wù)周到呀。

          posted @ 2011-12-09 09:54 leisure 閱讀(257) | 評(píng)論 (0)編輯 收藏

          [nginx]post數(shù)據(jù)莫名奇妙丟失事件

          昨天快下班的時(shí)候,有位同事遇到post數(shù)據(jù)接收不到的問(wèn)題

          首先網(wǎng)絡(luò)架構(gòu)是:
               nginx1
                 |  rewrite
               nginx2
                 |  pass
               resin1

          nginx1是在192.168.1.1上
          nginx2跟resin1是在192.168.1.2上

          首先訪問(wèn)nginx1,由nginx1 rewrite到nginx2,nginx2直接pass到resin1,整個(gè)過(guò)程是POST形式。至于
          為什么要用兩層nginx,這當(dāng)然是有原因的了:-)

          于是乎,快速制定了幾個(gè)測(cè)試案例:
          1,兩種訪問(wèn)方式:GET,POST
             GET URL帶參數(shù),沒(méi)有問(wèn)題。
             POST 有問(wèn)題。
             讓網(wǎng)絡(luò)同事檢查,處理這個(gè)location并沒(méi)有做什么特殊的POST處理。——!
          2,訪問(wèn)nginx1時(shí),直接pass到resin1,跳過(guò)nginx2
             問(wèn)題依舊。
          3,去掉nginx1,訪問(wèn)nginx2,直接pass到resin1
             有數(shù)據(jù)的。
          4,直接訪問(wèn)resin1
             是有數(shù)據(jù)的。

          到這里,我感到很奇怪,為啥,為啥nginx1傳遞不了post數(shù)據(jù)呀,而nginx2可以,問(wèn)題肯定出現(xiàn)在nginx1的配置上!~經(jīng)過(guò)一番斗爭(zhēng)后,終于找到問(wèn)題關(guān)鍵
          nginx1中,配置了一個(gè)全的post處理
          if($request_method = POST) {
             rewrite .* /post.php last;
          }
          最后,只能大眼望細(xì)眼,汗一滴。

          posted @ 2011-11-25 12:07 leisure 閱讀(5933) | 評(píng)論 (0)編輯 收藏

          反射判斷成員變量是否靜態(tài),并獲得其靜態(tài)成員的值

                  Field[] fields = cls.getDeclaredFields();
                  Field field 
          = fields[0];
                  
          boolean isStatic = Modifier.isStatic(field.getModifiers());
                  if(isStatic) {
                      System.out.println(
          field.get(null).toString());
                  }

          posted @ 2011-11-23 17:06 leisure 閱讀(7100) | 評(píng)論 (0)編輯 收藏

          npm ERR! Error: socket hang up

          when i use npm to install express, it goes this message:

          npm info it worked if it ends with ok
          npm info using npm@1.0.106
          npm info using node@v0.6.2
          npm info addNamed [ 'express', '' ]
          npm ERR! Error: socket hang up
          npm ERR! at createHangUpError (http.js:1092:15)
          npm ERR! at CleartextStream. (http.js:1175:27)
          npm ERR! at CleartextStream.emit (events.js:88:20)
          npm ERR! at Array.0 (tls.js:731:22)
          npm ERR! at EventEmitter._tickCallback (node.js:192:40)
          npm ERR! Report this entire log at:
          npm ERR! http://github.com/isaacs/npm/issues
          npm ERR! or email it to:
          npm ERR! npm-@googlegroups.com
          npm ERR! 
          npm ERR! System Linux 3.0.0-12-generic
          npm ERR! command "node" "/usr/local/bin/npm" "install" 
          "express" "-d"
          npm ERR! cwd /home/leisure/software/node-v0.6.2
          npm ERR! node -v v0.6.2
          npm ERR! npm -v 1.0.106
          npm ERR! code ECONNRESET
          npm ERR! 
          npm ERR! Additional logging details can be found in:
          npm ERR! /home/leisure/software/node-v0.6.2/npm-
          debug.log
          npm 

          it sounds the https_proxy is broken.
          so try to use http registry to solve it:
          npm config set registry http://registry.npmjs.org/

          posted @ 2011-11-23 15:11 leisure 閱讀(3328) | 評(píng)論 (1)編輯 收藏

          MYSQL Error Code: 1093 You can't specify target table 'x' for update in FROM clause

          當(dāng)子查詢(xún)作為條件,執(zhí)行delete跟update操作時(shí),會(huì)出現(xiàn):
          Error Code: 1093 You can't specify target table 'x' for update in FROM clause

          作一個(gè)簡(jiǎn)單的示例:
          CREATE TABLE tbl_a(
          id 
          INT,
          NAME 
          VARCHAR(50)
          );

          INSERT INTO tbl_a VALUES(1'leisure');
          INSERT INTO tbl_a VALUES(2'leisure2');

          SELECT * FROM tbl_a;

          執(zhí)行更新操作
          UPDATE tbl_a 
              
          SET id = (
                  
          SELECT id FROM tbl_a 
                  
          WHERE NAME = 'leisure2'
              ) 
          WHERE NAME = 'leisure';

          這時(shí),如愿見(jiàn)到我們標(biāo)題上的錯(cuò)誤,解決方法如下(橙色字體系關(guān)鍵):
          UPDATE tbl_a 
              
          SET id = (
                  
          SELECT id FROM (
                      
          SELECT * FROM tbl_a WHERE NAME = 'leisure2'
                  ) xx
              )
          WHERE NAME = 'leisure';

          posted @ 2011-11-22 09:58 leisure 閱讀(3546) | 評(píng)論 (1)編輯 收藏

          解決IE下location.href丟失refer信息

          相信有很多朋友,用javascript做一些跳轉(zhuǎn)時(shí),往往發(fā)現(xiàn)refer信息丟失了。為了解決該問(wèn)題,在IE下,模擬一下點(diǎn)擊事件即可!

          function jumpTo (url) {
              var isIE 
          = !-[1,];
              if (isIE) {
                  var link 
          = document.createElement("a");
                  link.href 
          = url;
                  link.style.display 
          = 'none';
                  document.body.appendChild(link);
                  link.click();
              } 
          else {
                  window.location.href 
          = url;
              }
          }

          posted @ 2011-11-17 16:54 leisure 閱讀(1064) | 評(píng)論 (0)編輯 收藏

          nginx gzip 代理服務(wù)器沒(méi)效

          昨天新上線了一個(gè)新應(yīng)用。經(jīng)測(cè)試發(fā)現(xiàn),采用代理,沒(méi)有開(kāi)啟到gzip壓縮。
          查了一下API,將gzip_proxied設(shè)為any即可。
          gzip_proxied系根據(jù)某些請(qǐng)求和應(yīng)答來(lái)決定是否在對(duì)代理請(qǐng)求的應(yīng)答啟用壓縮。

          posted @ 2011-11-16 14:53 leisure 閱讀(456) | 評(píng)論 (0)編輯 收藏

          utuntu登錄qq(qq2010協(xié)議)

          #add-apt-repository ppa:microcai/forchina
          #apt-get install libqq-pidgin
          如果安裝過(guò)程中提示E: Unable to locate package libqq-pidgin,請(qǐng)先更新一下庫(kù):
          #apt-get update

          接著重新再安裝一次。安裝完后,在empathy中添加賬號(hào),在高級(jí)處,記得把qq2008改成qq2010這個(gè)協(xié)議了!

          posted @ 2011-11-12 16:17 leisure 閱讀(399) | 評(píng)論 (0)編輯 收藏

          ubuntu開(kāi)啟ssh服務(wù)

          ubuntu默認(rèn)情況下只安裝了openssh-client,沒(méi)有安裝openssh-server。
          #sudo apt-fast install openssh-server
          #/etc/init.d/ssh start
          #netstat -tlp
          顯示tcp 0 0 *:ssh *:* LISTEN即說(shuō)明SSH啟動(dòng)成功。

          posted @ 2011-11-06 12:54 leisure 閱讀(239) | 評(píng)論 (0)編輯 收藏

          ubuntu安裝五筆輸入法(ibus-table-wubi)

          IBus-Table是為基于碼表的輸入法即所謂的形碼開(kāi)發(fā)的輸入法框架,常見(jiàn)的形碼有鄭碼、五筆、倉(cāng)頡、二筆等。

          安裝如下:
          # apt-get install ibus-table-wubi

          開(kāi)啟ibus輸入法,按操作提示即可。
          System - Preferences - Keyboard Input Methods

          開(kāi)啟完后,回到剛才的配置選項(xiàng)
          Input Method - 選擇 Chinese - 五 Wubi86 - Add

          在文本框里,ctrl + space即可切換輸入法。

          默認(rèn)情況下,ibus-table不開(kāi)啟直接上屏模式(即敲完四個(gè)碼,沒(méi)有重碼時(shí),直接顯示到屏幕上),在五筆輸入法下 Ctrl + / 即可。

          開(kāi)機(jī)自動(dòng)啟動(dòng)ibus
          System - Preferences - Startup Applications - Add
          Name: ibus daemon
          Command: /usr/bin/ibus-daemon -d
          Comment: start ibus daemon when gnome start

          posted @ 2011-11-06 12:31 leisure 閱讀(39816) | 評(píng)論 (2)編輯 收藏

          android瀏覽本地html

          android訪問(wèn)本地html,有幾種方法。

          1,可以采用自帶的瀏覽器,地址欄鍵入content://com.android.htmlfileprovider/sdcard/index.html

          2,可以通過(guò)opera瀏覽器,地址欄輸入file://localhost/mnt/sdcard/index.html

          3,通過(guò)ireader直接打開(kāi)瀏覽

          看html文檔的話(huà),第一,二兩點(diǎn)完美,可以靈活縮放,瀏覽起來(lái)跟在線瀏覽沒(méi)區(qū)別,至于第三點(diǎn),不支持縮放,并且樣式也有點(diǎn)小問(wèn)題。另外,第一點(diǎn)可以直接打開(kāi)apk,而第二點(diǎn)需要先下載,根據(jù)提示打開(kāi)。呵呵,這種情況適合刷了官方room并且沒(méi)有文件瀏覽器的情況下安裝軟件。

          posted @ 2011-11-05 20:17 leisure 閱讀(1145) | 評(píng)論 (0)編輯 收藏

          resin下定義mime-mapping

          mime-mapping系web服務(wù)器提供給web站點(diǎn)管理員能夠?qū)⑽募U(kuò)展名與媒體相關(guān)聯(lián)的方法。
          由于某種原因,有些請(qǐng)求到了/favicon.ico。chrome變了下載。
          resin的conf/app-default.xml
          <mime-mapping extension=".ico" mime-type="image/jpeg"/>

          posted @ 2011-11-03 15:47 leisure 閱讀(392) | 評(píng)論 (0)編輯 收藏

          SimpleDateFormat多線程并發(fā)下的不安全隱患

          最近偶然發(fā)現(xiàn)一些數(shù)據(jù)的日期有錯(cuò)亂,而且時(shí)間出錯(cuò)格式無(wú)規(guī)律,有些去了1970年了,有些月份錯(cuò)了,有些號(hào)數(shù)變了,而日志上看并沒(méi)有異常信息!

          根據(jù)用戶(hù)反應(yīng),常出現(xiàn)在某個(gè)批量更新操作中,于是乎,也按照用戶(hù)描述的,線下操作了數(shù)遍,也沒(méi)有出現(xiàn)這種情況。

          有趣的是,就算在線上操作,也并不是一定會(huì)出現(xiàn)這種問(wèn)題,只是偶然!

          我開(kāi)始懷疑底層代碼問(wèn)題了,因?yàn)槟莻€(gè)操作,并沒(méi)有修改到日期相關(guān)的字段,為了證實(shí)這點(diǎn),經(jīng)過(guò)我一番的排查,
          問(wèn)題終于定位在DateUtil.parse等方法上,parse方法調(diào)用了一個(gè)靜態(tài)的simpleDateFormat.parse方法,為什么?!為什么這個(gè)方法不穩(wěn)定的?
          仔細(xì)閱讀了java.util.SimpleDateFormat的api,發(fā)現(xiàn)此信息:

          Synchronization

          Date formats are not synchronized. It is recommended to create separate format instances for each thread.
          If multiple threads access a format concurrently, it must be synchronized externally.


          很明顯simpledateformat并不是線程同步的,以致并發(fā)的時(shí)候不安全!為了證實(shí)這點(diǎn)于是乎寫(xiě)了一個(gè)簡(jiǎn)單的測(cè)試程序。

          package com.leisure;
          import java.text.ParseException;
          public class TestSimpleDateFormatThreadSafe extends Thread {
              @Override
              public void run() {
                  while(true) {
                      try {
                          this.join(2000);
                      } 
          catch (InterruptedException e1) {
                          e1.printStackTrace();
                      }
                      try {
                          System.out.println(DateUtil.parse(
          "2011-10-11 06:02:20"));
                      } 
          catch (ParseException e) {
                          e.printStackTrace();
                      }
                  }
              }

              public static void main(String[] args) {
                  for(int i = 0; i < 20; i++)
                      new TestSimpleDateFormatThreadSafe().start();
              }
          }

          package com.leisure;

          import java.text.ParseException;
          import java.text.SimpleDateFormat;
          import java.util.Date;

          public class DateUtil {
              
          private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

              
          public static Date parse(String str) throws ParseException {
                  
          return sdf.parse(str);
              }
          }

          輸出結(jié)果:

          Tue Oct 11 18:02:20 CST 2011

          Tue Oct 11 18:02:20 CST 2011

          Sun Oct 11 18:02:20 CST 1970

          Tue Oct 11 18:02:20 CST 2011

          Thu Jan 01 18:02:20 CST 1970

          Sat Dec 11 18:02:20 CST 2010

          Tue Oct 11 18:02:20 CST 2011

          Exception in thread "Thread-18" java.lang.NumberFormatException: multiple points

          at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)

          at java.lang.Double.parseDouble(Unknown Source)

          at java.text.DigitList.getDouble(Unknown Source)

          at java.text.DecimalFormat.parse(Unknown Source)

          at java.text.SimpleDateFormat.subParse(Unknown Source)

          at java.text.SimpleDateFormat.parse(Unknown Source)

          at java.text.DateFormat.parse(Unknown Source)

          at com.leisure.DateUtil.parse(DateUtil.java:12)

          at com.leisure.TestSimpleDateFormatThreadSafe.run(TestSimpleDateFormatThreadSafe.java:16)

          Fri Dec 23 19:02:20 CST 2011

          Fri Dec 23 18:02:20 CST 2011

          輸出結(jié)果很明顯了,跟線上數(shù)據(jù)出現(xiàn)的問(wèn)題基本一致。不過(guò)按照這里看到的結(jié)果,有報(bào)錯(cuò),再仔細(xì)閱讀了應(yīng)用的底層代碼,
          某個(gè)位置攔截了部份異常,沒(méi)有記錄也沒(méi)有向上拋出處理,到這里,我只想問(wèn)一句:底層代碼誰(shuí)寫(xiě)的?

          posted @ 2011-10-15 00:22 leisure 閱讀(2870) | 評(píng)論 (0)編輯 收藏

          30個(gè)開(kāi)發(fā)人員最常用的linux命令

          free 查看內(nèi)存使用信息
          top 顯示cpu進(jìn)程信息
          ps 顯示進(jìn)程列表
          kill 殺死進(jìn)程
          df 查看硬盤(pán)剩余空間
          crontab 系統(tǒng)定時(shí)任務(wù)
          passwd 密碼管理
          cal 查看日歷
          date 查看時(shí)間
          chmod 改變文件權(quán)限
          clear 屏幕顯示信息太多?清理一下
          cat/tail 查看文件
          sort 排序文本內(nèi)容
          vi 編輯文件
          find 查找文件
          grep 查找文件中配匹配的信息
          cp  復(fù)制文件
          touch 創(chuàng)建文件
          mv 移動(dòng)文件
          rm 移除文件
          ls 顯示目錄的文件列表
          mkdir 創(chuàng)建文件夾
          tar GNU 壓縮工具
          make GNU make 工具
          gzip zip壓縮工具
          ln/lndir 建立鏈接
          mount 掛載信息
          ftp ftp鏈接工具
          telnet telnet連接工具
          ssh ssh連接工具

          posted @ 2011-10-14 10:44 leisure 閱讀(287) | 評(píng)論 (0)編輯 收藏

          Internet Explorer 無(wú)法打開(kāi)Internet 站點(diǎn)http://xxx.com 已終止操作


          Internet Explorer 無(wú)法打開(kāi)Internet 站點(diǎn)http://xxx.com
          已終止操作
          確定
          在ie6或者ie7,會(huì)出現(xiàn)這種情況,原因絕大多數(shù)是在頁(yè)面尚未加載完就操作節(jié)點(diǎn)。

          解決方法:把初始化操作的腳本放到頁(yè)面底部,或把初始化操作的腳本放到window.onload函數(shù)中,如果是加載外部script,在script標(biāo)簽中加入class="defer"屬性。
          注意:曾經(jīng)嘗把初始化操作腳本放在setTimeout函數(shù)中,經(jīng)長(zhǎng)期測(cè)試,絕大多數(shù)時(shí)候可行,但在頁(yè)面數(shù)據(jù)比較多,刷新多次偶然也會(huì)出現(xiàn)!

          posted @ 2011-10-13 10:21 leisure 閱讀(677) | 評(píng)論 (0)編輯 收藏

          jstl創(chuàng)建map和對(duì)map賦值

          jstl本身是沒(méi)有語(yǔ)法技持創(chuàng)建對(duì)象的,不過(guò)我們可以使用jsp:useBean標(biāo)簽來(lái)創(chuàng)建,然后使用c:set標(biāo)簽來(lái)賦相
          應(yīng)的值。
          <jsp:useBean id="map" class="java.util.HashMap" scope="request">
          <c:set target="${map}" property="a" value="b" />
          </jsp:useBean>
          ${map}
          另外c:remove可以移除相應(yīng)的屬性。

          posted @ 2011-10-12 08:46 leisure 閱讀(1455) | 評(píng)論 (0)編輯 收藏

          eclipse添加git功能

          Git是一個(gè)開(kāi)源的分布式版本控制系統(tǒng),提供了非常快捷和強(qiáng)大的項(xiàng)目版本管理功能。
          EGit項(xiàng)目是一個(gè)基于Eclipse插件開(kāi)發(fā)的,很大程度上方便了我們Eclipse一族。
          Help-->Install New Software-->Add
          Egit
          http://download.eclipse.org/egit/updates/ 
          注意egit對(duì)應(yīng)eclipse的版本~
          然后按默認(rèn)操作,待確認(rèn)重啟即完成安裝!

          posted @ 2011-10-11 09:36 leisure 閱讀(6663) | 評(píng)論 (0)編輯 收藏

          記一段mysql優(yōu)化體驗(yàn)

               摘要: 今天優(yōu)化了一個(gè)查詢(xún)語(yǔ)句,覺(jué)得蠻可以的,拿出來(lái)跟大家分享一下,為方便起見(jiàn),用了三個(gè)表作為示例說(shuō)明。分別有:
          tbl_commpany主要是記錄廠商的信息,包括該廠商的狀態(tài)。
          tbl_product主要是記錄產(chǎn)品的信息,包括產(chǎn)品的狀態(tài),與廠商信息表關(guān)聯(lián)。
          tbl_company_top主要記錄廠商瀏覽訪問(wèn)的排行榜信息(按年)。  閱讀全文

          posted @ 2011-10-09 12:20 leisure 閱讀(284) | 評(píng)論 (0)編輯 收藏

          推薦幾本程序員必讀的書(shū)籍

               摘要: 讀過(guò)了不少的書(shū)籍,細(xì)數(shù)這幾年,算起來(lái),買(mǎi)書(shū)也花了不少銀兩,在此推薦幾本必讀的書(shū)籍。  閱讀全文

          posted @ 2011-10-05 00:42 leisure 閱讀(459) | 評(píng)論 (0)編輯 收藏

          Javascript跨域請(qǐng)求的幾種解決方法

               摘要: 什么情況下才會(huì)出現(xiàn)跨域?
          假設(shè)域名是:http://www.example.com.cn/
          如果所請(qǐng)求的域名跟這個(gè)域名不致,這種情況就是跨域,由于跨域存在漏洞,所以一般來(lái)說(shuō)正常的跨域請(qǐng)求方式是請(qǐng)求不到的。
          解決方式:  閱讀全文

          posted @ 2011-09-29 22:57 leisure 閱讀(8046) | 評(píng)論 (1)編輯 收藏

          觸發(fā)onBeforeUnload事件

          1.點(diǎn)擊右上角關(guān)閉按鈕 
          2.點(diǎn)擊左上角IE圖標(biāo) 
          3.點(diǎn)擊右上角的IE圖標(biāo) 
          4.在地址欄輸入新地址 
          5.點(diǎn)擊后退按鈕 
          6.點(diǎn)擊刷新按鈕 
          7.點(diǎn)擊頁(yè)面上的鏈接(無(wú)論href里面是為空還是javascript,但是如果是#號(hào),則不會(huì)觸發(fā))。

          posted @ 2011-09-25 21:18 leisure 閱讀(292) | 評(píng)論 (0)編輯 收藏

          using dom4j to handle xml 使用dom4j操作xml

               摘要: dom4j是一個(gè)非常簡(jiǎn)單的開(kāi)源項(xiàng)目。該類(lèi)庫(kù)底層主要借助了Java集合框架,完美地支持對(duì)XML,XPath和XSLT的操作!
          以一個(gè)xml為例,分別展示出dom4j操作xml的常用操作(讀取,查找節(jié)點(diǎn),移除,輸出... ...  閱讀全文

          posted @ 2011-09-20 00:16 leisure 閱讀(493) | 評(píng)論 (0)編輯 收藏

          java自動(dòng)獲取安裝在線數(shù)字證書(shū)

               摘要: 主要原理是:使用socket嘗試對(duì)目標(biāo)服務(wù)器進(jìn)行通信,如果通信失敗,證明沒(méi)有證書(shū),不過(guò)此時(shí)的證書(shū)已悄悄發(fā)送到客戶(hù)端了。

          以前寫(xiě)過(guò)這個(gè)工具類(lèi)了:http://leisuredev.iteye.com/admin/blogs/714742
          今天稍微注釋并整理了一個(gè)版本:  閱讀全文

          posted @ 2011-09-18 23:36 leisure 閱讀(2280) | 評(píng)論 (0)編輯 收藏

          Java安裝本地證書(shū)

               摘要: 一:生成keystore文件
          keytool是Java的數(shù)字證書(shū)管理工具,位于%JAVA_HOME%\bin目錄下,keytool可以將密鑰(key)和證書(shū)(certificates)存在一個(gè)稱(chēng)為keystore的文件中。

          D:\>keytool -import -file d:\google.cer -keystore d:\google.keystore
          輸入keystore密碼:
          再次輸入新密碼:
          所有者:CN=www.google.com, O=Google Inc, L=Mountain View, ST=California, C=US
          簽發(fā)人:CN=Thawte SGC CA, O=Thawte Consulting (Pty) Ltd., C=ZA  閱讀全文

          posted @ 2011-09-17 21:13 leisure 閱讀(2374) | 評(píng)論 (1)編輯 收藏

          主站蜘蛛池模板: 东乌| 简阳市| 三河市| 淮阳县| 常熟市| 天全县| 中西区| 治县。| 綦江县| 西昌市| 常宁市| 闵行区| 孝义市| 乌兰察布市| 淮南市| 柳林县| 崇仁县| 布尔津县| 云安县| 龙游县| 庆阳市| 保靖县| 河东区| 孟州市| 海淀区| 营口市| 榆树市| 会昌县| 陕西省| 启东市| 新干县| 县级市| 滦平县| 扬中市| 洮南市| 阿图什市| 海晏县| 马龙县| 长宁县| 万源市| 松江区|