mica-ip2region
是 ip2region
的封装,方便 spring boot
用户使用。
关于 ip2region
Gitee:https://gitee.com/lionsoul/ip2region
使用
maven
<dependency> <groupId>net.dreamlu</groupId> <artifactId>mica-ip2region</artifactId> <version>${version}</version> </dependency>
|
gradle
compile("net.dreamlu:mica-ip2region:${version}")
|
配置说明(已经内置,忽略)
配置项 |
默认值 |
说明 |
ip2region.db-file-location |
classpath:ip2region/ip2region.db |
ip2region.db 文件的地址,默认内置的文件 |
maven 自定义 ip2region.db 注意事项:
<plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <nonFilteredFileExtensions> <nonFilteredFileExtension>db</nonFilteredFileExtension> </nonFilteredFileExtensions> </configuration> </plugin>
|
注入 bean
@Autowired private Ip2regionSearcher regionSearcher;
|
方法说明
@Nullable IpInfo memorySearch(long ip);
@Nullable IpInfo memorySearch(String ip);
@Nullable IpInfo getByIndexPtr(long ptr);
@Nullable IpInfo btreeSearch(long ip);
@Nullable IpInfo btreeSearch(String ip);
@Nullable IpInfo binarySearch(long ip);
@Nullable IpInfo binarySearch(String ip);
@Nullable default String getAddress(long ip) { return getInfo(ip, IpInfo::getAddress); }
@Nullable default String getAddress(String ip) { return getInfo(ip, IpInfo::getAddress); }
@Nullable default String getAddressAndIsp(long ip) { return getInfo(ip, IpInfo::getAddressAndIsp); }
@Nullable default String getAddressAndIsp(String ip) { return getInfo(ip, IpInfo::getAddressAndIsp); }
|
微信 vs 公众号
精彩内容每日推荐!!!