ObjectMapper将List和String互转
摘要:ObjectMapper objectMapper = new ObjectMapper(); List<Cell>cells=new ArrayList(); //List转String String str= objectMapper.writeValueAsString(cells); //S
阅读全文
java生成pdf文字水印和图片水印
摘要:@GetMapping(value = "/dypdf/", produces = MediaType.APPLICATION_PDF_VALUE) public ResponseEntity<InputStreamResource> dypdf(@RequestParam(value = "ztI
阅读全文
Date与LocalDateTime、LocalDate、LocalTime互转,以及LocalDateTime常规操作
摘要:一、Date与LocalDateTime、LocalDate、LocalTime互转 1、Date转LocalDateTime、LocalDate、LocalTime LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault
阅读全文
java后端获取本机的ip地址而非localhost和127.0.0.1
摘要:@GetMapping("/selectIp") public HashMap<String, String> selectIp() { String ipHostAddress = ""; try { Enumeration<NetworkInterface> allNetInterfaces =
阅读全文
java后端通过数据库地址等信息访问第三方数据库,以及JdbcTemplate的in语法参数解决办法
摘要:一、通过数据库信息访问第三方数据库 本例子是从一张存储数据库信息表中查出第三方数据库信息,再进行访问的 1、 对数据库密码的加密、解密类 public class SecretHelper { public byte[] random(int len) { byte[] buf = new byte
阅读全文
java的Object转实体类对象
摘要:直接强转 但是有时候强转会失败,比如下图所示 虽然这种强转方式没有出现编译错误,但是运行起来可能就会报错了,比如下图所示 java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class cn.xx
阅读全文
后端调用其他人提供的接口,把得到的JSON字符串数据反序列化成对象或数组
摘要:调用其他人提供的API的参考链接:https://www.baeldung.com/rest-template 下面代码是对于JSON字符串格式为这种的: {"Table":[{"name":"a1","code":"aaa"},{"name":"b1","code":"bbb"}]} 1、 @Ge
阅读全文
java创建List或数组时候 初始化赋值
摘要:集合一般可以直接这样: 数组可以: 数组和集合互转 其他的可以参考下面链接 参考链接1:https://blog.csdn.net/a1064072510/article/details/84943271 参考链接2:https://blog.csdn.net/qq_36827957/article
阅读全文
springboot分页且本表或引用其他表的多字段排序查询
摘要:1、本表多字段排序分页 ybsjlgsszRepository.findAllByQjId(qjId, PageRequest.of(page - 1, size, Sort.Direction.ASC, "bylc", "sylc")) 2、引用其他表的多字段排序分页,用hql来实现 首先通过na
阅读全文
Calendar的用法以及建议禁止用calendar 不建议用date 推荐用LocalDate、LocalTime、LocalDateTime【java8新提供的类】
摘要:1、通常使用Calendar,首先需要 Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); 指定时间: calendar.setTime(date);//date为日期类型 /
阅读全文
This inspection suggests to replace null check with Object/Stream static method
摘要:此检查建议用对象/流静态方法替换空检查 例如: Bmb bmb = bmbRepository.findById(allByUserId.getBmId()).orElseThrow(); if (bmb != null) { it.setBmb(bmb); } else { it.setBmb(n
阅读全文
后端Itext生成pdf到传到前端,支票打印A4纸,1毫米大概对应2.83f,以及PdfPTable获取高度失败和PdfPCell居中不生效的解决办法
摘要:@GetMapping(value = "/zppdf/{id}", produces = MediaType.APPLICATION_PDF_VALUE) public ResponseEntity<InputStreamResource> index(@Valid @PathVariable("
阅读全文
easyexcel导入获取表头并且表头为不固定列
摘要:1、Controller层 @PostMapping("upload") @ResponseBody public HashMap<String, Object> upload(@RequestParam(value = "file") MultipartFile file, @RequestPar
阅读全文
EasyExcel的不确定表头(根据数据生成表头)的excel导出和二级表头或多级表头以及设置表头的宽度自适应
摘要:1、效果如图 2、Controller @GetMapping("/exportExcel") public void exportExcel(@RequestParam(value = "menu") String menu, @RequestParam(value = "dwflglId") i
阅读全文
java的Iterable转stram流操作再转List集合
摘要:List<Integer> collect = StreamSupport.stream(dwflztglbRepository.findAll().spliterator(), false).map(Dwflztglb::getZtId).distinct().collect(Collectors
阅读全文
EasyExcel简单导入示例
摘要:一、后端 1、导入字段的类 public class UploadAjgl { private String ajnd; private String ajh; private String gjh; private String djh; //记得get和set,toString ...... }
阅读全文
Reports local variable of wrapper type though all usages allowed to be primitive and count of unnecessary boxing/unboxing operations reduces
摘要:Reports local variable of wrapper type though all usages allowed to be primitive and count of unnecessary boxing/unboxing operations reduces 报告包装器类型的局
阅读全文
java的(SXSSF)EasyExcel阿里开源excel导出和XSSF导出简单示例
摘要:一、EasyExcel阿里开源excel导出(SXSSF) 参考链接:EasyExcel阿里开源excel导出 1、建立映射到excel文件的映射类,然后get和set import com.alibaba.excel.annotation.ExcelProperty; public class D
阅读全文
Reports lambdas which can be replaced with method references
摘要:报告可以用方法引用替换的lambda 1、获取对象的属性值 警告截图: 解决截图: 把lambda表达式x->x.getFplrId()改成相应的“实体类::获取实体类的属性”,如Cfptz::getFplrId 2、使用自定义的函数 警告截图: 解决截图: 3、使用集合的函数 警告截图 解决截图:
阅读全文
No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call的解决办法
摘要:No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call 遇到这种问题,应该是你的controller层直接调用了Repository的删
阅读全文