【fix sonar】 I18nUtil.java文件

This commit is contained in:
tianwenbo
2023-03-10 17:47:51 +08:00
parent eb290dc443
commit 9fd17cdb8a
@@ -20,6 +20,9 @@ import java.util.Properties;
* @author xuxueli 2018-01-17 20:39:06
*/
public class I18nUtil {
private I18nUtil() {
}
private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);
private static Properties prop = null;
@@ -49,7 +52,11 @@ public class I18nUtil {
* @return
*/
public static String getString(String key) {
return loadI18nProp().getProperty(key);
Properties properties = loadI18nProp();
if(properties!=null&&properties.getProperty(key)!=null){
return properties.getProperty(key);
}
return "";
}
/**
@@ -59,21 +66,24 @@ public class I18nUtil {
* @return
*/
public static String getMultString(String... keys) {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
Properties prop = loadI18nProp();
if (keys!=null && keys.length>0) {
for (String key: keys) {
map.put(key, prop.getProperty(key));
if(prop!=null) {
map.put(key, prop.getProperty(key));
}
}
} else {
for (String key: prop.stringPropertyNames()) {
map.put(key, prop.getProperty(key));
if(prop!=null){
for (String key : prop.stringPropertyNames()) {
map.put(key, prop.getProperty(key));
}
}
}
String json = JacksonUtil.writeValueAsString(map);
return json;
return JacksonUtil.writeValueAsString(map);
}
}