Chinaunix首页 | 论坛 | 博客
  • 博客访问: 475363
  • 博文数量: 111
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 939
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 11:23
个人简介

Nathing

文章分类

全部博文(111)

文章存档

2016年(2)

2015年(1)

2014年(31)

2012年(2)

2011年(9)

2010年(36)

2009年(30)

我的朋友

分类: Java

2010-05-27 22:48:54

package com.my.stock.comm;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.my.stock.dao.CommonDao;
public class BaseService
{
 /**
  * 判断是否为null或""
  *
  * @param s
  * @return
  */
 public static boolean isNotNullOrEmpty(String s)
 {
  if (null == s)
  {
   return false;
  }
  if (s.trim().equals(""))
  {
   return false;
  }
  return true;
 }
 /**
  * 判断是否为null或0
  *
  * @param i
  * @return
  */
 public static boolean isNotNullOrZeroInteger(Integer i)
 {
  if (null == i)
  {
   return false;
  }
  if (i == 0)
  {
   return false;
  }
  return true;
 }
 /**
  * 批处理时,根据批处理数量,确定?占位符
  *
  * @param ids
  * @return
  */
 public static String getPoint(Object[] ids)
 {
  String str = "";
  for (int i = 0; i < ids.length; i++)
  {
   if (i == 0)
   {
    str = "?";
   }
   else
   {
    str += ",?";
   }
  }
  return str;
 }
 /** ****************************************************************************** */
 /**
  * 非对称MD5加密方法
  *
  * @param data
  *            需要加密的数据
  * @return 加密后的数据
  */
 public static String doMD5(String s)
 {
  String str2 = "";
  try
  {
   MessageDigest m = MessageDigest.getInstance("MD5");
   m.update(s.getBytes("UTF8"));
   str2 = encodeHex(m.digest());
  }
  catch (NoSuchAlgorithmException e)
  {
   e.printStackTrace();
  }
  catch (UnsupportedEncodingException e)
  {
   e.printStackTrace();
  }
  return str2;
 }
 private static final String encodeHex(byte[] bytes)
 {
  StringBuffer buf = new StringBuffer(bytes.length * 2);
  for (int i = 0; i < bytes.length; i++)
  {
   if (((int) bytes[i] & 0xff) < 0x10)
   {
    buf.append("0");
   }
   buf.append(Long.toString((int) bytes[i] & 0xff, 16));
  }
  return buf.toString();
 }
 /** ******************************************************************** */
}
阅读(593) | 评论(0) | 转发(0) |
0

上一篇:struts+jpa+spring通用DAO_3

下一篇:FreeTDS

给主人留下些什么吧!~~