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

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

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

      這需要導入java.io類
    import java.io.*;

    public class FileOperate {
      public FileOperate() {
      }

      /**
       * 新建目錄
       * @param folderPath String 如 c:/fqf
       * @return boolean
       */
      public void newFolder(String folderPath) {
        try {
          String filePath = folderPath;
          filePath = filePath.toString();
          java.io.File myFilePath = new java.io.File(filePath);
          if (!myFilePath.exists()) {
            myFilePath.mkdir();
          }
        }
        catch (Exception e) {
          System.out.println("新建目錄操作出錯");
          e.printStackTrace();
        }
      }

      /**
       * 新建文件
       * @param filePathAndName String 文件路徑及名稱 如c:/fqf.txt
       * @param fileContent String 文件內容
       * @return boolean
       */
      public void newFile(String filePathAndName, String fileContent) {

        try {
          String filePath = filePathAndName;
          filePath = filePath.toString();
          File myFilePath = new File(filePath);
          if (!myFilePath.exists()) {
            myFilePath.createNewFile();
          }
          FileWriter resultFile = new FileWriter(myFilePath);
          PrintWriter myFile = new PrintWriter(resultFile);
          String strContent = fileContent;
          myFile.println(strContent);
          resultFile.close();

        }
        catch (Exception e) {
          System.out.println("新建目錄操作出錯");
          e.printStackTrace();

        }

      }

      /**
       * 刪除文件
       * @param filePathAndName String 文件路徑及名稱 如c:/fqf.txt
       * @param fileContent String
       * @return boolean
       */
      public void delFile(String filePathAndName) {
        try {
          String filePath = filePathAndName;
          filePath = filePath.toString();
          java.io.File myDelFile = new java.io.File(filePath);
          myDelFile.delete();

        }
        catch (Exception e) {
          System.out.println("刪除文件操作出錯");
          e.printStackTrace();

        }

      }

      /**
       * 刪除文件夾
       * @param filePathAndName String 文件夾路徑及名稱 如c:/fqf
       * @param fileContent String
       * @return boolean
       */
      public void delFolder(String folderPath) {
        try {
          delAllFile(folderPath); //刪除完里面所有內容
          String filePath = folderPath;
          filePath = filePath.toString();
          java.io.File myFilePath = new java.io.File(filePath);
          myFilePath.delete(); //刪除空文件夾

        }
        catch (Exception e) {
          System.out.println("刪除文件夾操作出錯");
          e.printStackTrace();

        }

      }

      /**
       * 刪除文件夾里面的所有文件
       * @param path String 文件夾路徑 如 c:/fqf
       */
      public void delAllFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
          return;
        }
        if (!file.isDirectory()) {
          return;
        }
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
          if (path.endsWith(File.separator)) {
            temp = new File(path + tempList[i]);
          }
          else {
            temp = new File(path + File.separator + tempList[i]);
          }
          if (temp.isFile()) {
            temp.delete();
          }
          if (temp.isDirectory()) {
            delAllFile(path+"/"+ tempList[i]);//先刪除文件夾里面的文件
            delFolder(path+"/"+ tempList[i]);//再刪除空文件夾
          }
        }
      }

      /**
       * 復制單個文件
       * @param oldPath String 原文件路徑 如:c:/fqf.txt
       * @param newPath String 復制后路徑 如:f:/fqf.txt
       * @return boolean
       */
      public void copyFile(String oldPath, String newPath) {
        try {
          int bytesum = 0;
          int byteread = 0;
          File oldfile = new File(oldPath);
          if (oldfile.exists()) { //文件存在時
            InputStream inStream = new FileInputStream(oldPath); //讀入原文件
            FileOutputStream fs = new FileOutputStream(newPath);
            byte[] buffer = new byte[1444];
            int length;
            while ( (byteread = inStream.read(buffer)) != -1) {
              bytesum += byteread; //字節數 文件大小
              System.out.println(bytesum);
              fs.write(buffer, 0, byteread);
            }
            inStream.close();
          }
        }
        catch (Exception e) {
          System.out.println("復制單個文件操作出錯");
          e.printStackTrace();

        }

      }

      /**
       * 復制整個文件夾內容
       * @param oldPath String 原文件路徑 如:c:/fqf
       * @param newPath String 復制后路徑 如:f:/fqf/ff
       * @return boolean
       */
      public void copyFolder(String oldPath, String newPath) {

        try {
          (new File(newPath)).mkdirs(); //如果文件夾不存在 則建立新文件夾
          File a=new File(oldPath);
          String[] file=a.list();
          File temp=null;
          for (int i = 0; i < file.length; i++) {
            if(oldPath.endsWith(File.separator)){
              temp=new File(oldPath+file[i]);
            }
            else{
              temp=new File(oldPath+File.separator+file[i]);
            }

            if(temp.isFile()){
              FileInputStream input = new FileInputStream(temp);
              FileOutputStream output = new FileOutputStream(newPath + "/" +
                  (temp.getName()).toString());
              byte[] b = new byte[1024 * 5];
              int len;
              while ( (len = input.read(b)) != -1) {
                output.write(b, 0, len);
              }
              output.flush();
              output.close();
              input.close();
            }
            if(temp.isDirectory()){//如果是子文件夾
              copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]);
            }
          }
        }
        catch (Exception e) {
          System.out.println("復制整個文件夾內容操作出錯");
          e.printStackTrace();

        }

      }

      /**
       * 移動文件到指定目錄
       * @param oldPath String 如:c:/fqf.txt
       * @param newPath String 如:d:/fqf.txt
       */
      public void moveFile(String oldPath, String newPath) {
        copyFile(oldPath, newPath);
        delFile(oldPath);

      }

      /**
       * 移動文件到指定目錄
       * @param oldPath String 如:c:/fqf.txt
       * @param newPath String 如:d:/fqf.txt
       */
      public void moveFolder(String oldPath, String newPath) {
        copyFolder(oldPath, newPath);
        delFolder(oldPath);

      }
    }



    java中刪除目錄事先要刪除目錄下的文件或子目錄。用遞歸就可以實現。這是我第一個用到算法作的程序,哎看來沒白學。
    public void del(String filepath) throws IOException{
    File f = new File(filepath);//定義文件路徑       
    if(f.exists() && f.isDirectory()){//判斷是文件還是目錄
        if(f.listFiles().length==0){//若目錄下沒有文件則直接刪除
            f.delete();
        }else{//若有則把文件放進數組,并判斷是否有下級目錄
            File delFile[]=f.listFiles();
            int i =f.listFiles().length;
            for(int j=0;j<i;j++){
                if (delFile[j].isDirectory()){                                                del (delFile[j].getAbsolutePath());//遞歸調用del方法并取得子目錄路徑
                }
                delFile[j].delete();//刪除文件
            }
        }
        del(filepath);//遞歸調用
    }

    }    


    刪除一個非空目錄并不是簡單地創建一個文件對象,然后再調用delete()就可以完成的。要在平臺無關的方式下安全地刪除一個非空目錄,你還需要一個算法。該算法首先刪除文件,然后再從目錄樹的底部由下至上地刪除其中所有的目錄。

    只要簡單地在目錄中循環查找文件,再調用delete就可以清除目錄中的所有文件:

    static public void emptyDirectory(File directory) {
       File[ ] entries = directory.listFiles( );
       for(int i=0; i<entries.length; i++) {
           entries[i].delete( );
       }
    }
    這個簡單的方法也可以用來刪除整個目錄結構。當在循環中遇到一個目錄時它就遞歸調用deleteDirectory,而且它也會檢查傳入的參數是否是一個真正的目錄。最后,它將刪除作為參數傳入的整個目錄。
    static public void deleteDirectory(File dir) throws IOException {
       if( (dir == null) || !dir.isDirectory) {
           throw new IllegalArgumentException(

                     "Argument "+dir+" is not a directory. "
                 );
       }

       File[ ] entries = dir.listFiles( );
       int sz = entries.length;

       for(int i=0; i<sz; i++) {
           if(entries[i].isDirectory( )) {
               deleteDirectory(entries[i]);
           } else {
               entries[i].delete( );
           }
       }

      dir.delete();
    }
    在Java 1.1以及一些J2ME/PersonalJava的變種中沒有File.listFiles方法。所以只能用File.list,它的返回值一個字符串數組,你要為每個字符串構造一個新的文件對象。
    posted @ 2007-07-24 13:25 重歸本壘(Bing) 閱讀(1440) | 評論 (0)編輯 收藏
     
    1。試圖在Struts的form標記外使用form的子元素。在后面使用Struts的html標記等

    2。不經意使用的無主體的標記,如web 服務器解析時當作一個無主體的標記,隨后使用的標記都被認為是在這個標記之外的
    3。還有就是在使用taglib引入HTML標記庫時,你使用的prefix的值不是html

    4。property必須和所要提交的action對應的formbean中的某個屬性相匹配(必須有一個formbean)
    5。要使用標簽,外層必須使用標簽,不能使用html的

    posted @ 2007-07-19 17:22 重歸本壘(Bing) 閱讀(7191) | 評論 (7)編輯 收藏
     
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryId' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Cannot configure CacheManager: 文件過早結束。

    昨天rebase后出現了這個問題,費了我一個下午的時間,多方查找資料都沒有辦法,到今天早上后看到
    http://forum.springframework.org/showthread.php?t=25528上說的。才知道大概是ehcache配制不當造成的,于是從同事那里拷貝ehcache.xml過來,解決了!血的教訓!

    ehcache是一個很不錯的輕量級緩存實現,速度快,功能全面(一般的應用完全足夠了),從1.2版后可以支持分布式緩存,可以用在集群環境中。除了可以緩存普通的對象,還可以用來作為Web頁面的緩存。緩存靜態HTML、JSP、Velocity、FreeMarker等等的頁面。Hibernate選擇ehcache作為默認的緩存實現的。






    posted @ 2007-07-19 09:45 重歸本壘(Bing) 閱讀(2403) | 評論 (0)編輯 收藏
     
         摘要: Hibernate的透明持久化用起來非常舒服,有時甚至忘記了數據庫的存在。我身邊的朋友經常會分不清save、saveOrUpdate、update的區別,lock、merge、replicate、refresh、evict甚至不知道是干什么用的。而且關于實體對象的生命周期也有很多概念不清,分不清transient、persistent、detached的區別,只是知道PO、VO這樣的通俗叫法。其實...  閱讀全文
    posted @ 2007-07-13 13:02 重歸本壘(Bing) 閱讀(366) | 評論 (0)編輯 收藏
     
    一、數組轉成字符串:
    1、 將數組中的字符轉換為一個字符串
    將數組中的字符轉換為一個字符串

    @param strToConv 要轉換的字符串 ,默認以逗號分隔
    @return 返回一個字符串
    String[3] s={"a","b","c"}
    StringUtil.convString(s)="a,b,c"
    2、 static public String converString(String strToConv)
    @param strToConv 要轉換的字符串 ,
    @param conv 分隔符,默認以逗號分隔
    @return 同樣返回一個字符串

    String[3] s={"a","b","c"}
    StringUtil.convString(s,"@")="a@b@c"
    static public String converString(String strToConv, String conv)


    二、空值檢測:
    3、

    Checks if a String is empty ("") or null.


    判斷一個字符串是否為空,空格作非空處理。 StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false

    NOTE: This method changed in Lang version 2.0.

    It no longer trims the String.
    That functionality is available in isBlank().


    @param str the String to check, may be null
    @return true if the String is empty or null
    public static boolean isEmpty(String str)


    三、非空處理:
    4、
    Checks if a String is not empty ("") and not null.


    判斷一個字符串是否非空,空格作非空處理. StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true

    @param str the String to check, may be null
    @return true if the String is not empty and not null
    public static boolean isNotEmpty(String str)

    5、

    Checks if a String is not empty (""), not null and not whitespace only.


    判斷一個字符串是否非空,空格作空處理. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true

    @param str the String to check, may be null
    @return true if the String is
    not empty and not null and not whitespace
    @since 2.0
    public static boolean isNotBlank(String str)


    四、 空格處理
    6、
    Removes control characters (char <= 32) from both

    ends of this String, handling null by returning
    null.


    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link //strip(String)}.


    To trim your choice of characters, use the

    {@link //strip(String, String)} methods.


    格式化一個字符串中的空格,有非空判斷處理; StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed string, null if null String input
    public static String trim(String str)

    7、


    Removes control characters (char <= 32) from both

    ends of this String returning null if the String is
    empty ("") after the trim or if it is null.

    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link /stripToNull(String)}.


    格式化一個字符串中的空格,有非空判斷處理,如果為空返回null; StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed String,
    null if only chars <= 32, empty or null String input
    @since 2.0
    public static String trimToNull(String str)

    8、


    Removes control characters (char <= 32) from both

    ends of this String returning an empty String ("") if the String
    is empty ("") after the trim or if it is null.

    The String is trimmed using {@link String#trim()}.

    Trim removes start and end characters <= 32.
    To strip whitespace use {@link /stripToEmpty(String)}.


    格式化一個字符串中的空格,有非空判斷處理,如果為空返回""; StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"

    @param str the String to be trimmed, may be null
    @return the trimmed String, or an empty String if null input
    @since 2.0
    public static String trimToEmpty(String str)


    五、 字符串比較:
    9、
    Compares two Strings, returning true if they are equal.


    nulls are handled without exceptions. Two null

    references are considered to be equal. The comparison is case sensitive.


    判斷兩個字符串是否相等,有非空處理。 StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false

    @param str1 the first String, may be null
    @param str2 the second String, may be null
    @return true if the Strings are equal, case sensitive, or
    both null
    @see java.lang.String#equals(Object)
    public static boolean equals(String str1, String str2)


    10、

    Compares two Strings, returning true if they are equal ignoring

    the case.


    nulls are handled without exceptions. Two null

    references are considered equal. Comparison is case insensitive.


    判斷兩個字符串是否相等,有非空處理。忽略大小寫 StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, "abc") = false StringUtils.equalsIgnoreCase("abc", null) = false StringUtils.equalsIgnoreCase("abc", "abc") = true StringUtils.equalsIgnoreCase("abc", "ABC") = true

    @param str1 the first String, may be null
    @param str2 the second String, may be null
    @return true if the Strings are equal, case insensitive, or
    both null
    @see java.lang.String#equalsIgnoreCase(String)
    public static boolean equalsIgnoreCase(String str1, String str2)


    六、 IndexOf 處理
    11、


    Finds the first index within a String, handling null.

    This method uses {@link String#indexOf(String)}.


    A null String will return -1.


    返回要查找的字符串所在位置,有非空處理 StringUtils.indexOf(null, *) = -1 StringUtils.indexOf(*, null) = -1 StringUtils.indexOf("", "") = 0 StringUtils.indexOf("aabaabaa", "a") = 0 StringUtils.indexOf("aabaabaa", "b") = 2 StringUtils.indexOf("aabaabaa", "ab") = 1 StringUtils.indexOf("aabaabaa", "") = 0

    @param str the String to check, may be null
    @param searchStr the String to find, may be null
    @return the first index of the search String,
    -1 if no match or null string input
    @since 2.0
    public static int indexOf(String str, String searchStr)

    12、

    Finds the first index within a String, handling null.

    This method uses {@link String#indexOf(String, int)}.


    A null String will return -1.

    A negative start position is treated as zero.
    An empty ("") search String always matches.
    A start position greater than the string length only matches
    an empty search String.


    返回要由指定位置開始查找的字符串所在位置,有非空處理 StringUtils.indexOf(null, *, *) = -1 StringUtils.indexOf(*, null, *) = -1 StringUtils.indexOf("", "", 0) = 0 StringUtils.indexOf("aabaabaa", "a", 0) = 0 StringUtils.indexOf("aabaabaa", "b", 0) = 2 StringUtils.indexOf("aabaabaa", "ab", 0) = 1 StringUtils.indexOf("aabaabaa", "b", 3) = 5 StringUtils.indexOf("aabaabaa", "b", 9) = -1 StringUtils.indexOf("aabaabaa", "b", -1) = 2 StringUtils.indexOf("aabaabaa", "", 2) = 2 StringUtils.indexOf("abc", "", 9) = 3

    @param str the String to check, may be null
    @param searchStr the String to find, may be null
    @param startPos the start position, negative treated as zero
    @return the first index of the search String,
    -1 if no match or null string input
    @since 2.0
    public static int indexOf(String str, String searchStr, int startPos)


    七、 子字符串處理:
    13、
    Gets a substring from the specified String avoiding exceptions.


    A negative start position can be used to start n

    characters from the end of the String.


    A null String will return null.

    An empty ("") String will return "".


    返回指定位置開始的字符串中的所有字符 StringUtils.substring(null, *) = null StringUtils.substring("", *) = "" StringUtils.substring("abc", 0) = "abc" StringUtils.substring("abc", 2) = "c" StringUtils.substring("abc", 4) = "" StringUtils.substring("abc", -2) = "bc" StringUtils.substring("abc", -4) = "abc"

    @param str the String to get the substring from, may be null
    @param start the position to start from, negative means
    count back from the end of the String by this many characters
    @return substring from start position, null if null String input
    public static String substring(String str, int start)

    14、

    Gets a substring from the specified String avoiding exceptions.


    A negative start position can be used to start/end n

    characters from the end of the String.


    The returned substring starts with the character in the start

    position and ends before the end position. All postion counting is
    zero-based -- i.e., to start at the beginning of the string use
    start = 0. Negative start and end positions can be used to
    specify offsets relative to the end of the String.


    If start is not strictly to the left of end, ""

    is returned.


    返回由開始位置到結束位置之間的子字符串 StringUtils.substring(null, *, *) = null StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" StringUtils.substring("abc", 2, 0) = "" StringUtils.substring("abc", 2, 4) = "c" StringUtils.substring("abc", 4, 6) = "" StringUtils.substring("abc", 2, 2) = "" StringUtils.substring("abc", -2, -1) = "b" StringUtils.substring("abc", -4, 2) = "ab"

    @param str the String to get the substring from, may be null
    @param start the position to start from, negative means
    count back from the end of the String by this many characters
    @param end the position to end at (exclusive), negative means
    count back from the end of the String by this many characters
    @return substring from start position to end positon,
    null if null String input
    public static String substring(String str, int start, int end)


    15、 SubStringAfter/SubStringBefore(前后子字符串處理:


    Gets the substring before the first occurance of a separator.

    The separator is not returned.


    A null string input will return null.

    An empty ("") string input will return the empty string.
    A null separator will return the input string.


    返回指定字符串之前的所有字符 StringUtils.substringBefore(null, *) = null StringUtils.substringBefore("", *) = "" StringUtils.substringBefore("abc", "a") = "" StringUtils.substringBefore("abcba", "b") = "a" StringUtils.substringBefore("abc", "c") = "ab" StringUtils.substringBefore("abc", "d") = "abc" StringUtils.substringBefore("abc", "") = "" StringUtils.substringBefore("abc", null) = "abc"

    @param str the String to get a substring from, may be null
    @param separator the String to search for, may be null
    @return the substring before the first occurance of the separator,
    null if null String input
    @since 2.0
    public static String substringBefore(String str, String separator)

    16、

    Gets the substring after the first occurance of a separator.

    The separator is not returned.


    A null string input will return null.

    An empty ("") string input will return the empty string.
    A null separator will return the empty string if the
    input string is not null.


    返回指定字符串之后的所有字符 StringUtils.substringAfter(null, *) = null StringUtils.substringAfter("", *) = "" StringUtils.substringAfter(*, null) = "" StringUtils.substringAfter("abc", "a") = "bc" StringUtils.substringAfter("abcba", "b") = "cba" StringUtils.substringAfter("abc", "c") = "" StringUtils.substringAfter("abc", "d") = "" StringUtils.substringAfter("abc", "") = "abc"

    @param str the String to get a substring from, may be null
    @param separator the String to search for, may be null
    @return the substring after the first occurance of the separator,
    null if null String input
    @since 2.0
    public static String substringAfter(String str, String separator)

    17、

    Gets the substring before the last occurance of a separator.

    The separator is not returned.


    A null string input will return null.

    An empty ("") string input will return the empty string.
    An empty or null separator will return the input string.


    返回最后一個指定字符串之前的所有字符 StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast("", *) = "" StringUtils.substringBeforeLast("abcba", "b") = "abc" StringUtils.substringBeforeLast("abc", "c") = "ab" StringUtils.substringBeforeLast("a", "a") = "" StringUtils.substringBeforeLast("a", "z") = "a" StringUtils.substringBeforeLast("a", null) = "a" StringUtils.substringBeforeLast("a", "") = "a"

    @param str the String to get a substring from, may be null
    @param separator the String to search for, may be null
    @return the substring before the last occurance of the separator,
    null if null String input
    @since 2.0
    public static String substringBeforeLast(String str, String separator)

    18、

    Gets the substring after the last occurance of a separator.

    The separator is not returned.


    A null string input will return null.

    An empty ("") string input will return the empty string.
    An empty or null separator will return the empty string if
    the input string is not null.


    返回最后一個指定字符串之后的所有字符 StringUtils.substringAfterLast(null, *) = null StringUtils.substringAfterLast("", *) = "" StringUtils.substringAfterLast(*, "") = "" StringUtils.substringAfterLast(*, null) = "" StringUtils.substringAfterLast("abc", "a") = "bc" StringUtils.substringAfterLast("abcba", "b") = "a" StringUtils.substringAfterLast("abc", "c") = "" StringUtils.substringAfterLast("a", "a") = "" StringUtils.substringAfterLast("a", "z") = ""

    @param str the String to get a substring from, may be null
    @param separator the String to search for, may be null
    @return the substring after the last occurance of the separator,
    null if null String input
    @since 2.0
    public static String substringAfterLast(String str, String separator)


    八、 Replacing(字符串替換)
    19、
    Replaces all occurances of a String within another String.


    A null reference passed to this method is a no-op.


    以指定字符串替換原來字符串的的指定字符串 StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", null, null) = "aba" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "aba" StringUtils.replace("aba", "a", "z") = "zbz"

    @param text text to search and replace in, may be null
    @param repl the String to search for, may be null
    @param with the String to replace with, may be null
    @return the text with any replacements processed,
    null if null String input
    @see #replace(String text, String repl, String with, int max)
    public static String replace(String text, String repl, String with)

    20、

    Replaces a String with another String inside a larger String,

    for the first max values of the search String.


    A null reference passed to this method is a no-op.


    以指定字符串最大替換原來字符串的的指定字符串 StringUtils.replace(null, *, *, *) = null StringUtils.replace("", *, *, *) = "" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", null, null, 1) = "abaa" StringUtils.replace("abaa", "a", null, 1) = "abaa" StringUtils.replace("abaa", "a", "", 1) = "abaa" StringUtils.replace("abaa", "a", "z", 0) = "abaa" StringUtils.replace("abaa", "a", "z", 1) = "zbaa" StringUtils.replace("abaa", "a", "z", 2) = "zbza" StringUtils.replace("abaa", "a", "z", -1) = "zbzz"

    @param text text to search and replace in, may be null
    @param repl the String to search for, may be null
    @param with the String to replace with, may be null
    @param max maximum number of values to replace, or -1 if no maximum
    @return the text with any replacements processed,
    null if null String input
    public static String replace(String text, String repl, String with, int max)


    九、 Case conversion(大小寫轉換)
    21、

    Converts a String to upper case as per {@link String#toUpperCase()}.


    A null input String returns null.


    將一個字符串變為大寫 StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC"

    @param str the String to upper case, may be null
    @return the upper cased String, null if null String input
    public static String upperCase(String str) 22、

    Converts a String to lower case as per {@link String#toLowerCase()}.


    A null input String returns null.


    將一個字符串轉換為小寫 StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"

    @param str the String to lower case, may be null
    @return the lower cased String, null if null String input
    public static String lowerCase(String str) 23、

    Capitalizes a String changing the first letter to title case as

    per {@link Character#toTitleCase(char)}. No other letters are changed.


    For a word based alorithm, see {@link /WordUtils#capitalize(String)}.

    A null input String returns null.


    StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt"

    @param str the String to capitalize, may be null
    @return the capitalized String, null if null String input
    @see /WordUtils#capitalize(String)
    @see /uncapitalize(String)
    @since 2.0
    將字符串中的首字母大寫
    public static String capitalize(String str)
    posted @ 2007-07-13 12:57 重歸本壘(Bing) 閱讀(739) | 評論 (0)編輯 收藏
     

    一、load,get
    (1)當記錄不存在時候,get方法返回null,load方法產生異常

    (2)load方法可以返回實體的代理類,get方法則返回真是的實體類

    (3)load方法可以充分利用hibernate的內部緩存和二級緩存中的現有數據,而get方法僅僅在內部緩存中進行數據查找,如果沒有發現數據則將越過二級緩存,直接調用SQL查詢數據庫。
       (4) 也許別人把數據庫中的數據修改了,load如何在緩存中找到了數據,則不會再訪問數據庫,而get則會返回最新數據。
     
    二、find,iterator
         (1) iterator首先會獲取符合條件的記錄的id,再跟據id在本地緩存中查找數據,查找不到的再在數據庫中查找,結果再存在緩存中。N+1條SQL。
     (2)find跟據生成的sql語句,直接訪問數據庫,查到的數據存在緩存中,一條sql。

    三、Hibernate生成的DAO類中函數功能說明(merge,saveOrUpdate,lock)

    /**
          * 將傳入的detached狀態的對象的屬性復制到持久化對象中,并返回該持久化對象。
          * 如果該session中沒有關聯的持久化對象,加載一個。
          * 如果傳入對象未保存,保存一個副本并作為持久對象返回,傳入對象依然保持detached狀態。
          */

    public Sysuser merge(Sysuser detachedInstance) {
          log.debug("merging Sysuser instance");
          try {
           Sysuser result = (Sysuser) getHibernateTemplate().merge(
             detachedInstance);
           log.debug("merge successful");
           return result;
          } catch (RuntimeException re) {
           log.error("merge failed", re);
           throw re;
          }
    }

    /**
          * 將傳入的對象持久化并保存。 如果對象未保存(Transient狀態),調用save方法保存。
          * 如果對象已保存(Detached狀態),調用update方法將對象與Session重新關聯。
          */
    public void attachDirty(Sysuser instance) {
          log.debug("attaching dirty Sysuser instance");
          try {
           getHibernateTemplate().saveOrUpdate(instance);
           log.debug("attach successful");
          } catch (RuntimeException re) {
           log.error("attach failed", re);
           throw re;
          }
    }

    /**
          * 將傳入的對象狀態設置為Transient狀態
          */

    public void attachClean(Sysuser instance) {
          log.debug("attaching clean Sysuser instance");
          try {
           getHibernateTemplate().lock(instance, LockMode.NONE);
           log.debug("attach successful");
          } catch (RuntimeException re) {
           log.error("attach failed", re);
           throw re;
          }
    }

    posted @ 2007-07-13 11:18 重歸本壘(Bing) 閱讀(2800) | 評論 (0)編輯 收藏
     

    錯誤 :javax.servlet.ServletException: DispatchMapping[/configaction] does not define a handler property

     原因: action參數配置不全
    解決方法:在 config文件中 添加 parameter="method"等

    錯誤: 表單數據驗證失敗時發生錯誤,“No input attribute for mapping path”


    原因:action中表單驗證 validate="true" ,如果validate()返回非空的ActionErrors,將會被轉到input屬性指定的URI,而action中未指定input時會報此錯
    解決方法:添加 input="url" 或者 validate="false"

    posted @ 2007-07-09 16:32 重歸本壘(Bing) 閱讀(311) | 評論 (0)編輯 收藏
     
         摘要: Filter有要實現的三方法:void init(FilterConfig config) throws ServletExceptionvoid doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletExceptionvoid destroy...  閱讀全文
    posted @ 2007-07-04 09:31 重歸本壘(Bing) 閱讀(1359) | 評論 (0)編輯 收藏
     

    要有這么一個監聽器,當加入session時就可以觸發一個加入session事件,在session過期時就可以觸發一個刪除事件,那么我們的把要處理的東西加入到這兩個事件中就可以做很多于SESSION相關連的事。如在線用戶的管理,單點登陸等等。
    在J2EE中可以實現HttpSessionBindingListener接口,此接口有兩要實現的方法。
     void valueBound(HttpSessionBindingEvent event) 當實現此接口的監聽類和session綁定時觸發此事件。
    void valueUnbound(HttpSessionBindingEvent event) 當session過期或實現此接口的監聽類卸裁時觸發此事件。

    下面是一個示例解決方案:可以把登陸用戶的信息記錄在緩沖池中,當SESSION過期時,用戶信息自動刪除。
    一個用戶信息接口。一個用戶緩沖池。一個HttpSessionBindingListener接口的監聽類。

    public interface LoginUserMessage {}

     

    public class LoginUserPool {
        
    private Map map = new HashMap();
        
    private static LoginUserPool loginUserPool = new LoginUserPool();
        
    private LoginUserPool(){}
        
    public static LoginUserPool getInstance() {
            
    return loginUserPool;
        }

        
    public void addLoginUserMessage(String sessionId,LoginUserMessage loginUserMessage){
           map.remove(sessionId);
           map.put(sessionId,loginUserMessage);
        }

        
    public LoginUserMessage removeLoginUserMessage(String sessionId){
            
    return  (LoginUserMessage) map.remove(sessionId);
        }

        
    public LoginUserMessage getLoginUserMessage(String sessionId){
            
    return (LoginUserMessage) map.get(sessionId);
        }

        
    public Map getLoginUserMessages(){
            
    return map;
        }

        
    public boolean isEmpty(){
            
    return  map.isEmpty();
        }

    }

     

    public class UserLoginListener implements HttpSessionBindingListener{
        
    private final Log logger = LogFactory.getLog(getClass());
        
    private String sessionId = null;
        
    private LoginUserMessage loginUserMessage = null;
        
    private LoginUserPool loginUserPool = LoginUserPool.getInstance();

        
    public LoginUserMessage getLoginUserMessage() {
            
    return loginUserMessage;
        }

        
    public void setLoginUserMessage(LoginUserMessage loginUserMessage) {
            
    this.loginUserMessage = loginUserMessage;
        }

        
    public String getSessionId() {
            
    return sessionId;
        }

        
    public void setSessionId(String sessionId) {
            
    this.sessionId = sessionId;
        }

        
    /* (non-Javadoc)
         * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
         
    */

        
    public void valueBound(HttpSessionBindingEvent event) {
            
    // TODO Auto-generated method stub
            if(this.getLoginUserMessage() != null){
                loginUserPool.addLoginUserMessage(
    this.getSessionId(),this.getLoginUserMessage());
                logger.info(
    "用戶信息加入緩存池成功");
            }

            
    this.setLoginUserMessage(null);
        }


        
    /* (non-Javadoc)
         * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
         
    */

        
    public void valueUnbound(HttpSessionBindingEvent event) {
            
    // TODO Auto-generated method stub
            if(!loginUserPool.isEmpty()){
                loginUserPool.removeLoginUserMessage(sessionId);
                logger.info(
    "用戶信息從緩存池中移除成功");
            }

        }


    }


    這樣子的話,當在應用中把userLoginListener加入到session中時,就會自動把用戶信息加入到緩沖池中了。
    如:
     session.setAttribute("userLoginListener",userLoginListener);



    (原創,轉載請保留文章出處http://www.tkk7.com/bnlovebn/archive/2007/07/04/128006.html


    posted @ 2007-07-04 08:59 重歸本壘(Bing) 閱讀(1876) | 評論 (1)編輯 收藏
     
    最近好久沒有看書了,是不是又要開始墮落了,上學時是三點一線,現在上班了,就是兩點一線,更沒勁。有時候真的不知道人活著是為了什么,掙錢嗎?掙錢又是為了什么,為是家庭?為了房子?為了生活……
    畢業了,家里人就整天嚷嚷——結婚,等結婚后又嚷嚷著——生孩子吧,生孩子了,又要撫養他,上學,長大,成年了,如果他還是不能自立,他又只能是吃你的,這時,他又找個女的一起吃你的,如果是生的是個女孩,那么她找個男的一起吃你的,還要給他們帶孩子,等他們自立了,可能你也就安度晚年了,這時候,就是玩也玩不動,吃也吃不了了。
    小時候,盼長大,讀書時,盼畢業,以為畢業了就可以自己掙錢了,可以想怎么花就怎么花,可真上班了,又由不得你,可能你談戀愛了,想買房了,想買車了。累一輩子,等什么都有的時候,老了。走不動了……
    你上班,掙錢了,又用來消費了,最終這錢到哪去了,經濟發達了,可生活好不上去,這是為什么,可能,不管你是老板還是工薪員工,不論你是在哪里上班,做什么職業,收入多少。最終的輸家還是這些黎民百姓。贏的又會是誰呢……
    不禁嘆一聲,唉…… 
    posted @ 2007-07-02 08:39 重歸本壘(Bing) 閱讀(320) | 評論 (0)編輯 收藏
    僅列出標題
    共12頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
     
    Web Page Rank Icon
    主站蜘蛛池模板: 伊人亚洲综合青草青草久热| 亚洲大尺码专区影院| 亚洲AV中文无码乱人伦| 日韩成人在线免费视频| 免费看大美女大黄大色| 女性无套免费网站在线看| 扒开双腿猛进入爽爽免费视频 | 中文字幕亚洲综合久久综合| 亚洲成aⅴ人在线观看| 亚洲一级毛片免费看| 国产色在线|亚洲| 亚洲人成电影网站免费| 亚洲精品av无码喷奶水糖心| 亚洲AV无码资源在线观看| 国产成人va亚洲电影| 成人在线免费视频| 老司机精品免费视频| 青青操免费在线观看| 日韩免费在线观看视频| 91大神免费观看| 动漫黄网站免费永久在线观看| 性生交片免费无码看人| 国产精品高清全国免费观看| 日韩亚洲国产综合久久久| 红杏亚洲影院一区二区三区| 情人伊人久久综合亚洲| 久久亚洲AV成人无码软件| 亚洲一区精彩视频| 在线亚洲精品视频| 中文字幕无码免费久久9一区9| 日韩视频免费在线观看| 免费中文熟妇在线影片| 国产又黄又爽又刺激的免费网址| 亚洲男人第一无码aⅴ网站| 亚洲av无码精品网站| 亚洲午夜国产精品无卡| 国产精品亚洲专区在线播放| 丁香花在线观看免费观看图片| 8x成人永久免费视频| 日韩免费观看一级毛片看看| 久久亚洲国产精品五月天婷|