开发中常用

来源:互联网 发布:海淘网站哪个好 知乎 编辑:程序博客网 时间:2024/05/16 07:56

1.  生成文件上传的二级目录:  获得指定字符串的hashcode,生成二级目录

// 获得hashcode生成二级目录public static String generateRandomDir(String uuidFileName) {int hashCode = uuidFileName.hashCode();// 一级目录int d1 = hashCode & 0xf;// 二级目录int d2 = (hashCode >> 4) & 0xf;return "/" + d1 + "/" + d2;}

2. 使用MD5的算法进行加密

/** * 使用md5的算法进行加密 * @param plainText 加密原文 * @return 加密密文 */public static String md5(String plainText) {byte[] secretBytes = null;try {secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());} catch (NoSuchAlgorithmException e) {throw new RuntimeException("没有md5这个算法!");}return new BigInteger(1, secretBytes).toString(16);}
3. 处理文件下载,不同浏览器的乱码问题

      /**       *  IE和Chrome的解决方案       */       URLEncoder.encode(string, enco);      /**       *  FireFox的解决方案       */       new String(string.getByte("utf-8"), "iso-8859-1");
4. 日期时间显示js  (资源下载地址(分页/datatime):  http://pan.baidu.com/share/link?shareid=1273127762&uk=3659181825 )

//在datetimepicker_css.js中65行修改图片路径,是增加减少图片能够正常显示document.getElementById("mytime").onclick = function(){NewCssCal('mytime','yyyyMMdd','dropdown',true,'24','')};












原创粉丝点击