JAVA常见问题
maven
基础
BigDecimal 解决double精度丢失问题(加减乘除)
排序
1.Collections排序 1)基本类型的元素 List<Integer> demo_list = new ArrayList<>(); Collections.sort(demo_list ); 2)实体类元素的排序:通过某个成员变量的值做比较 Collections.sort(demo_list , (Bean b1, Bean b2) -> b2.getXxx().compareTo(b31.getXxx())); 倒序: Collections.reversed(demo_list); 2.java8 Stream 排序 实体类元素的排序:通过某个成员变量的值做比较 demo_list.stream().sorted(Comparator.comparing(bean::getXxx));
SpringBoot
spriing boot 启动报错:Cannot determine embedded database driver class for database type NONE
Excel
Excel导出用IE浏览器文件名乱码解决
String userAgent = request.getHeader("user-agent"); if (userAgent != null && userAgent.indexOf("Firefox") >= 0 || userAgent.indexOf("Chrome") >= 0 || userAgent.indexOf("Safari") >= 0) { fileName= new String((fileName).getBytes(), "ISO8859-1"); } else { fileName=URLEncoder.encode(fileName,"UTF8"); //其他浏览器 }
spring boot获取resource目录下文件
Resource resource = new ClassPathResource("a/1.txt"); File file = resource.getFile();