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
4d9c611a
Commit
4d9c611a
authored
Jul 27, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化下载文件
parent
43bde836
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
73 deletions
+4
-73
src/main/java/com/ruoyi/project/common/CommonController.java
+4
-30
src/main/resources/ehcache/ehcache-shiro.xml
+0
-43
No files found.
src/main/java/com/ruoyi/project/common/CommonController.java
View file @
4d9c611a
package
com
.
ruoyi
.
project
.
common
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
javax.servlet.http.HttpServletRequest
;
...
...
@@ -14,6 +9,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.stereotype.Controller
;
import
org.springframework.util.ResourceUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
com.ruoyi.common.utils.FileUtils
;
/**
* 通用请求处理
...
...
@@ -29,8 +25,6 @@ public class CommonController
public
void
fileDownload
(
String
fileName
,
Boolean
delete
,
HttpServletResponse
response
,
HttpServletRequest
request
)
{
String
realFileName
=
System
.
currentTimeMillis
()
+
fileName
.
substring
(
fileName
.
indexOf
(
"_"
)
+
1
);
InputStream
inputStream
=
null
;
OutputStream
os
=
null
;
try
{
String
filePath
=
ResourceUtils
.
getURL
(
"classpath:"
).
getPath
()
+
"static/file/"
+
fileName
;
...
...
@@ -38,36 +32,16 @@ public class CommonController
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setContentType
(
"multipart/form-data"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
setFileDownloadHeader
(
request
,
realFileName
));
File
file
=
new
File
(
filePath
);
inputStream
=
new
FileInputStream
(
file
);
os
=
response
.
getOutputStream
();
byte
[]
b
=
new
byte
[
1024
];
int
length
;
while
((
length
=
inputStream
.
read
(
b
))
>
0
)
FileUtils
.
writeBytes
(
filePath
,
response
.
getOutputStream
());
if
(
delete
)
{
os
.
write
(
b
,
0
,
length
);
}
if
(
delete
&&
file
.
exists
())
{
file
.
delete
();
FileUtils
.
deleteFile
(
filePath
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"下载文件失败"
,
e
);
}
finally
{
try
{
os
.
close
();
inputStream
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"close close fail "
,
e
);
}
}
}
public
String
setFileDownloadHeader
(
HttpServletRequest
request
,
String
fileName
)
throws
UnsupportedEncodingException
...
...
src/main/resources/ehcache/ehcache-shiro.xml
View file @
4d9c611a
...
...
@@ -23,47 +23,5 @@
statistics=
"true"
>
</cache>
<!-- 系统用户缓存 没必要过期 -->
<cache
name=
"sys-userCache"
maxEntriesLocalHeap=
"10000"
overflowToDisk=
"false"
eternal=
"false"
diskPersistent=
"false"
timeToLiveSeconds=
"0"
timeToIdleSeconds=
"0"
statistics=
"true"
/>
<!-- 系统用户授权缓存 没必要过期 -->
<cache
name=
"sys-authCache"
maxEntriesLocalHeap=
"10000"
overflowToDisk=
"false"
eternal=
"false"
diskPersistent=
"false"
timeToLiveSeconds=
"0"
timeToIdleSeconds=
"0"
memoryStoreEvictionPolicy=
"LRU"
statistics=
"true"
/>
<!-- 菜单缓存 没必要过期 -->
<cache
name=
"sys-menuCache"
maxEntriesLocalHeap=
"10000"
overflowToDisk=
"false"
eternal=
"false"
diskPersistent=
"false"
timeToLiveSeconds=
"0"
timeToIdleSeconds=
"0"
statistics=
"true"
/>
<!-- shiro 会话缓存 不需要序列化到磁盘 此处我们放到db中了 此处cache没必要过期 因为我们存放到db了 -->
<cache
name=
"shiro-activeSessionCache"
maxEntriesLocalHeap=
"10000"
overflowToDisk=
"false"
eternal=
"false"
diskPersistent=
"false"
timeToLiveSeconds=
"0"
timeToIdleSeconds=
"0"
statistics=
"true"
/>
</ehcache>
\ No newline at end of file
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