📄 stringutils.java
字号:
package com.blue.web.common.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* The string utils class
* @author Lucifer
*
*/
public class StringUtils {
public static String toString(String s) {
return s == null ? "" : s;
}
public static String toString(int value) {
return String.valueOf(value);
}
public static int getInt(String s) {
return StringUtils.getInt(s, -1);
}
public static int getInt(Object obj) {
return getInt(obj.toString(), -1);
}
public static int getInt(String s, int defaultValue) {
try {
return Integer.parseInt(s.trim());
} catch (Exception e) {
return defaultValue;
}
}
public static boolean getBoolean(String s, boolean defaultValue) {
if (s == null)
return defaultValue;
if (s.equals("1") || s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes"))
return true;
else if (s.equals("0") || s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no"))
return false;
else
return defaultValue;
}
public static String toString(boolean value) {
return value ? "1" : "0";
}
public static String toString(java.sql.Date date) {
Date dt = new Date(date.getTime());
return toString(dt);
}
public static String toString(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return sdf.format(date);
} catch (Exception e) {
return null;
}
}
public static Date getDate(String s) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return sdf.parse(s);
} catch (Exception e) {
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -