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
c10662a1
Commit
c10662a1
authored
Dec 12, 2018
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复相关缺陷
parent
037558c4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
243 additions
and
109 deletions
+243
-109
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+130
-0
PxiController.java
...a/org/sss/presentation/noui/controller/PxiController.java
+15
-107
NoUiPresentationUtil.java
.../org/sss/presentation/noui/util/NoUiPresentationUtil.java
+17
-2
noUiMapping_pxiame.properties
src/main/resources/noUiMapping_pxiame.properties
+10
-0
HttpTest.java
.../java/org/sss/presentation/noui/api/servlet/HttpTest.java
+71
-0
No files found.
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
0 → 100644
View file @
c10662a1
package
org
.
sss
.
presentation
.
noui
.
controller
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
log.Log
;
import
log.LogFactory
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IBaseObject
;
import
org.sss.common.model.IDatafield
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.api.model.Alias
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
import
org.sss.presentation.noui.context.NoUiPresentation
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
public
class
AbstractCommonController
{
protected
static
final
Log
log
=
LogFactory
.
getLog
(
AbstractCommonController
.
class
);
protected
static
String
ON_CLICK
=
"ON_CLICK"
;
protected
static
String
INIT
=
"INIT"
;
protected
static
String
ON_CHANGE
=
"ON_CHANGE"
;
protected
static
String
ON_CHECK
=
"ON_CHECK"
;
public
Object
event
(
String
mappingUrl
,
String
eventType
,
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
mappingUrl
,
dataMap
);
NoUiContext
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
Alias
alias
=
new
Alias
(
mappingUrl
);
String
trnName
=
alias
.
getTrnName
();
// 交易参数赋值
Map
<
String
,
?>
paramsMap
=
noUiRequest
.
getParamsMap
();
for
(
String
key
:
paramsMap
.
keySet
())
{
context
.
getSession
().
storeData
(
key
,
paramsMap
.
get
(
key
));
}
// 设置old sysmod
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
NoUiPresentationUtil
.
setSysmod
(
context
,
(
byte
[])
redisLoginInfo
.
getSysmod
());
// 交易跳转
context
.
getSession
().
chain
(
true
,
trnName
);
try
{
// 模型赋值
NoUiPresentationUtil
.
hanleInput
(
context
,
noUiRequest
,
alias
);
// 不为初始化事件
if
(
eventType
!=
null
&&
(!
eventType
.
equals
(
INIT
)))
{
String
aliasActionUrl
=
alias
.
getAliasActionUrl
();
String
actionUrl
=
alias
.
getRel
().
get
(
aliasActionUrl
);
IBaseObject
dataField
=
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
actionUrl
);
if
(
null
==
dataField
)
throw
new
NoUiException
(
"onClickUrl :"
+
actionUrl
+
"is not exsit"
);
else
{
if
(
dataField
instanceof
IDatafield
)
if
(
eventType
.
equals
(
ON_CLICK
))
{
((
IDatafield
<?>)
dataField
).
invokeEventRules
(
context
,
EventType
.
ON_CLICK
,
null
);
}
else
if
(
eventType
.
equals
(
ON_CHANGE
))
{
((
IDatafield
<?>)
dataField
).
invokeEventRules
(
context
,
EventType
.
ON_CHANGE
,
null
);
}
else
if
(
eventType
.
equals
(
ON_CHECK
))
{
for
(
String
aliasKey
:
alias
.
getRel
().
keySet
())
{
if
(
aliasKey
.
startsWith
(
"_"
))
{
continue
;
}
String
realPath
=
alias
.
getRelPath
(
aliasKey
);
IBaseObject
currentDataField
=
(
IDatafield
<?>)
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
realPath
);
if
(
currentDataField
instanceof
IDatafield
<?>)
{
((
IDatafield
<?>)
currentDataField
).
invokeCheckRules
(
context
);
}
}
}
}
}
// 保存新的RedisLoginInfo
byte
[]
sysmodBytes
=
NoUiPresentationUtil
.
sysmodToBytes
(
context
);
redisLoginInfo
.
setSysmod
(
sysmodBytes
);
RedisUtil
.
set
(
StringUtil
.
userUniqueId
(
noUiRequest
),
redisLoginInfo
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
NoUiPresentationUtil
.
retMsg
(
context
),
handleReturnData
(
eventType
,
context
,
noUiRequest
,
alias
),
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
));
}
catch
(
Exception
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
}
return
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"提交处理异常"
,
null
);
}
private
Map
<
String
,
Object
>
handleReturnData
(
String
eventType
,
NoUiContext
context
,
NoUiRequest
request
,
Alias
alias
)
{
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
// 初始化事件
if
(
eventType
.
equals
(
INIT
))
{
for
(
String
aliasKey
:
alias
.
getRel
().
keySet
())
{
if
(
aliasKey
.
startsWith
(
"_"
))
{
continue
;
}
String
realPath
=
alias
.
getRelPath
(
aliasKey
);
IBaseObject
baseObject
=
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
realPath
);
data
.
put
(
aliasKey
,
NoUiPresentationUtil
.
handIBaseObject
(
context
,
baseObject
,
realPath
));
}
return
data
;
}
NoUiPresentation
gui
=
(
NoUiPresentation
)
context
.
getGui
();
Map
<
String
,
Object
>
modifyMap
=
gui
.
getModifyMap
();
for
(
Map
.
Entry
<
String
,
Object
>
modifyEntry
:
modifyMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
aliasEntry
:
alias
.
getRel
().
entrySet
())
{
String
aliasKey
=
aliasEntry
.
getKey
();
String
aliasPath
=
aliasEntry
.
getValue
();
if
(
aliasPath
.
startsWith
(
modifyEntry
.
getKey
()))
{
Object
val
=
modifyEntry
.
getValue
();
data
.
put
(
aliasKey
,
NoUiPresentationUtil
.
handIBaseObject
(
context
,
val
,
aliasEntry
.
getValue
()));
}
}
}
return
data
;
}
}
src/main/java/org/sss/presentation/noui/controller/PxiController.java
View file @
c10662a1
...
@@ -5,83 +5,28 @@ import java.util.Map;
...
@@ -5,83 +5,28 @@ import java.util.Map;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
log.Log
;
import
log.LogFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IDatafield
;
import
org.sss.presentation.noui.api.exception.NoUiException
;
import
org.sss.presentation.noui.api.model.Alias
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.util.NoUiPresentationUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
@Controller
@Controller
public
class
PxiController
{
public
class
PxiController
extends
AbstractCommonController
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
LoginController
.
class
);
// Event 事件
// Event 事件
@ResponseBody
@ResponseBody
@RequestMapping
(
value
=
"/pxiadd/_save"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/pxiadd/_save"
,
method
=
RequestMethod
.
POST
)
public
Object
save
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
public
Object
save
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
String
mappingUrl
=
"/pxiadd/_save"
;
String
mappingUrl
=
"/pxiadd/_save"
;
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
mappingUrl
,
dataMap
);
return
event
(
mappingUrl
,
ON_CLICK
,
dataMap
,
request
,
session
);
NoUiContext
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
Alias
alias
=
new
Alias
(
mappingUrl
);
String
trnName
=
alias
.
getTrnName
();
// 交易参数赋值
Map
<
String
,
?>
paramsMap
=
noUiRequest
.
getParamsMap
();
for
(
String
key
:
paramsMap
.
keySet
())
{
context
.
getSession
().
storeData
(
key
,
paramsMap
.
get
(
key
));
}
}
// 设置old sysmod
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
NoUiPresentationUtil
.
setSysmod
(
context
,
(
byte
[])
redisLoginInfo
.
getSysmod
());
// 交易跳转
context
.
getSession
().
chain
(
true
,
trnName
);
try
{
// 模型赋值
NoUiPresentationUtil
.
hanleInput
(
context
,
noUiRequest
,
alias
);
String
aliasActionUrl
=
alias
.
getAliasActionUrl
();
String
actionUrl
=
alias
.
getRel
().
get
(
aliasActionUrl
);
// context.getRoot().bindEvents(context);
IDatafield
<?>
dataField
=
(
IDatafield
<?>)
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
actionUrl
);
// OnChange 事件
if
(
null
==
dataField
)
@ResponseBody
throw
new
NoUiException
(
"onClickUrl :"
+
actionUrl
+
"is not exsit"
);
@RequestMapping
(
value
=
"/pxiadd/_onchange"
,
method
=
RequestMethod
.
POST
)
else
{
public
Object
onchange
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
if
(
dataField
instanceof
IDatafield
)
String
mappingUrl
=
"/pxiadd/_onchange"
;
((
IDatafield
<?>)
dataField
).
invokeEventRules
(
context
,
EventType
.
ON_CLICK
,
null
);
return
event
(
mappingUrl
,
ON_CHANGE
,
dataMap
,
request
,
session
);
}
// 保存新的RedisLoginInfo
byte
[]
sysmodBytes
=
NoUiPresentationUtil
.
sysmodToBytes
(
context
);
// IBaseObject sysmod =
// context.getSession().getBaseObject(context.getRoot(), "sysmod");
redisLoginInfo
.
setSysmod
(
sysmodBytes
);
RedisUtil
.
set
(
StringUtil
.
userUniqueId
(
noUiRequest
),
redisLoginInfo
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
NoUiPresentationUtil
.
retMsg
(
context
),
NoUiPresentationUtil
.
handleEventReturnData
(
context
,
noUiRequest
,
alias
),
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
));
}
catch
(
Exception
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
}
return
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"提交处理异常"
,
null
);
}
}
// Event 事件
// Event 事件
...
@@ -89,51 +34,14 @@ public class PxiController {
...
@@ -89,51 +34,14 @@ public class PxiController {
@RequestMapping
(
value
=
"/pxisel/_sel"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/pxisel/_sel"
,
method
=
RequestMethod
.
POST
)
public
Object
sel
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
public
Object
sel
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
String
mappingUrl
=
"/pxisel/_sel"
;
String
mappingUrl
=
"/pxisel/_sel"
;
NoUiRequest
noUiRequest
=
new
NoUiRequest
(
request
,
mappingUrl
,
dataMap
);
return
event
(
mappingUrl
,
ON_CLICK
,
dataMap
,
request
,
session
);
NoUiContext
context
=
NoUiContextManager
.
createNoUiContext
(
noUiRequest
);
Alias
alias
=
new
Alias
(
mappingUrl
);
String
trnName
=
alias
.
getTrnName
();
// 交易参数赋值
Map
<
String
,
?>
paramsMap
=
noUiRequest
.
getParamsMap
();
for
(
String
key
:
paramsMap
.
keySet
())
{
context
.
getSession
().
storeData
(
key
,
paramsMap
.
get
(
key
));
}
}
// 设置old sysmod
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
NoUiPresentationUtil
.
setSysmod
(
context
,
(
byte
[])
redisLoginInfo
.
getSysmod
());
// 交易跳转
context
.
getSession
().
chain
(
true
,
trnName
);
try
{
// 模型赋值
NoUiPresentationUtil
.
hanleInput
(
context
,
noUiRequest
,
alias
);
String
aliasActionUrl
=
alias
.
getAliasActionUrl
();
String
actionUrl
=
alias
.
getRel
().
get
(
aliasActionUrl
);
// context.getRoot().bindEvents(context);
// 初始化 事件
@ResponseBody
IDatafield
<?>
dataField
=
(
IDatafield
<?>)
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
actionUrl
);
@RequestMapping
(
value
=
"/pxiame/init"
,
method
=
RequestMethod
.
POST
)
if
(
null
==
dataField
)
public
Object
ame
(
@RequestBody
Map
<
String
,
Object
>
dataMap
,
HttpServletRequest
request
,
HttpSession
session
)
{
throw
new
NoUiException
(
"onClickUrl :"
+
actionUrl
+
"is not exsit"
);
String
mappingUrl
=
"/pxiame/init"
;
else
{
return
event
(
mappingUrl
,
INIT
,
dataMap
,
request
,
session
);
if
(
dataField
instanceof
IDatafield
)
((
IDatafield
<?>)
dataField
).
invokeEventRules
(
context
,
EventType
.
ON_CLICK
,
null
);
}
// 保存新的RedisLoginInfo
byte
[]
sysmodBytes
=
NoUiPresentationUtil
.
sysmodToBytes
(
context
);
// IBaseObject sysmod =
// context.getSession().getBaseObject(context.getRoot(), "sysmod");
redisLoginInfo
.
setSysmod
(
sysmodBytes
);
RedisUtil
.
set
(
StringUtil
.
userUniqueId
(
noUiRequest
),
redisLoginInfo
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
NoUiPresentationUtil
.
retMsg
(
context
),
NoUiPresentationUtil
.
handleEventReturnData
(
context
,
noUiRequest
,
alias
),
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
));
}
catch
(
Exception
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
}
return
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"提交处理异常"
,
null
);
}
}
}
}
src/main/java/org/sss/presentation/noui/util/NoUiPresentationUtil.java
View file @
c10662a1
...
@@ -18,6 +18,7 @@ import log.LogFactory;
...
@@ -18,6 +18,7 @@ import log.LogFactory;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.sss.common.impl.StreamImpl
;
import
org.sss.common.impl.StreamImpl
;
import
org.sss.common.model.EventType
;
import
org.sss.common.model.IBaseObject
;
import
org.sss.common.model.IBaseObject
;
import
org.sss.common.model.IContext
;
import
org.sss.common.model.IContext
;
import
org.sss.common.model.IDatafield
;
import
org.sss.common.model.IDatafield
;
...
@@ -164,8 +165,22 @@ public class NoUiPresentationUtil {
...
@@ -164,8 +165,22 @@ public class NoUiPresentationUtil {
return
StringUtil
.
isEmpty
(
gui
.
getMessage
())
?
ErrorCodes
.
SUCCESS_INFO
:
gui
.
getMessage
();
return
StringUtil
.
isEmpty
(
gui
.
getMessage
())
?
ErrorCodes
.
SUCCESS_INFO
:
gui
.
getMessage
();
}
}
public
static
Map
<
String
,
Object
>
handleEventReturnData
(
NoUiContext
context
,
NoUiRequest
request
,
Alias
alias
)
{
public
static
Map
<
String
,
Object
>
handleEventReturnData
(
EventType
eventType
,
NoUiContext
context
,
NoUiRequest
request
,
Alias
alias
)
{
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
// 初始化事件
if
(
eventType
==
null
)
{
for
(
String
aliasKey
:
alias
.
getRel
().
keySet
())
{
if
(
aliasKey
.
startsWith
(
"_"
))
{
continue
;
}
String
realPath
=
alias
.
getRelPath
(
aliasKey
);
IBaseObject
baseObject
=
context
.
getSession
().
getBaseObject
(
context
.
getRoot
(),
realPath
);
data
.
put
(
aliasKey
,
NoUiPresentationUtil
.
handIBaseObject
(
context
,
baseObject
,
realPath
));
}
return
data
;
}
NoUiPresentation
gui
=
(
NoUiPresentation
)
context
.
getGui
();
NoUiPresentation
gui
=
(
NoUiPresentation
)
context
.
getGui
();
Map
<
String
,
Object
>
modifyMap
=
gui
.
getModifyMap
();
Map
<
String
,
Object
>
modifyMap
=
gui
.
getModifyMap
();
for
(
Map
.
Entry
<
String
,
Object
>
modifyEntry
:
modifyMap
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Object
>
modifyEntry
:
modifyMap
.
entrySet
())
{
...
@@ -182,7 +197,7 @@ public class NoUiPresentationUtil {
...
@@ -182,7 +197,7 @@ public class NoUiPresentationUtil {
return
data
;
return
data
;
}
}
p
rivate
static
Object
handIBaseObject
(
NoUiContext
context
,
Object
val
,
String
path
)
{
p
ublic
static
Object
handIBaseObject
(
NoUiContext
context
,
Object
val
,
String
path
)
{
if
(
val
==
null
)
if
(
val
==
null
)
return
null
;
return
null
;
if
(
val
instanceof
IModuleList
<?>)
{
if
(
val
instanceof
IModuleList
<?>)
{
...
...
src/main/resources/noUiMapping_pxiame.properties
0 → 100644
View file @
c10662a1
_save
=
\\
pxip
\\
sav
nam
=
\\
pxigrp
\\
rec
\\
nam
sex
=
\\
pxigrp
\\
rec
\\
sex
univer
=
\\
pxigrp
\\
rec
\\
univer
major
=
\\
pxigrp
\\
rec
\\
major
tel
=
\\
pxigrp
\\
rec
\\
tel
headimg
=
\\
pxigrp
\\
rec
\\
headimg
age
=
\\
pxigrp
\\
rec
\\
age
balance
=
\\
pxigrp
\\
rec
\\
balance
\ No newline at end of file
src/test/java/org/sss/presentation/noui/api/servlet/HttpTest.java
View file @
c10662a1
...
@@ -22,6 +22,7 @@ public class HttpTest {
...
@@ -22,6 +22,7 @@ public class HttpTest {
pxiadd
(
token
,
userId
,
terminalType
);
pxiadd
(
token
,
userId
,
terminalType
);
pxisel
(
token
,
userId
,
terminalType
);
pxisel
(
token
,
userId
,
terminalType
);
pxiame
(
token
,
userId
,
terminalType
);
}
}
...
@@ -95,6 +96,76 @@ public class HttpTest {
...
@@ -95,6 +96,76 @@ public class HttpTest {
System
.
out
.
println
(
"result="
+
result
);
System
.
out
.
println
(
"result="
+
result
);
}
}
public
static
void
pxiame
(
String
token
,
String
userId
,
String
terminalType
)
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
String
result
=
""
;
try
{
// "http://172.17.2.100:8080/oauth/token?username=user_1&password=123456&grant_type=password&client_id=client&client_secret=123456"
URL
realUrl
=
new
URL
(
"http://localhost:8080/business/service/pxiame/init"
);
// URL realUrl = new
// URL("http://localhost:8080/healthServer/getMacSeq");
// 打开和URL之间的连接
URLConnection
conn
=
realUrl
.
openConnection
();
// 设置通用的请求属性
conn
.
setRequestProperty
(
"accept"
,
"application/json"
);
conn
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json;charset=utf-8"
);
conn
.
addRequestProperty
(
"token"
,
token
);
conn
.
addRequestProperty
(
"userId"
,
userId
);
conn
.
addRequestProperty
(
"terminalType"
,
terminalType
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"pxiinr"
,
"00000023"
);
/*
* map.put("sex", "F"); map.put("univer", "湖北大学"); map.put("major",
* "计算机"); map.put("headimg", "NO IMAGE"); map.put("age", 20);
* map.put("tel", "18912345678"); map.put("balance", 10000);
*/
Map
<
String
,
Object
>
map2
=
new
HashMap
<
String
,
Object
>();
map2
.
put
(
"params"
,
map
);
// System.out.println(JSON.toJSON(student));
out
.
print
(
new
Gson
().
toJson
(
map2
));
// out.print("abc");
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送 POST 请求出现异常!"
+
e
);
e
.
printStackTrace
();
}
// 使用finally块来关闭输出流、输入流
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
}
System
.
out
.
println
(
"result="
+
result
);
}
public
static
void
pxiadd
(
String
token
,
String
userId
,
String
terminalType
)
{
public
static
void
pxiadd
(
String
token
,
String
userId
,
String
terminalType
)
{
PrintWriter
out
=
null
;
PrintWriter
out
=
null
;
...
...
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