jeecg uedit 自定義圖片上傳路徑

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;
}

至此已經大功告成了,看一下效果吧:

如果文章有錯的地方歡迎指正,大家互相留言交流。習慣在微信看技術文章,想要獲取更多的Java資源的同學,可以關注微信公衆號:niceyoo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章