📄 commonfunction.java
字号:
package gzwj.common;
import java.io.File;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Vector;
public class CommonFunction {
public CommonFunction()
{
}
// 用户
public static String Function_addslash(String input_string)
{
String F_input_string = input_string;
//在此扩展数据过滤代码
return F_input_string;
}
//字符编码转换 中文乱码
public static String Function_conv(String conv_string,String Start_type,String Last_type)
{
String F_conv_string = conv_string;
String F_Start_type = Start_type;
String F_Last_type = Last_type;
if ( F_Start_type == "" )
{
F_Start_type = "ISO-8859-1";
}
if (F_Last_type == "")
{
F_Last_type = "GB2312";
}
try
{
F_conv_string =new String(F_conv_string.getBytes(F_Start_type),F_Last_type);
}catch(Exception e)
{
System.out.print("字符编码转换错误");
}
return F_conv_string;
}
public static String Function_getCurrent_time()
{
String current_time = "";
try{
current_time = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date());
}catch(Exception e)
{
System.out.println("时间格式错误");
}
return current_time;
}
//重载
public static String Function_getCurrent_time(String time_format)
{
String current_time = "";
try{
//System.out.println(new java.text.SimpleDateFormat(time_format).format(new java.util.Date()));
current_time = new java.text.SimpleDateFormat(time_format).format(new java.util.Date());
}catch(Exception e)
{
System.out.println("时间格式错误");
}
return current_time;
}
public static ArrayList s_multi(int totle_number,
int current_page,
String action,
int select_page,
int page_number
)
{
//分页函数参数列表:
// 1.int totle_number //总条数
// 2.int current_page //当前页数
// 3.String action //当前操作
// 4.int select_page //goto...
// 5.int page_number //默认每页显示个数
ArrayList multi = new ArrayList();
//此Vector对象中将包含
// 1.总个数
// 2.每页显示数
// 3.总页数
// 4.当前页数
// 5.页数列表
// 6.limit字符串
current_page = Math.abs(current_page);
if(page_number==0)
{
page_number = 16;
//默认每页显示个数;
}
page_number = Math.abs(page_number);
multi.add(0,new Integer(totle_number)); // 1
multi.add(1,new Integer(page_number)); // 2
int page_totle = 0;
//总页数
if(totle_number != 0)
{
Double temp = new Double (Math.ceil(Double.parseDouble(totle_number/page_number + "." + totle_number%page_number)));
page_totle = temp.intValue();
}
multi.add(2,new Integer(page_totle)); // 3
if(action.equals("HeadPage"))
{
current_page = 1;
multi.add(3,new Integer(current_page)); // 4
}
if(action.equals("EndPage"))
{
current_page = page_totle;
multi.add(3,new Integer(current_page)); // 4
}
if(action.equals("UpPage"))
{
current_page = current_page - 1;
if(current_page <= 0)
{
current_page = 1;
multi.add(3,new Integer(1));
} // 4
else
multi.add(3,new Integer(current_page));
}
if(action.equals("Goto"))
{
current_page = select_page;
multi.add(3,new Integer(select_page)); // 4
}
if(action.equals("") || action.equals(null))
{
multi.add(3,new Integer(1)); // 4
}
if(action.equals("NextPage"))
{
current_page = current_page + 1;
if(current_page >= page_totle)
{
multi.add(3,new Integer(page_totle)); // 4
current_page = page_totle;
}
else
multi.add(3,new Integer(current_page));
}
String list_option = "<option value=0>请选择</option>";
for(int list_temp = 1;list_temp <= page_totle; list_temp++)
{
list_option = list_option + "<option value=" + list_temp + ">第" + list_temp + "页</option>";
}
multi.add(4,list_option);
multi.add(5,new Integer(Math.abs(current_page-1)*page_number));
return multi;
}
public static void Function_deleteDirectory(File dir) throws IOException {
if( (dir == null) || !dir.isDirectory()) {
throw new IllegalArgumentException(
"Argument "+dir+" is not a directory. "
);
}
File[] entries = dir.listFiles( );
int sz = entries.length;
for(int i=0; i<sz; i++) {
if(entries[i].isDirectory( )) {
Function_deleteDirectory(entries[i]);
} else {
entries[i].delete( );
}
}
dir.delete();
}
public static void Function_delete_file(String path)
{
File file = new File(path);
file.delete();
}
public static String GetMD5String(String s)
{
char hexDigits[] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
'e', 'f'};
try
{
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
}
catch (Exception e)
{
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -