2020.7.1工作日志

    技术2022-07-10  174

    2020.7.1 工作日志 写博客的第一天,刚刚参加工作,小白一枚,仅仅是做一些工作记录。

    需求: 点击页面拇指图按钮,从nginx中访问图片在页面显示。在此过程中遇到的问题。

    一、

    问题: 在往封装类中设置属性的时候一直报警告: Null pointer access: The variable sysPngTif can only be null at this location. 原因:

    这是因为在声明的时候设置成了null,后面的代码中又没有对这个对象new一下进行初始化,所以报空指针异常。

    修改后代码:

    @Override public SysPngTif selectSysPngTifByTifPath(int id) { SysPngTif sysPngTif = new SysPngTif; OutputStream outputStream = null; ImageEncoder imageEncoder = null; // 获取图像路径 String tifPath = wakeInfraredMapper.selectWakeInfraredById(id).getImagePath(); // 判断图像路径是否为空 if (!"".equals(tifPath) && tifPath.length() > 0) { // 查询有没有对应的pngPath SysPngTif pngPath = sysPngTifMapper.selectSysPngTifByImagePath(tifPath); // pngPath为空,没有对应png,获取imagePath转换png if (pngPath == null || pngPath.getId() == null) { // png命名,和tifpath一样 String pngPathName = tifPath.substring(tifPath.lastIndexOf("/") + 1, tifPath.indexOf(".")) + ".png"; System.out.println(pngPathName); // png存储路径 String pngFilePath = pngLocalPath + pngPathName; // tif转换png RenderedOp ro = JAI.create("fileload", tifPath); try { outputStream = new FileOutputStream(pngFilePath); PNGEncodeParam param = new PNGEncodeParam.RGB(); imageEncoder = ImageCodec.createImageEncoder("PNG", outputStream, param); imageEncoder.encode(ro); outputStream.flush(); } catch (Exception e) { e.printStackTrace(); } try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println(tifPath); sysPngTif.setImagePath(tifPath); sysPngTif.setPngPath(pngWebPath + pngPathName); sysPngTifMapper.insertSysPngTif(sysPngTif); } else { sysPngTif = pngPath; } } else { wakeInfraredMapper.selectWakeInfraredById(id).getImagePath(); } return sysPngTif; }

    二、

    问题: 前台获取拇指图时,第一次获取的宽高较小,后面几次就显示正常。 原因: 页面中对图片的宽高设置如下:

    在页面打断点可以看出:

    前台拿到的data中并没有imageHeight、imageWidth这两个属性,所以会出现问题。

    修改后: 前端页面js中直接将宽高设置成定长,解决!

    Processed: 0.029, SQL: 8