1 Star 0 Fork 744

ylh23y126/mica

forked from 如梦技术/mica 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

mica-ip2region

mica-ip2regionip2region 的封装,方便 spring boot 用户使用。

使用

maven

<dependency>
  <groupId>net.dreamlu</groupId>
  <artifactId>mica-ip2region</artifactId>
  <version>${version}</version>
</dependency>

gradle

compile("net.dreamlu:mica-ip2region:${version}")

配置说明(已经内置,可忽略)

配置项 默认值 说明
mica.ip2region.db-file-location classpath:ip2region/ip2region.db ip2region.db 文件的地址,默认内置的文件

maven 自定义 ip2region.db 注意事项:

maven resources 拷贝文件是默认会做 filter,会导致我们的文件发生变化,导致不能读,pom 中你需要添加下面的配置。

<plugin>
	<artifactId>maven-resources-plugin</artifactId>
	<configuration>
		<nonFilteredFileExtensions>
			<nonFilteredFileExtension>db</nonFilteredFileExtension>
		</nonFilteredFileExtensions>
	</configuration>
</plugin>

关于 ip2region

Gitee:https://gitee.com/lionsoul/ip2region

一般我们都会同步更新 ip2region.db 文件,不需要手动配置。

使用文档

注入 bean

@Autowired
private Ip2regionSearcher regionSearcher;

方法说明

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo memorySearch(long ip);

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo memorySearch(String ip);

/**
 * ip 位置 搜索
 *
 * @param ptr ptr
 * @return 位置
 */
@Nullable
IpInfo getByIndexPtr(long ptr);

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo btreeSearch(long ip);

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo btreeSearch(String ip);

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo binarySearch(long ip);

/**
 * ip 位置 搜索
 *
 * @param ip ip
 * @return 位置
 */
@Nullable
IpInfo binarySearch(String ip);

IpInfo 上的属性和方法:

/**
 * 城市id
 */
private Integer cityId;
/**
 * 国家
 */
private String country;
/**
 * 区域
 */
private String region;
/**
 * 省
 */
private String province;
/**
 * 城市
 */
private String city;
/**
 * 运营商
 */
private String isp;
/**
 * region ptr in the db file
 */
private int dataPtr;

/**
 * 拼接完整的地址
 *
 * @return address
 */
public String getAddress();
/**
 * 拼接完整的地址
 *
 * @return address
 */
public String getAddressAndIsp();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/ylh23y/mica.git
git@gitee.com:ylh23y/mica.git
ylh23y
mica
mica
master

搜索帮助