您的位置:首页 > 其它

经验分享之tips(3)

2017-04-27 15:16 134 查看
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;

 }

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: