工作中使用到的代码或者脚本记录
从classpath路径中,获取文件
import org.springframework.core.io.ClassPathResource;
import org.apache.commons.io.FileUtils;
@Test
public void testfile() throws IOException {
File file = new ClassPathResource("aaa/bbb.json").getFile();
String jsonStr = FileUtils.readFileToString(file, Charset.defaultCharset());
}
spring单元测试设置private属性
@Test
public void whenNonPublicMethod_thenReflectionTestUtilsInvokeMethod() {
Employee employee = new Employee();
ReflectionTestUtils.setField(employee, "id", 1);
employee.setName("Smith, John");
assertTrue(ReflectionTestUtils.invokeMethod(employee, "employeeToString")
.equals("id: 1; name: Smith, John"));
}
发起HTTP请求
使用 retrofit
参考:https://www.baeldung.com/retrofit
获取注解
参考:https://www.cnblogs.com/wujf/p/9115329.html
计算对象大小
参考:https://www.jianshu.com/p/aaddf00a1d83
使用VisualVM dump内存,然后查看对象占用内存。
csv操作
https://mkyong.com/java/how-to-read-and-parse-csv-file-in-java/
https://www.baeldung.com/opencsv