# spring-mvc-json-xml-demo
**Repository Path**: coderdream/spring-mvc-json-xml-demo
## Basic Information
- **Project Name**: spring-mvc-json-xml-demo
- **Description**: spring-mvc-json-xml-demo
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 0
- **Created**: 2015-08-10
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
SpringMVC 中整合JSON、XML视图一
http://www.cnblogs.com/hoojo/archive/2011/04/29/2032571.html
SpringMVC 中整合JSON、XML视图二
http://www.cnblogs.com/hoojo/archive/2011/04/29/2032609.html
----------
## 七、 JSON-lib转换Java到JSON ##
http://localhost:8080/spring-mvc-json-xml-demo/jsonlib/view/doBeanJsonView
{
"account": {
"address": "北京",
"birthday": {
"birthday": "2010-11-22"
},
"email": "email",
"id": 1,
"name": "haha"
}
}
http://localhost:8080/spring-mvc-json-xml-demo/jsonlib/view/doMapJsonView
{
"hashMap": {
"success": true,
"user": {
"address": "china GuangZhou",
"age": 23,
"birthday": {
"date": 10,
"day": 1,
"hours": 14,
"minutes": 1,
"month": 7,
"seconds": 39,
"time": 1439186499277,
"timezoneOffset": -480,
"year": 115
},
"name": "jack",
"sex": true
}
},
"title": "ViewController doBeanJsonView"
}
http://localhost:8080/spring-mvc-json-xml-demo/jsonlib/view/doListJsonView
{
"userList": [
{
"address": "china GuangZhou#0",
"age": 23,
"birthday": {
"date": 10,
"day": 1,
"hours": 14,
"minutes": 4,
"month": 7,
"seconds": 6,
"time": 1439186646673,
"timezoneOffset": -480,
"year": 115
},
"name": "jack_0",
"sex": true
},
{
"address": "china GuangZhou#1",
"age": 24,
"birthday": {
"date": 10,
"day": 1,
"hours": 14,
"minutes": 4,
"month": 7,
"seconds": 6,
"time": 1439186646673,
"timezoneOffset": -480,
"year": 115
},
"name": "jack_1",
"sex": true
},
{
"address": "china GuangZhou#2",
"age": 25,
"birthday": {
"date": 10,
"day": 1,
"hours": 14,
"minutes": 4,
"month": 7,
"seconds": 6,
"time": 1439186646673,
"timezoneOffset": -480,
"year": 115
},
"name": "jack_2",
"sex": true
}
]
}
----------
## 六、 Jackson转换Java对象 ##
http://localhost:8080/spring-mvc-json-xml-demo/jackson/view/doBeanJsonView
{
"account" : {
"id" : 1,
"name" : "haha",
"email" : "email",
"address" : "北京",
"birthday" : {
"birthday" : "2010-11-22"
}
}
}
http://localhost:8080/spring-mvc-json-xml-demo/jackson/view/doMapJsonView
{
"hashMap" : {
"success" : true,
"user" : {
"name" : "jack",
"age" : 23,
"sex" : true,
"address" : "china GuangZhou",
"birthday" : 1439182082530
}
},
"title" : "ViewController doBeanJsonView"
}
http://localhost:8080/spring-mvc-json-xml-demo/jackson/view/doListJsonView
{
"userList" : [
{
"name" : "jack_0",
"age" : 23,
"sex" : true,
"address" : "china GuangZhou#0",
"birthday" : 1439182315879
},
{
"name" : "jack_1",
"age" : 24,
"sex" : true,
"address" : "china GuangZhou#1",
"birthday" : 1439182315879
},
{
"name" : "jack_2",
"age" : 25,
"sex" : true,
"address" : "china GuangZhou#2",
"birthday" : 1439182315879
}
]
}
----------
## 四、 用Castor转换XML ##
http://localhost:8080/spring-mvc-json-xml-demo/castor/view/doArrayXMLCastorView
haha#0
email0@120.com
address#0
<生日 birthday="2010-11-20"/>
haha#1
email1@121.com
address#1
<生日 birthday="2010-11-21"/>
china GuangZhou#
jack#
true
2015-08-07T14:52:27.120+08:00
http://localhost:8080/spring-mvc-json-xml-demo/castor/view/doListXMLCastorView
haha#0
email0@120.com
address#0
<生日 birthday="2010-11-20"/>
china GuangZhou# 0
jack#0
false
2015-08-07T14:48:12.615+08:00
haha#1
email1@121.com
address#1
<生日 birthday="2010-11-21"/>
china GuangZhou# 1
jack#1
false
2015-08-07T14:48:12.615+08:00
haha#2
email2@122.com
address#2
<生日 birthday="2010-11-22"/>
china GuangZhou# 2
jack#2
false
2015-08-07T14:48:12.615+08:00
http://localhost:8080/spring-mvc-json-xml-demo/castor/view/doMapXMLCastorView
http://localhost:8080/spring-mvc-json-xml-demo/castor/view/doBeanXMLCastorView
haha
email
北京
<生日 birthday="2010-11-22"/>
----------
## 三、 利用xStream转换XML ##
http://localhost:8080/spring-mvc-json-xml-demo/xStream/view/doMoreXMLXStream
1
haha
email
北京
2010-11-22
1
haha
email
上海
2010-11-22
http://localhost:8080/spring-mvc-json-xml-demo/xStream/view/doDifferXMLXStream
http://localhost:8080/spring-mvc-json-xml-demo/xStream/view/doListXMLXStream
1
haha#0
email0@120.com
北京#0
2010-11-20
jack#0
23
false
china GuangZhou 广州# 0
2015-08-10 06:36:57.245 UTC
2
haha#1
email1@121.com
北京#1
2010-11-21
jack#1
24
false
china GuangZhou 广州# 1
2015-08-10 06:36:57.245 UTC
3
haha#2
email2@122.com
北京#2
2010-11-22
jack#2
25
false
china GuangZhou 广州# 2
2015-08-10 06:36:57.245 UTC
----------
## 利用Jaxb2编组XML ##
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doListXMLXStream
1
haha#0
email0@120.com
北京#0
2010-11-20
china GuangZhou 广州# 0
23
2015-08-07 05:29:30.123 UTC
jack#0
false
2
haha#1
email1@121.com
北京#1
2010-11-21
china GuangZhou 广州# 1
24
2015-08-07 05:29:30.123 UTC
jack#1
false
3
haha#2
email2@122.com
北京#2
2010-11-22
china GuangZhou 广州# 2
25
2015-08-07 05:29:30.123 UTC
jack#2
false
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doDifferXMLXStream
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doMoreXMLXStream
1
haha
email
北京
2010-11-22
1
haha
email
上海
2010-11-22
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doMapXMLJaxb2
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doListXMLJaxb2
address#0
2010-11-20
email0@120.com
1
haha#0
china GuangZhou# 0
23
2015-08-07T12:38:32.191+08:00
jack#0
false
address#1
2010-11-21
email1@121.com
2
haha#1
china GuangZhou# 1
24
2015-08-07T12:38:32.191+08:00
jack#1
false
address#2
2010-11-22
email2@122.com
3
haha#2
china GuangZhou# 2
25
2015-08-07T12:38:32.191+08:00
jack#2
false
http://localhost:8080/spring-mvc-json-xml-demo/jaxb2/view/doXMLJaxb2
address
2010-11-22
email
1
haha
----------
Version 02:
Case 01:
http://localhost:8080/spring-mvc-json-xml-demo/getUserName?name=favccxx
Case 02:
http://localhost:8080/spring-mvc-json-xml-demo/getFavUserBody
{
"userId": "mm",
"userName": "女神",
"userAge": 18,
"createDate": "1998-08-08 18:18:18"
}
Case 03:
http://localhost:8080/spring-mvc-json-xml-demo/buildRestUser
{
"userId" : "mm",
"userName" : "美眉",
"userAge" : 18,
"createDate" : "2015-08-05 02:48:32"
}
----------
Version 01
http://localhost:8080/spring-mvc-json-xml-demo/greeting?name=%E7%BE%8E%E5%A5%B3
## 参考: ##
搭建Spring MVC 4开发环境八步走
http://favccxx.blog.51cto.com/2890523/1575885
使用Spring MVC 4构建Restful服务
http://favccxx.blog.51cto.com/2890523/1576730
使用Spring RestTemplate解析RESTful服务
http://favccxx.blog.51cto.com/2890523/1579305