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
2f926f92
Commit
2f926f92
authored
May 31, 2019
by
fukai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化下载
parent
679dbc65
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
41 deletions
+39
-41
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+35
-41
spring-mvc.xml
src/main/resources/spring-mvc.xml
+4
-0
No files found.
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
2f926f92
...
...
@@ -2,20 +2,14 @@ package org.sss.presentation.noui.controller;
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.FileItem
;
import
org.apache.commons.fileupload.disk.DiskFileItemFactory
;
import
org.apache.commons.fileupload.servlet.ServletFileUpload
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IBaseObject
;
import
org.sss.common.model.IDatafield
;
...
...
@@ -37,7 +31,8 @@ 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
);
...
...
@@ -49,38 +44,37 @@ public class AbstractCommonController {
protected
static
String
ON_STREAM_DOWNLOAD
=
"ON_STREAM_DOWNLOAD"
;
@SuppressWarnings
(
"unchecked"
)
public
Object
event
(
String
mappingUrl
,
String
eventType
,
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
Object
event
(
String
mappingUrl
,
String
eventType
,
MultipartFile
file
,
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
NoUiContext
context
=
null
;
Result
ret
=
null
;
boolean
isMultipart
=
false
;
FileItem
lastFileItem
=
null
;
try
{
isMultipart
=
ServletFileUpload
.
isMultipartContent
(
request
);
if
(
isMultipart
)
{
ServletFileUpload
upload
=
new
ServletFileUpload
(
new
DiskFileItemFactory
());
// Parse the request
List
<
FileItem
>
items
=
upload
.
parseRequest
(
request
);
Iterator
<
FileItem
>
iter
=
items
.
iterator
();
while
(
iter
.
hasNext
())
{
FileItem
item
=
iter
.
next
();
// 普通表单域
if
(
item
.
isFormField
())
{
String
itemName
=
item
.
getFieldName
();
String
itemValue
=
item
.
getString
();
log
.
info
(
"文件表单 key:"
+
itemName
+
",Value:"
+
itemValue
);
// 给dataMap赋值
Map
<
String
,
?>
itemMap
=
new
Gson
().
fromJson
(
itemValue
,
Map
.
class
);
dataMap
.
put
(
itemName
,
itemMap
);
}
else
{
// 文件域
lastFileItem
=
item
;
}
}
}
else
{
log
.
info
(
"普通表单key-Value:"
+
dataMap
);
}
//
isMultipart = ServletFileUpload.isMultipartContent(request);
//
if (isMultipart) {
//
//
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
//
// Parse the request
//
List<FileItem> items = upload.parseRequest(request);
//
Iterator<FileItem> iter = items.iterator();
//
//
while (iter.hasNext()) {
//
FileItem item = iter.next();
//
// 普通表单域
//
if (item.isFormField()) {
//
String itemName = item.getFieldName();
//
String itemValue = item.getString();
//
log.info("文件表单 key:" + itemName + ",Value:" + itemValue);
//
// 给dataMap赋值
//
Map<String, ?> itemMap = new Gson().fromJson(itemValue, Map.class);
//
dataMap.put(itemName, itemMap);
//
} else { // 文件域
//
lastFileItem = item;
//
}
//
}
//
} else {
//
log.info("普通表单key-Value:" + dataMap);
//
}
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
mappingUrl
,
dataMap
);
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
Alias
alias
=
new
Alias
(
mappingUrl
);
...
...
@@ -117,14 +111,14 @@ public class AbstractCommonController {
((
IDatafield
<?>)
currentDataField
).
invokeCheckRules
(
context
);
}
}
}
else
if
(
eventType
.
equals
(
ON_STREAM_UPLOAD
)
&&
lastFileItem
!=
null
)
{
}
else
if
(
eventType
.
equals
(
ON_STREAM_UPLOAD
)
&&
file
!=
null
)
{
@SuppressWarnings
(
"rawtypes"
)
IDatafield
dataField
=
(
IDatafield
)
baseObject
(
context
,
noUiRequest
,
alias
);
IStream
stream
=
(
IStream
)
dataField
.
getValue
();
stream
.
setName
(
lastFileItem
.
getName
());
stream
.
setType
(
lastFileItem
.
getContentType
());
IOUtils
.
copy
(
lastFileItem
.
getInputStream
(),
stream
.
getOutputStream
(),
1024
);
// dataField.setValue(stream
);
stream
.
setName
(
file
.
getName
());
stream
.
setType
(
file
.
getContentType
());
log
.
info
(
"文件表单 key:"
+
file
.
getName
()
+
",size:"
+
file
.
getSize
()
);
IOUtils
.
copy
(
file
.
getInputStream
(),
stream
.
getOutputStream
(),
1024
);
dataField
.
invokeEventRules
(
context
,
EventType
.
ON_STREAM_UPLOAD
,
null
);
}
else
if
(
eventType
.
equals
(
ON_STREAM_DOWNLOAD
))
{
@SuppressWarnings
(
"rawtypes"
)
...
...
src/main/resources/spring-mvc.xml
View file @
2f926f92
...
...
@@ -26,6 +26,10 @@
<bean
class=
"org.sss.presentation.noui.jwt.TokenInterceptor"
></bean>
</mvc:interceptor>
</mvc:interceptors>
<bean
id=
"multipartResolver"
class=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
>
<property
name=
"maxUploadSize"
value=
"200000"
/>
<property
name=
"maxInMemorySize"
value=
"200000"
/>
</bean>
<!-- 配置自动扫描的包 -->
<context:component-scan
base-package=
"org.sss.presentation.noui.controller"
></context:component-scan>
...
...
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