1. 程式人生 > 實用技巧 >京東閱讀(web)體驗優化

京東閱讀(web)體驗優化

一、 複製data資料夾到自己的專案當中

可以進行載入到這個檔案即可 博主放入在專案的根目錄當中

請移步Gitee pull 該檔案 https://gitee.com/yangbuyi/ip_file

https://gitee.com/yangbuyi/ip_file

獲取點選量來一波 https://www.yangbuyi.top/login.html

https://www.yangbuyi.top/login.html

帶入maven依賴 因為這個編輯器的原因 複製依賴 顯示不出來淦!!!! 圖片自己打吧

                             org.lionsoul                   ip2region  
1.7.2

二、最重要的一步 編譯地理位置

找到自己的專案地址

執行開啟cmd 執行這段程式碼

java -Dfile.encoding=utf-8 -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv

java -Dfile.encoding=utf-8 -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv


請跟著一步步來


程式碼開始 建立iputils

package top.yangbuyi.system.webapi;import org.lionsoul.ip2region.DataBlock;import org.lionsoul.ip2region.DbConfig;import org.lionsoul.ip2region.DbSearcher;import org.lionsoul.ip2region.Util;import java.io.File;import java.io.UnsupportedEncodingException;import java.lang.reflect.Method;import java.net.URLDecoder;/** * description:  楊不易網站 :www.yangbuyi.top * program:  yangbuyi-erp-2020 * ClassName:  iputils * create:  2020-07-10 09:20 * * @author: yangbuyi * @since: JDK1.8 * @iputils: **//** * 具體請看 SQL當中的 data檔案  和jar包 * 通過下面語句進行 編譯 地理位置 * java -jar dbMaker-1.2.2.jar -src ./data/ip.merge.txt -region ./data/global_region.csv */public class iputils {            public static String getCityInfo(String ip) throws UnsupportedEncodingException {            //db            String dbPath = new File('SQL/data/ip2region.db').getPath();            dbPath = URLDecoder.decode(dbPath, 'UTF-8');            File file = new File(dbPath);            if (file.exists() == false) {                  System.out.println('Error: Invalid ip2region.db file');            }            //查詢演算法            int algorithm = DbSearcher.BTREE_ALGORITHM; //B-tree            //DbSearcher.BINARY_ALGORITHM //Binary            //DbSearcher.MEMORY_ALGORITYM //Memory            try {                  DbConfig config = new DbConfig();                  DbSearcher searcher = new DbSearcher(config, dbPath);                  //define the method                  Method method = null;                  switch (algorithm) {                        case DbSearcher.BTREE_ALGORITHM:                              method = searcher.getClass().getMethod('btreeSearch', String.class);                              break;                        case DbSearcher.BINARY_ALGORITHM:                              method = searcher.getClass().getMethod('binarySearch', String.class);                              break;                        case DbSearcher.MEMORY_ALGORITYM:                              method = searcher.getClass().getMethod('memorySearch', String.class);                              break;                  }                  DataBlock dataBlock = null;                  if (Util.isIpAddress(ip) == false) {                        System.out.println('Error: Invalid ip address');                  }                  dataBlock = (DataBlock) method.invoke(searcher, ip);                  String decode = URLDecoder.decode(dataBlock.getRegion(), 'UTF-8');                  return decode;            } catch (Exception e) {                  e.printStackTrace();            }            return null;      }            public static void main(String[] args) throws Exception {            System.err.println(iputils.getCityInfo('106.18.167.102'));      }      }

最後 測試程式碼

太累了吧!!!!