mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix resource
This commit is contained in:
parent
b0e37e3ef3
commit
761c8c1757
@ -314,7 +314,7 @@ public class FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 如果用户需要相对项目路径,则使用project:前缀
|
// 如果用户需要相对项目路径,则使用project:前缀
|
||||||
if (path.startsWith("project:")) {
|
if (path.startsWith(UrlUtil.PROJECT_URL_PREFIX)) {
|
||||||
return new File(path);
|
return new File(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ public class ResourceUtil {
|
|||||||
*/
|
*/
|
||||||
public static Resource getResource(final String path) {
|
public static Resource getResource(final String path) {
|
||||||
if (StrUtil.isNotBlank(path)) {
|
if (StrUtil.isNotBlank(path)) {
|
||||||
if (path.startsWith(UrlUtil.FILE_URL_PREFIX) || FileUtil.isAbsolutePath(path)) {
|
if (StrUtil.startWithAny(path, UrlUtil.FILE_URL_PREFIX, UrlUtil.PROJECT_URL_PREFIX) || FileUtil.isAbsolutePath(path)) {
|
||||||
return new FileResource(path);
|
return new FileResource(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,10 @@ public class UrlUtil {
|
|||||||
* 针对ClassPath路径的伪协议前缀(兼容Spring): "classpath:"
|
* 针对ClassPath路径的伪协议前缀(兼容Spring): "classpath:"
|
||||||
*/
|
*/
|
||||||
public static final String CLASSPATH_URL_PREFIX = "classpath:";
|
public static final String CLASSPATH_URL_PREFIX = "classpath:";
|
||||||
|
/**
|
||||||
|
* 针对project路径的伪协议前缀: "project:"
|
||||||
|
*/
|
||||||
|
public static final String PROJECT_URL_PREFIX = "project:";
|
||||||
/**
|
/**
|
||||||
* URL 前缀表示文件: "file:"
|
* URL 前缀表示文件: "file:"
|
||||||
*/
|
*/
|
||||||
|
@ -59,6 +59,6 @@ public class ResourceUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
void getResourceTest2() {
|
void getResourceTest2() {
|
||||||
// project:开头表示基于项目的相对路径,此处无文件报错
|
// project:开头表示基于项目的相对路径,此处无文件报错
|
||||||
Assertions.assertThrows(NoResourceException.class, () -> ResourceUtil.getResource("project:test.xml"));
|
Assertions.assertThrows(NoResourceException.class, () -> ResourceUtil.getResource("project:test.xml").getStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user