Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
53bc0505
Commit
53bc0505
authored
Jan 23, 2019
by
cjl
Browse files
createTime返回前端有时分秒,updateTime返回没有,有人对createTime做了特殊处理,在此处加上updateTime
parent
4744dee4
Changes
2
Hide whitespace changes
Inline
Side-by-side
erp_web/pages/manage/serialNumber.html
View file @
53bc0505
...
...
@@ -162,8 +162,8 @@
return
value
?
"
是
"
:
"
否
"
;
}
},
{
title
:
'
创建时间
'
,
field
:
'
createTime
'
,
width
:
70
},
{
title
:
'
更新时间
'
,
field
:
'
updateTime
'
,
width
:
70
},
{
title
:
'
创建时间
'
,
field
:
'
createTime
'
,
width
:
140
,
formatter
:
formatDatebox
},
{
title
:
'
更新时间
'
,
field
:
'
updateTime
'
,
width
:
140
,
formatter
:
formatDatebox
},
{
title
:
'
备注
'
,
field
:
'
remark
'
,
width
:
300
}
]],
toolbar
:
[
...
...
@@ -448,6 +448,40 @@
$
(
"
#searchBtn
"
).
click
();
}
});
/**时间格式化*/
Date
.
prototype
.
format
=
function
(
format
)
{
var
o
=
{
"
M+
"
:
this
.
getMonth
()
+
1
,
// month
"
d+
"
:
this
.
getDate
(),
// day
"
h+
"
:
this
.
getHours
(),
// hour
"
m+
"
:
this
.
getMinutes
(),
// minute
"
s+
"
:
this
.
getSeconds
(),
// second
"
q+
"
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// quarter
"
S
"
:
this
.
getMilliseconds
()
// millisecond
}
if
(
/
(
y+
)
/
.
test
(
format
))
format
=
format
.
replace
(
RegExp
.
$1
,
(
this
.
getFullYear
()
+
""
)
.
substr
(
4
-
RegExp
.
$1
.
length
));
for
(
var
k
in
o
)
if
(
new
RegExp
(
"
(
"
+
k
+
"
)
"
).
test
(
format
))
format
=
format
.
replace
(
RegExp
.
$1
,
RegExp
.
$1
.
length
==
1
?
o
[
k
]
:
(
"
00
"
+
o
[
k
]).
substr
((
""
+
o
[
k
]).
length
));
return
format
;
}
function
formatDatebox
(
value
)
{
if
(
value
==
null
||
value
==
''
)
{
return
''
;
}
var
dt
;
if
(
value
instanceof
Date
)
{
dt
=
value
;
}
else
{
dt
=
new
Date
(
value
);
}
return
dt
.
format
(
"
yyyy-MM-dd hh:mm:ss
"
);
//扩展的Date的format方法(上述插件实现)
}
</script>
</body>
</html>
src/main/java/com/jsh/erp/utils/ResponseJsonUtil.java
View file @
53bc0505
package
com.jsh.erp.utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.serializer.ValueFilter
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TimeZone
;
public
class
ResponseJsonUtil
{
public
static
final
SimpleDateFormat
FORMAT
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
static
{
FORMAT
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
}
/**
* 响应过滤器
*/
public
static
final
class
ResponseFilter
extends
ExtJsonUtils
.
ExtFilter
implements
ValueFilter
{
@Override
public
Object
process
(
Object
object
,
String
name
,
Object
value
)
{
if
(
name
.
equals
(
"createTime"
)
||
name
.
equals
(
"modifyTime"
))
{
return
value
;
}
else
if
(
value
instanceof
Date
)
{
return
FORMAT
.
format
(
value
);
}
else
{
return
value
;
}
}
}
/**
*
* @param responseCode
* @return
*/
public
static
String
backJson4HttpApi
(
ResponseCode
responseCode
)
{
if
(
responseCode
!=
null
)
{
String
result
=
JSON
.
toJSONString
(
responseCode
,
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
result
=
result
.
replaceFirst
(
"\"data\":\\{"
,
""
);
return
result
.
substring
(
0
,
result
.
length
()
-
1
);
}
return
null
;
}
/**
* 验证失败的json串
* @param code
* @return
*/
public
static
String
backJson4VerifyFailure
(
int
code
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"message"
,
"未通过验证"
);
return
JSON
.
toJSONString
(
new
ResponseCode
(
code
,
map
),
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
}
/**
* 成功的json串
* @param responseCode
* @return
*/
public
static
String
backJson
(
ResponseCode
responseCode
)
{
if
(
responseCode
!=
null
)
{
return
JSON
.
toJSONString
(
responseCode
,
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
}
return
null
;
}
public
static
String
returnJson
(
Map
<
String
,
Object
>
map
,
String
message
,
int
code
)
{
map
.
put
(
"message"
,
message
);
return
backJson
(
new
ResponseCode
(
code
,
map
));
}
}
package
com.jsh.erp.utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.serializer.ValueFilter
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TimeZone
;
public
class
ResponseJsonUtil
{
public
static
final
SimpleDateFormat
FORMAT
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
static
{
FORMAT
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
}
/**
* 响应过滤器
*/
public
static
final
class
ResponseFilter
extends
ExtJsonUtils
.
ExtFilter
implements
ValueFilter
{
@Override
public
Object
process
(
Object
object
,
String
name
,
Object
value
)
{
if
(
name
.
equals
(
"createTime"
)
||
name
.
equals
(
"modifyTime"
)
||
name
.
equals
(
"updateTime"
)
)
{
return
value
;
}
else
if
(
value
instanceof
Date
)
{
return
FORMAT
.
format
(
value
);
}
else
{
return
value
;
}
}
}
/**
*
* @param responseCode
* @return
*/
public
static
String
backJson4HttpApi
(
ResponseCode
responseCode
)
{
if
(
responseCode
!=
null
)
{
String
result
=
JSON
.
toJSONString
(
responseCode
,
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
result
=
result
.
replaceFirst
(
"\"data\":\\{"
,
""
);
return
result
.
substring
(
0
,
result
.
length
()
-
1
);
}
return
null
;
}
/**
* 验证失败的json串
* @param code
* @return
*/
public
static
String
backJson4VerifyFailure
(
int
code
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"message"
,
"未通过验证"
);
return
JSON
.
toJSONString
(
new
ResponseCode
(
code
,
map
),
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
}
/**
* 成功的json串
* @param responseCode
* @return
*/
public
static
String
backJson
(
ResponseCode
responseCode
)
{
if
(
responseCode
!=
null
)
{
return
JSON
.
toJSONString
(
responseCode
,
new
ResponseFilter
(),
SerializerFeature
.
DisableCircularReferenceDetect
,
SerializerFeature
.
WriteNonStringKeyAsString
);
}
return
null
;
}
public
static
String
returnJson
(
Map
<
String
,
Object
>
map
,
String
message
,
int
code
)
{
map
.
put
(
"message"
,
message
);
return
backJson
(
new
ResponseCode
(
code
,
map
));
}
}
Write
Preview
Supports
Markdown
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