操作系统:Window10
1.在做到ShopServiceTest的JUnit测试时,报出错误信息:addShopImg error:null
如下:
解决办法:修改PathUtil.java的配置信息
检查private static String separator = System.getProperty("file.separator")
的两个separator是否一致并且拼写正确。
只要两个separator确保一致并且拼写无误就不会有null报错信息了
2.win10系统弹出:addShopImg error:character to be escaped is missing
如下:
解决办法:修改PathUtil.java的配置信息
将后面所有replaceAll里面的separator
全部改成Matcher.quoteReplacement(separator)
最后附上完全正确的PathUtil.java源代码:
package com.imooc.o2o.util;
import java.util.regex.Matcher;
public class PathUtil {
private static String separator = System.getProperty("file.separator");
public static String getImgBasePath() {
String os = System.getProperty("os.name");
String basePath = "";
if (os.toLowerCase().startsWith("win")) {
basePath = "E:/Work/o2o/image";
} else {
basePath = "/home/Work/o2o/image";
}
basePath = basePath.replaceAll("/", Matcher.quoteReplacement(separator));
return basePath;
}
public static String getShopImagePath(long shopId) {
String imagePath = "upload/item/shop/" + shopId + "/";
return imagePath.replaceAll("/", Matcher.quoteReplacement(separator));
}
}