Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
12e68fab
Commit
12e68fab
authored
Aug 23, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增本地资源通用下载方法
parent
47852057
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
3 deletions
+31
-3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
+21
-0
ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java
+1
-1
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
+5
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
+2
-1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
+2
-1
No files found.
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
View file @
12e68fab
...
...
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.multipart.MultipartFile
;
import
com.ruoyi.common.config.Global
;
import
com.ruoyi.common.config.ServerConfig
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.file.FileUploadUtils
;
...
...
@@ -88,4 +89,24 @@ public class CommonController
return
AjaxResult
.
error
(
e
.
getMessage
());
}
}
/**
* 本地资源通用下载
*/
@GetMapping
(
"/common/download/resource"
)
public
void
resourceDownload
(
String
resource
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
// 本地资源路径
String
localPath
=
Global
.
getProfile
();
// 数据库资源地址
String
downloadPath
=
localPath
+
StringUtils
.
substringAfter
(
resource
,
Constants
.
RESOURCE_PREFIX
);
// 下载名称
String
downloadName
=
StringUtils
.
substringAfterLast
(
downloadPath
,
"/"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"multipart/form-data"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
FileUtils
.
setFileDownloadHeader
(
request
,
downloadName
));
FileUtils
.
writeBytes
(
downloadPath
,
response
.
getOutputStream
());
}
}
ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java
View file @
12e68fab
...
...
@@ -129,7 +129,7 @@ public class Global
*/
public
static
String
getDownloadPath
()
{
return
getProfile
()
+
"/download"
;
return
getProfile
()
+
"/download
/
"
;
}
/**
...
...
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
View file @
12e68fab
...
...
@@ -61,4 +61,9 @@ public class Constants
* 排序的方向 "desc" 或者 "asc".
*/
public
static
final
String
IS_ASC
=
"isAsc"
;
/**
* 资源映射路径 前缀
*/
public
static
final
String
RESOURCE_PREFIX
=
"/profile"
;
}
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
View file @
12e68fab
...
...
@@ -5,6 +5,7 @@ import java.io.IOException;
import
org.apache.commons.io.FilenameUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.ruoyi.common.config.Global
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.exception.file.FileNameLengthLimitExceededException
;
import
com.ruoyi.common.exception.file.FileSizeLimitExceededException
;
import
com.ruoyi.common.exception.file.InvalidExtensionException
;
...
...
@@ -147,7 +148,7 @@ public class FileUploadUtils
{
int
dirLastIndex
=
uploadDir
.
lastIndexOf
(
"/"
)
+
1
;
String
currentDir
=
StringUtils
.
substring
(
uploadDir
,
dirLastIndex
);
String
pathFileName
=
"/profile
/"
+
currentDir
+
"/"
+
fileName
;
String
pathFileName
=
Constants
.
RESOURCE_PREFIX
+
"
/"
+
currentDir
+
"/"
+
fileName
;
return
pathFileName
;
}
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
View file @
12e68fab
...
...
@@ -8,6 +8,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
com.ruoyi.common.config.Global
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.framework.interceptor.RepeatSubmitInterceptor
;
/**
...
...
@@ -40,7 +41,7 @@ public class ResourcesConfig implements WebMvcConfigurer
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
/** 本地文件上传路径 */
registry
.
addResourceHandler
(
"/profile
/**"
).
addResourceLocations
(
"file:"
+
Global
.
getProfile
()
+
"/"
);
registry
.
addResourceHandler
(
Constants
.
RESOURCE_PREFIX
+
"
/**"
).
addResourceLocations
(
"file:"
+
Global
.
getProfile
()
+
"/"
);
/** swagger配置 */
registry
.
addResourceHandler
(
"swagger-ui.html"
).
addResourceLocations
(
"classpath:/META-INF/resources/"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment