老师您好,为什么我的relativepath会直接获取我的图片根路径

来源:4-5 店铺注册之Service层的实现

weixin_慕丝6290347

2022-02-05

public static String generateThumbnail(File thumbnail,String targetAddr) {
		String realFileName = getRandomFileName();
		String extension = getFileExtension(thumbnail);
		makeDirPath(targetAddr);
		String relativeAddr = targetAddr + realFileName + extension;
		logger.debug("current relativeAddr is" + relativeAddr);
		File dest = new File(PathUtil.getImgBasePath()+relativeAddr);
		logger.debug("current completeAddr is" + PathUtil.getImgBasePath() + relativeAddr);
		try {
			Thumbnails.of(thumbnail).size(200, 200)
			.watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File(basePath + "/watermark.jpg")),0.25f)
			.outputQuality(0.8).toFile(dest);
			Thumbnails.of(thumbnail).size(200, 200)
			.watermark(Positions.BOTTOM_RIGHT,ImageIO.read(new File("/watermark.jpg")),0.25f)
			.outputQuality(0.8).toFile(dest);
		}catch(IOException e) {
			logger.error(e.toString());
			e.printStackTrace();
		}
		return relativeAddr;
	}
	

写回答

1回答

翔仔

2022-02-05

同学好,可以调试看看你传入的targetAddr是啥,设置断点调试下就知道答案了

0
2
weixin_慕丝6290347
解决了 是ShopService里面有路径获取错误
2022-02-06
共2条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程