• maven 时区设置&ip&jdk编译版本


    一、spring boot 解决时区的问题

    方法一: application.properties 

    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    spring.jackson.time-zone=Asia/Shanghai 

    方法二:启动类上加

    public static void main(String[] args) {
       TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
      SpringApplication.run(BaseMicroServiceApplication.class, args);
    }

    二、获取用户 IP 的工具类

    public static String getIpAddress(HttpServletRequest request) {
            String unknown = "unknown";
            String ip = request.getHeader("x-forwarded-for");
            if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
                ip = request.getHeader("Proxy-Client-IP");
            }
            if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
                ip = request.getHeader("WL-Proxy-Client-IP");
            }
            if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
                ip = request.getRemoteAddr();
            }
            if ("0:0:0:0:0:0:0:1".equals(ip)) {
                ip = "127.0.0.1";
            }
            if (ip.split(",").length > 1) {
                ip = ip.split(",")[0];
            }
            return ip;
        }
    
        public static String getIpInfo(String ip) {
            if ("127.0.0.1".equals(ip)) {
                ip = "127.0.0.1";
            }
            String info = "";
            try {
                URL url = new URL("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip);
                HttpURLConnection htpcon = (HttpURLConnection) url.openConnection();
                htpcon.setRequestMethod("GET");
                htpcon.setDoOutput(true);
                htpcon.setDoInput(true);
                htpcon.setUseCaches(false);
    
                InputStream in = htpcon.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
                StringBuffer temp = new StringBuffer();
                String line = bufferedReader.readLine();
                while (line != null) {
                    temp.append(line).append("
    ");
                    line = bufferedReader.readLine();
                }
                bufferedReader.close();
                JSONObject obj = (JSONObject) JSON.parse(temp.toString());
                if (obj.getIntValue("code") == 0) {
                    JSONObject data = obj.getJSONObject("data");
                    info += data.getString("country") + " ";
                    info += data.getString("region") + " ";
                    info += data.getString("city") + " ";
                    info += data.getString("isp");
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (ProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return info;
        }

    三、使用Maven 时,指定编译运行 jdk 版本

     
    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>
  • 相关阅读:
    HTML5 GeoLocation 地理定位
    HTML5 LocalStorage 本地存储
    JS-事件代理(委托)
    面向对象(封装、继承、多态)
    js图片预加载
    jQuery 事件
    svn无法验证
    Ext.data.Store(转)
    ExtJS实现Excel导出(转)
    <![CDATA[ ]]> 意思
  • 原文地址:https://www.cnblogs.com/bytecodebuffer/p/11822388.html
Copyright © 2020-2023  润新知