Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nouiWithSpringMVC
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
gechengyang
nouiWithSpringMVC
Commits
e5aaeba2
Commit
e5aaeba2
authored
May 30, 2019
by
fukai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持上传
parent
fb1e153f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
28 deletions
+22
-28
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+22
-28
No files found.
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
e5aaeba2
package
org
.
sss
.
presentation
.
noui
.
controller
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.fileupload.FileItemIterator
;
import
org.apache.commons.fileupload.FileItemStream
;
import
org.apache.commons.fileupload.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.apache.commons.fileupload.util.Streams
;
import
org.apache.commons.io.IOUtils
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IBaseObject
;
...
...
@@ -39,6 +34,11 @@ import org.sss.presentation.noui.util.NoUiPresentationUtil;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
import
com.google.gson.Gson
;
import
log.Log
;
import
log.LogFactory
;
public
class
AbstractCommonController
{
protected
static
final
Log
log
=
LogFactory
.
getLog
(
AbstractCommonController
.
class
);
protected
static
String
ON_CLICK
=
"ON_CLICK"
;
...
...
@@ -53,25 +53,27 @@ public class AbstractCommonController {
NoUiContext
context
=
null
;
Result
ret
=
null
;
boolean
isMultipart
=
false
;
InputStream
fileStrea
m
=
null
;
FileItem
lastFileIte
m
=
null
;
try
{
isMultipart
=
ServletFileUpload
.
isMultipartContent
(
request
);
if
(
isMultipart
)
{
ServletFileUpload
upload
=
new
ServletFileUpload
();
ServletFileUpload
upload
=
new
ServletFileUpload
(
new
DiskFileItemFactory
()
);
// Parse the request
FileItemIterator
iter
=
upload
.
getItemIterator
(
request
);
List
<
FileItem
>
items
=
upload
.
parseRequest
(
request
);
Iterator
<
FileItem
>
iter
=
items
.
iterator
();
while
(
iter
.
hasNext
())
{
FileItemStream
item
=
iter
.
next
();
FileItem
item
=
iter
.
next
();
// 普通表单域
if
(
item
.
isFormField
())
{
String
itemName
=
item
.
getFieldName
();
String
itemValue
=
Streams
.
asString
(
item
.
openStream
()
);
String
itemValue
=
item
.
getString
(
);
// 给dataMap赋值
dataMap
.
put
(
itemName
,
itemValue
);
Map
<
String
,?>
itemMap
=
new
Gson
().
fromJson
(
itemValue
,
Map
.
class
);
dataMap
.
put
(
itemName
,
itemMap
);
}
else
{
// 文件域
fileStream
=
item
.
openStream
()
;
lastFileItem
=
item
;
}
}
...
...
@@ -112,23 +114,15 @@ public class AbstractCommonController {
((
IDatafield
<?>)
currentDataField
).
invokeCheckRules
(
context
);
}
}
}
else
if
(
eventType
.
equals
(
ON_STREAM_UPLOAD
))
{
}
else
if
(
eventType
.
equals
(
ON_STREAM_UPLOAD
)
&&
lastFileItem
!=
null
)
{
@SuppressWarnings
(
"rawtypes"
)
IDatafield
dataField
=
(
IDatafield
)
baseObject
(
context
,
noUiRequest
,
alias
);
IStream
stream
=
(
IStream
)
dataField
.
getValue
();
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
byte
[]
data
=
new
byte
[
1024
];
int
bytes
=
0
;
if
(
fileStream
!=
null
)
{
while
((
bytes
=
fileStream
.
read
(
data
))
!=
-
1
)
{
bos
.
write
(
data
,
0
,
bytes
);
}
IOUtils
.
write
(
bos
.
toByteArray
(),
stream
.
getOutputStream
());
IOUtils
.
closeQuietly
(
bos
);
}
stream
.
setName
(
lastFileItem
.
getName
());
stream
.
setType
(
lastFileItem
.
getContentType
());
IOUtils
.
copy
(
lastFileItem
.
getInputStream
(),
stream
.
getOutputStream
(),
1024
);
// dataField.setValue(stream);
dataField
.
invokeEventRules
(
context
,
EventType
.
ON_STREAM_UPLOAD
,
null
);
IOUtils
.
closeQuietly
(
fileStream
);
}
else
if
(
eventType
.
equals
(
ON_STREAM_DOWNLOAD
))
{
@SuppressWarnings
(
"rawtypes"
)
IDatafield
dataField
=
(
IDatafield
)
baseObject
(
context
,
noUiRequest
,
alias
);
...
...
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