jeesite ckfinder mac/linux 文件上傳路徑設置


背景:

如果你使用的是Mac 或者 Ubuntu 這種 Unix系統的話,你一定知道Unix系統的文件路徑分隔符是 / 而Windows系統文件分隔符是 \

當你設置了jeesite.properties 中的 

userfiles.basedir= D\:\\workspace\\jeesite

如果不設置,上傳的路徑會是:dir = ServletContextFactory.getServletContext().getRealPath("/");

在如果你使用的是Windows操作系統,將來程序也要部署在Windows操作系統上的話,看着這里就可以了,stop,感興趣的同學可以繼續。

 

thinkGen 這哥們把寫了個ckfinder 的配置類

com.thinkgem.jeesite.common.web.CKFinderConfig

繼承了 

com.ckfinder.connector.configuration.Configuration

來完成通過 jeesite.properties 一個配置文件配置整個項目配置。真是考慮的夠全面的。但問題來了。

 

這里如果配置的是絕對的Unix路徑的話:比如,/User/jeesite 會被轉換為 User/jeesite 的相對路徑。

 

說了這么多如何解決整個問題那?

 

1.找到:

com.thinkgem.jeesite.common.utils.FileUtils.java

修改 path方法:增加15-17行,搞定收工。

2.測試你的程序吧。

 1 /**
 2      * 修復路徑,將 \\ 或 / 等替換為 File.separator
 3      * @param path
 4      * @return
 5      */
 6     public static String path(String path){
 7         String p = StringUtils.replace(path, "\\", "/");
 8         p = StringUtils.join(StringUtils.split(p, "/"), "/");
 9         if (!StringUtils.startsWithAny(p, "/") && StringUtils.startsWithAny(path, "\\", "/")){
10             p += "/";
11         }
12         if (!StringUtils.endsWithAny(p, "/") && StringUtils.endsWithAny(path, "\\", "/")){
13             p = p + "/";
14         }
15         if(path.startsWith("/")){
16             p = "/" + p;
17         }
18         return p;
19     }

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM