这需要导入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) 阅读(1426) | 评论 (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) 阅读(7137) | 评论 (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) 阅读(2386) | 评论 (0)编辑 收藏
 
     摘要: Hibernate的透明持久化用起来非常舒服,有时甚至忘记了数据库的存在。我身边的朋友经常会分不清save、saveOrUpdate、update的区别,lock、merge、replicate、refresh、evict甚至不知道是干什么用的。而且关于实体对象的生命周期也有很多概念不清,分不清transient、persistent、detached的区别,只是知道PO、VO这样的通俗叫法。其实...  阅读全文
posted @ 2007-07-13 13:02 重归本垒(Bing) 阅读(349) | 评论 (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) 阅读(718) | 评论 (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) 阅读(2777) | 评论 (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) 阅读(297) | 评论 (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) 阅读(1341) | 评论 (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.blogjava.net/bnlovebn/archive/2007/07/04/128006.html


posted @ 2007-07-04 08:59 重归本垒(Bing) 阅读(1858) | 评论 (1)编辑 收藏
 
最近好久没有看书了,是不是又要开始堕落了,上学时是三点一线,现在上班了,就是两点一线,更没劲。有时候真的不知道人活着是为了什么,挣钱吗?挣钱又是为了什么,为是家庭?为了房子?为了生活……
毕业了,家里人就整天嚷嚷——结婚,等结婚后又嚷嚷着——生孩子吧,生孩子了,又要抚养他,上学,长大,成年了,如果他还是不能自立,他又只能是吃你的,这时,他又找个女的一起吃你的,如果是生的是个女孩,那么她找个男的一起吃你的,还要给他们带孩子,等他们自立了,可能你也就安度晚年了,这时候,就是玩也玩不动,吃也吃不了了。
小时候,盼长大,读书时,盼毕业,以为毕业了就可以自己挣钱了,可以想怎么花就怎么花,可真上班了,又由不得你,可能你谈恋爱了,想买房了,想买车了。累一辈子,等什么都有的时候,老了。走不动了……
你上班,挣钱了,又用来消费了,最终这钱到哪去了,经济发达了,可生活好不上去,这是为什么,可能,不管你是老板还是工薪员工,不论你是在哪里上班,做什么职业,收入多少。最终的输家还是这些黎民百姓。赢的又会是谁呢……
不禁叹一声,唉…… 
posted @ 2007-07-02 08:39 重归本垒(Bing) 阅读(306) | 评论 (0)编辑 收藏
仅列出标题
共12页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last 
 
Web Page Rank Icon