2019-09-20 14:45
工具类PropertiesUtil
import com.jfinal.kit.PathKit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* @Date: 2019-09-20 14:59
* @Version v1.0.0
*/
public class PropertiesUtil {
public static final String FILE_NAME = "api.properties";
/**
* 循环所有key value
*/
public static Map list(Properties p) {
Map propertiesMap = new HashMap<>();
Enumeration en = p.propertyNames(); //得到配置文件的名字
while(en.hasMoreElements()) {
String strKey = (String) en.nextElement();
String strValue = p.getProperty(strKey);
propertiesMap.put(strKey,strValue);
}
return propertiesMap;
}
/**
* 通过key删除value
* @param key
*/
public static void delete(Properties p,String key) {
p.remove(key);
fileupdate(p);
}
/**
* 修改或者新增key
* @param key
* @param value
*/
public static void update(Properties p,String key, String value) {
p.setProperty(key, value);
fileupdate(p);
}
public static void fileupdate(Properties p){
FileOutputStream oFile = null;
try {
oFile = new FileOutputStream(PathKit.getRootClassPath()+ File.separator + FILE_NAME);
p.store(oFile, "");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
oFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
2019-08-31 08:58
@lyh061619 确实是这样,我才在这里提问的。参数结构复杂,数据量大时候非常容易出错,不安规则走的话,会变成每个接口加密规则都不一样,也挺麻烦的。用oauth2.0,我们做平台接口,不是所有客户都有账号