jeecg uedit 圖片上傳配置自定義物理路徑,簡單描述:我們知道 jeecg 中使用的 uedit 默認圖片上傳路徑為 "當前項目\plug-in\ueditor\jsp\uploadx\日期\圖片.png",但是把圖片放在項目中顯然是很不友好的,所以我們自定義上傳路徑。
1、plug-in\ueditor\ueditor.config.js
放開 insertimage 注釋
toolbars:[[
忽略
"|",
"insertimage",
"|",
忽略]]
我修改了圖片的一些路徑,以至於想然他看起來醒目一些,其中:minyiyun 為我的醒目名稱:

顯示效果:

圖二能否實現訪問的主要步驟是需要配置 tomcat - service.xml ,如下圖

<Context docBase="D:\upFiles\" path="/minyiyun/myyImg" reloadable="true"/>
如果訪問不了,在 web.xml 增加你的路徑:

2、plug-in\ueditor\jsp\imageManager.jsp
主要修改 imgStr、realpath 變量的值:
<%
僅做示例用,請自行修改
String path = "";
String imgStr ="";
##String realpath = getRealPath(request,path)+"/"+path;##
String realpath = "D:/upFiles/upload1/";
System.out.println("realpath:"+realpath);
List<File> files = getFiles(realpath,new ArrayList());
for(File file :files ){
##imgStr+=file.getPath().replace(getRealPath(request,path),"")+"ue_separate_ue";##
imgStr+=file.getPath().split("upFiles")[1] + "ue_separate_ue";
}
if(imgStr!=""){
imgStr = imgStr.substring(0,imgStr.lastIndexOf("ue_separate_ue")).replace(File.separator, "/").trim();
}
out.print(imgStr);
%>
被 "##" 標記的為原來的寫法,該方法的修改主要為了獲取以前上傳的所有圖片。

3、src\main\java\org\jeecgframework\core\servlet\Uploader.java
修改了 getPhysicalPath() 方法,將之前獲取.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\minyiyun\plug-in\ueditor\jsp\upload1 的目錄改為讀取 system.properties 文件標簽。

private String getPhysicalPath(String path) {
return ResourceUtil.getConfigByName("webUploadpath") + "/" + path;
}
至此已經大功告成了,看一下效果吧:

18年專科畢業后,期間一度迷茫,最近我創建了一個公眾號用來記錄自己的成長,微信公眾號:小偉后端筆記
