å¯ä»¥ç
å¨webç¨åºå¼åä¸ï¼å端åæå¡å¨æ°æ®çä¼ è¾æ¹å¼å¸¸ç¨çæ两ç§ï¼ä¸ç§æ¯ä»¥è¡¨åçå½¢å¼æ交ï¼æ¤æ¶å¯ä»¥å©ç¨jqueryçserialize()æ¹æ³å°è¡¨åå
容转为a=1&b=2&c=3&d=4&e=5è¿æ ·çæ ¼å¼ä¼ è¾è¿å»ï¼æ¥æ¶ç«¯åå¯ä»¥ç¨javabeanç´æ¥æ¥æ¶ã
è¿æä¸ç§æ¹å¼æ¯ä»¥jsonæ ¼å¼ä¼ è¾ï¼æ¥æ¶æ¶è¥ç´æ¥ç¨beanæ¥æ¶åæ¥æ¶ä¸å°ï¼æ¤æ¶åºè¯¥ç¨@RequestBodyæ¹å¼ï¼éè¦æ³¨æçæ¯æ¥æ¶çéè¦æ¯json串ï¼èä¸æ¯json对象ï¼å¯ä»¥å¨åéå使ç¨JSON.stringifyå½æ°è¿è¡å¤çã
ä¾åå¦ä¸
客æ·ç«¯ï¼
var url=path+'testConverter.html';
$.ajax(
{
url :
url,
type :
"POST",
dataType:"json",
contentType:'application/json;charset=UTF-8',
data:JSON.stringify({userId:'1',userName:'hello',password:'test',credits:'2',lastIp:'',lastVisit:'1986-05-27'}),
success :
function(data) {
alert(data.userName);
},
error:function(e){
alert("err");
}
æå¡ç«¯ï¼
@RequestMapping(value="/testConverter.html")
@ResponseBody
public User
testConverter(@RequestBody User user)
{
System.out.println(user.getUserName());
user.setUserName("testname");
return
user;
}
ä¸é¢ä¾åä¸æå¡ç«¯è¿åçæ¯ä¸ªå¯¹è±¡ï¼@ResponseBodyå½æ°ä¼èªå¨å°å
¶è½¬æ¢ä¸ºå®¢æ·ç«¯è¦æ±çâ
dataType:"json",âæ ¼å¼ã
æåéè¦æ³¨æçæ¯
1,å¨xxx-serverleté
ç½®æ件ä¸åºè¯¥åä¸ï¼ä»¥ä¾¿å¯ä»¥ä½¿ç¨
@ResponseBodyå@RequestBody
2,åéæ¶è¦åä¸ contentType:'application/json'
3,æ°ç»å
容è¦ç¨[]èä¸æ¯listï¼ç¨listä¼æ¥æ¶å°ä¸ä¸ªmap对象ï¼èä¸æ¯bean
温馨提示:内容为网友见解,仅供参考