做java web项目中常用的工具类中的方法
来源:互联网 发布:php交换两个变量的值 编辑:程序博客网 时间:2024/05/21 22:21
做java web项目中常用的工具类中的方法!之后会不断更新的!大家有什么好的共用方法也可送上,共同学习,学习!
一: 把时间Date类型转换成String类型
/** * 把Date类型转换成String类型 * @param date * @return */ public static String dateToString(Date date){ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(date); }
二:把String类型转换成Date类型
/** * 把String类型转换成Date类型 * @param date * @return */ public static Date stringToDate(String date){ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d = null; try { d = format.parse(date); } catch (java.text.ParseException e) { e.printStackTrace(); } return d; }
三:同时判断‘’‘’和null 两种情况
/** * 判断变量是否为空 * @param s * @return */ public static boolean isEmpty(String s){ if(null == s || "".equals(s) || "".equals(s.trim()) || "null".equalsIgnoreCase(s)){ return true; }else{ return false; } }
四:去除字符串前后的空格
/** * 去除字符串前后的空格 * @param s * @return */ public static String trim(String s){ if(null == s){ return ""; }else{ return s.trim(); } }
五:用来去掉List中空值和相同项的。
/** * 用来去掉List中空值和相同项的。 * @param list * @return */ public List<String> removeSameItem(List<String> list) { List<String> difList = new ArrayList<String>(); for (String t : list) { if (t != null && !difList.contains(t)) { difList.add(t); } } return difList; }
六:当前天数加一天
/** * 天数加一 * @param dateTime * @return * @throws Exception */ public static String dateFamte(String dateTime) throws Exception{ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date = format.parse(dateTime); Calendar calendar = Calendar.getInstance();//日历对象 calendar.setTime(date);//设置当前日期 calendar.add(Calendar.DAY_OF_MONTH, 1);//天数加一 return format.format(calendar.getTime()); }
七:把一个json字符串转换java对象
/** * 从一个JSON数组得到一个java对象数组,形如: * [{"id" : idValue, "name" : nameValue}, {"id" : idValue, "name" : nameValue}, ...] * @param object * @param clazz * @return */ public static Object[] getDTOArray(String jsonString, Class clazz){ JSONArray array = JSONArray.fromObject(jsonString); Object[] obj = new Object[array.size()]; for(int i = 0; i < array.size(); i++){ JSONObject jsonObject = array.getJSONObject(i); obj[i] = JSONObject.toBean(jsonObject, clazz); } return obj; }
0 0
- 做java web项目中常用的工具类中的方法
- 分享 做javaEE项目中常用的工具类中的方法!
- 分享 做javaEE项目中常用的工具类中的方法!
- 分享 做javaEE项目中常用的工具类中的方法!
- Java Web项目中常用的工具类
- java web项目常用的工具类——项目经验分享
- Java web项目中jsp使用java类的方法
- Java web 中几个常用的获取项目路径的方法
- 推荐几个WEB中常用的工具方法
- 项目中常用的工具类
- 项目中常用的简单工具类
- java中的集合工具类Collections中的常用方法
- JAVA中常用的时间工具类
- java中常用的工具类
- java中常用的工具类(-)
- java中常用的工具类
- java中常用的工具类
- java中常用的工具类(-)
- 28个Java常用的工具类
- eclipse运行项目时怎么设置虚拟机内存大小
- 自动生成Makefile的全过程详解2
- VS2010 常用快捷键
- 杭电4500小Q系列故事——屌丝的逆袭
- 做java web项目中常用的工具类中的方法
- 使eclipse XML文件内容变整齐
- Android实战简易教程<三十二>(自定义View登录注册界面EditText-实现一键清空)
- ios7 UITableViewCell高度自适应
- Lua中__index和__newindex之间的沉默与合作
- 零基础写Java知乎爬虫之抓取知乎答案
- 选择器的基本分类和扩展选择器
- setArguments 出现fragment already active异常
- Android实战简易教程<三十三>(自定义View实现控件晃动提示效果)