mirror of https://github.com/elunez/eladmin
[新增功能](v2.5): 代码优化
parent
f8028c8310
commit
56c19f2f5b
|
@ -27,11 +27,9 @@ import org.lionsoul.ip2region.DbSearcher;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -42,6 +40,7 @@ import java.util.Date;
|
||||||
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
||||||
*/
|
*/
|
||||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(StringUtils.class);
|
private static final Logger log = LoggerFactory.getLogger(StringUtils.class);
|
||||||
private static boolean ipLocal = false;
|
private static boolean ipLocal = false;
|
||||||
private static DbSearcher searcher = null;
|
private static DbSearcher searcher = null;
|
||||||
|
@ -50,20 +49,16 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
SpringContextHolder.addCallBacks(() -> {
|
SpringContextHolder.addCallBacks(() -> {
|
||||||
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
||||||
if (ipLocal) {
|
if (ipLocal) {
|
||||||
/**
|
/*
|
||||||
* 此文件为独享 ,不必关闭
|
* 此文件为独享 ,不必关闭
|
||||||
*/
|
*/
|
||||||
String path = "ip2region/ip2region.db";
|
String path = "ip2region/ip2region.db";
|
||||||
String name = "ip2region.db";
|
String name = "ip2region.db";
|
||||||
DbConfig config = null;
|
DbConfig config;
|
||||||
try {
|
try {
|
||||||
config = new DbConfig();
|
config = new DbConfig();
|
||||||
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
|
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
|
||||||
searcher = new DbSearcher(config, file.getPath());
|
searcher = new DbSearcher(config, file.getPath());
|
||||||
} catch (DbMakerConfigException | FileNotFoundException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue