赞
踩
TODO: 把内网的Http代码包搞到这里
TODO:
public static String getRealIP() { try { Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface .getNetworkInterfaces(); while (allNetInterfaces.hasMoreElements()) { NetworkInterface netInterface = allNetInterfaces .nextElement(); // 去除回环接口,子接口,未运行和接口 if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) { continue; } if (!netInterface.getDisplayName().contains("Intel") && !netInterface.getDisplayName().contains("Realtek")) { continue; } Enumeration<InetAddress> addresses = netInterface .getInetAddresses(); System.out.println(netInterface.getDisplayName()); while (addresses.hasMoreElements()) { InetAddress ip = addresses.nextElement(); if (ip != null) { // ipv4 if (ip instanceof Inet4Address) { System.out.println("ipv4 = " + ip.getHostAddress()); return ip.getHostAddress(); } } } break; } } catch (SocketException e) { System.err.println("Error when getting host ip address" + e.getMessage()); } return null; }
public String uuid(){
return UUID.randomUUID().toString().replaceAll("-","");
}
生成文件:
public void createFile() throws IOException { String filePath = "D:/a/b"; File dir = new File(filePath); // 一、检查放置文件的文件夹路径是否存在,不存在则创建 if (!dir.exists()) { dir.mkdirs();// mkdirs创建多级目录 } File checkFile = new File(filePath + "/filename.txt"); FileWriter writer = null; try { // 二、检查目标文件是否存在,不存在则创建 if (!checkFile.exists()) { checkFile.createNewFile();// 创建目标文件 } // 三、向目标文件中写入内容 // FileWriter(File file, boolean append),append为true时为追加模式,false或缺省则为覆盖模式 writer = new FileWriter(checkFile, true); writer.append("your content"); writer.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != writer) writer.close(); } }
写入内容:
try{
//如果module文件夹下没有bar.txt就会创建该文件
BufferedWriter bw = new BufferedWriter(new FileWriter("H:\\Company\\2019.7.2报表工具\\chart-desginer\\src\\views\\_test2\\module\\bar.txt"));
bw.write("Hello bar!"); //在创建好的文件中写入"Hello bar"
bw.close(); //关闭文件
}catch(IOException e) {
e.printStackTrace();
}
或
FileUtiles.copyInputStreamToFile(new ByteArrayInputStream(s.getBytes()),new File(path))
需要引入maven
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
读取内容
public static void readTxt(String filePath) { try { File file = new File(filePath); if(file.isFile() && file.exists()) { InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8"); BufferedReader br = new BufferedReader(isr); String lineTxt = null; while ((lineTxt = br.readLine()) != null) { System.out.println(lineTxt); } br.close(); } else { System.out.println("文件不存在!"); } } catch (Exception e) { System.out.println("文件读取错误!"); } }
如果传入的参数是一个json对象,则需要使用@RequestBody注解。不能用form-data类型, 需要使用raw类型
/** * 遍历JSONArray */ private static void LoopJSONArray(){ //颜色数组字符串 String colorStr = "[{'name':'刘德华','age':28,'sex':'男'}," + "{'name':'张学友','age':29,'sex':'男'}]"; //转化为数组 JSONArray jsonArr = JSONArray.fromObject(colorStr); Iterator<Object> it = jsonArr.iterator(); List<JSONObject> list = new ArrayList<JSONObject>(); while (it.hasNext()) { JSONObject jsonObj = (JSONObject) it.next(); String name = jsonObj.getString("name"); Integer age = (Integer) jsonObj.get("age"); System.out.println("name:"+name+";age:"+age); } }
condition ? exprIfTrue : exprIfFalse
condition 判断条件
四元运算符
condition ? '成功' : (condition1 ? '失败' : '其他')"
工具类
git branch --set-upstream-to=origin/xxxxxxxxx
serverTimezone=Asia/Shanghai
//还需要
allowPublicKeyRetrieval=true
package com.example.demo.util; import org.apache.tomcat.util.codec.binary.Base64; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; /** * @User远 * @Date2021/11/11 */ public class DESUtil { //算法名称 public static final String KEY_ALGORITHM = "DES"; //算法名称/加密模式/填充方式 //DES共有四种工作模式-->>ECB:电子密码本模式、CBC:加密分组链接模式、CFB:加密反馈模式、OFB:输出反馈模式 public static final String CIPHER_ALGORITHM = "DES/ECB/NoPadding"; /** * * 生成密钥key对象 * @param keyStr 密钥字符串 * @return 密钥对象 * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException * @throws Exception */ private static SecretKey keyGenerator(String keyStr) throws Exception { byte[] input = HexString2Bytes(keyStr); DESKeySpec desKey = new DESKeySpec(input); //创建一个密匙工厂,然后用它把DESKeySpec转换成 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey securekey = keyFactory.generateSecret(desKey); return securekey; } private static int parse(char c) { if (c >= 'a') return (c - 'a' + 10) & 0x0f; if (c >= 'A') return (c - 'A' + 10) & 0x0f; return (c - '0') & 0x0f; } // 从十六进制字符串到字节数组转换 public static byte[] HexString2Bytes(String hexstr) { byte[] b = new byte[hexstr.length() / 2]; int j = 0; for (int i = 0; i < b.length; i++) { char c0 = hexstr.charAt(j++); char c1 = hexstr.charAt(j++); b[i] = (byte) ((parse(c0) << 4) | parse(c1)); } return b; } /** * 加密数据 * @param data 待加密数据 * @param key 密钥 * @return 加密后的数据 */ public static String encrypt(String data, String key) throws Exception { Key deskey = keyGenerator(key); // 实例化Cipher对象,它用于完成实际的加密操作 Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); SecureRandom random = new SecureRandom(); // 初始化Cipher对象,设置为加密模式 cipher.init(Cipher.ENCRYPT_MODE, deskey, random); byte[] results = cipher.doFinal(data.getBytes()); // 该部分是为了与加解密在线测试网站(http://tripledes.online-domain-tools.com/)的十六进制结果进行核对 for (int i = 0; i < results.length; i++) { System.out.print(results[i] + " "); } System.out.println(); // 执行加密操作。加密后的结果通常都会用Base64编码进行传输 return Base64.encodeBase64String(results); } /** * 解密数据 * @param data 待解密数据 * @param key 密钥 * @return 解密后的数据 */ public static String decrypt(String data, String key) throws Exception { Key deskey = keyGenerator(key); Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); //初始化Cipher对象,设置为解密模式 cipher.init(Cipher.DECRYPT_MODE, deskey); // 执行解密操作 return new String(cipher.doFinal(Base64.decodeBase64(data))); } public static void main(String[] args) throws Exception { String source = "啦啦啦有限公司"; System.out.println("原文: " + source); String key = "A1B2C3D4E5F60708"; String encryptData = encrypt(source, key); System.out.println("加密后: " + encryptData); String decryptData = decrypt(encryptData, key); System.out.println("解密后: " + decryptData); } }
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。