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     }

 

 

 

posted @ 2016-04-16 23:48  Ray.Wang  阅读(8213)  评论(2编辑  收藏  举报