經驗分享之tips(3)


1、讀取文件夾下的文件的個數

@Test
public void ddfd(){
    File file = new File("E:\\PDF\\picture\\1acb15772e57497399dcbccf0de946dd\\pic"); //文件夾路徑
    File files[];
    files = file.listFiles();
    int num = files.length;
    System.out.println("該文件夾下的文件個數爲:"+num);
     
    for(int i=0;i<files.length;i++)
    {
      System.out.println(files[i]);
      
    } 
  }



2、JS 打開新窗口

a.超鏈接<a href="http://blog.csdn.net/helijie92902" title="我的博客">Welcome</a>
等效於js代碼
window.location.href="http://blog.csdn.net/helijie92902"; //在同當前窗口中打開窗口
 
b.超鏈接<a href="http://blog.csdn.net/helijie92902" title="我的博客" target="_blank">Welcome</a>
等效於js代碼
window.open("http://blog.csdn.net/helijie92902"); //在另外新建窗口中打開窗口



3、判空

工具類:

   /**
   * 判斷字符串是否爲空
   * @param str 目標字符串
   * @return
   */

   public static boolean isEmpty(String str){
     return str == null || str.isEmpty() || str.trim().length() == 0;

   }


使用工具類:

   //數據回顯,根據傳入的id是否爲空來判斷
    if(!StringUtils.isEmpty(classifyPic.getId())){
      classifyPic=classifyPicService.get(classifyPic.getId());
    }
    classifyPic.setParent(classifyPicService.get(classifyPic.getParent().getId()));



4、判斷文件上傳的類型是否時png和jpg

if(suffix.toLowerCase().equals("png")||suffix.toLowerCase().equals("jpg")){

   System.out.println("文件格式正確,準備上傳!");

}



5、獲取url中"?"符後的字串

 function GetRequest() {

     var url = location.search; 

     var theRequest = new Object();
     if (url.indexOf("?") != -1) {
 var str = url.substr(1);
 strs = str.split("&");
 for(var i = 0; i < strs.length; i ++) {
       theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
 }
      return theRequest;

 }




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章