最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpingMvc復(fù)雜參數(shù)傳收總結(jié)

 更新時間:2023年08月09日 14:16:08   作者:KenDoEverthing  
這篇文章主要為大家介紹了SpingMvc復(fù)雜參數(shù)傳收總結(jié),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

上一篇文章[javaWeb傳收參數(shù)方式總結(jié)]總結(jié)了簡單傳收參數(shù),這一篇講如何傳收復(fù)雜參數(shù)

比如Long[] 、User(bean里面包含List)、User[]、List<User><user style="margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word !important; box-sizing: border-box;">、List<Map<String,Object>等幾種復(fù)雜參數(shù)</user>。

簡單數(shù)組集合類

比如Long[],String[],List<User><long style="margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word !important; box-sizing: border-box;">等</long>

1.重復(fù)單個參數(shù)

前端

//(1)普通
http://localhost:8080/ajaxGet?id=1&id=2&id=3

//(2)Ajaxget方式 發(fā)送請求時等于(1)方式
    $.ajax({
        type: "GET",
        url: "http://localhost:8080/ajaxGet?id=1&id=2&id=3"
    });
//(3)Form表單GET方式 發(fā)送請求時等于(1)方式
<form id="fromGet" action="fromGet" method="GET">
    <input type="text"name="id" value="1">
    <input type="text"name="id" value="2">
    <input type="text"name="id" value="3">
</form>
//(4)Form表單POST方式 
//發(fā)送請求參數(shù)會被拼接成 id=1&id=2&id=3 存儲在請求體中
<form id="fromGet" action="fromGet" method="POST">
    <input type="text"name="id" value="1">
    <input type="text"name="id" value="2">
    <input type="text"name="id" value="3">
</form>

后端SpringMvc:

//數(shù)組
public void ajaxGet(Long[] id){
}
//List集合
public void ajaxGet(@RequestParam("id") List<Long> id){
}

2.數(shù)組參數(shù)

前端:

//(1)普通url
http://localhost:8080/ajaxGet?id[]=1&id[]=2&id[]=3

//2.Form GET方式(Ajax異步表單提交) 發(fā)送請求時等于(1)方式
$.ajax({
        type: "GET",
        url: "http://localhost:8080/ajaxGet",
        data: {"id":[1,2,3]},
        contentType:'application/x-www-form-urlencoded'
    });
//(3)Form POST方式(Ajax異步表單提交)
//發(fā)送請求參數(shù)會被拼接成 id[]=1&id[]=2&id[]=3 存儲在請求體中
$.ajax({
        type: "POST",
        url: "http://localhost:8080/ajaxPost",
        data: {"id":[1,2,3]},
        contentType:'application/x-www-form-urlencoded'
    });

后端SpringMvc:

//數(shù)組
public void ajaxGet(@RequestParam("id[]") Long[] id){
}
//List集合
public void ajaxGet(@RequestParam("id[]") List<Long> id){
}

其實以上兩種都是一個道理,主要是看發(fā)送請求時 參數(shù)是id還是id[](可使用瀏覽器的F12開發(fā)者工具查看network請求),來決定后端使不使用@RequestParam("id[]")進行數(shù)據(jù)綁定

復(fù)雜實體類與集合

比如User(bean里面包含List)、User[]、List<User><user style="margin: 0px; padding: 0px; max-width: 100%; overflow-wrap: break-word !important; box-sizing: border-box;">、List<Map<String,Object>等,此種類型均使用Json提交</user>

1.復(fù)雜實體類User

User實體類

//User實體類
public class User {  
    private String name;   
    private String pwd;  
    private List<User> customers;//屬于用戶的客戶群 
    //省略getter/setter  
}

前端:

//用戶
var user = {};
user.name = "李剛";
user.pwd = "888";
//客戶
var customerArray = new Array();
customerArray.push({name: "李四",pwd: "123"});
customerArray.push({name: "張三",pwd: "332"});
user. customers = customerArray;
$.ajax({
        type: "POST",
        url: "http://localhost:8080/ajaxPost",
        data: JSON.stringify(user),
        contentType:'application/json;charset=utf-8'
    });

后端SpringMvc:

public void ajaxPost(@ResponBody User user){
 }

前端:

//用戶
var userList = new Array();  
userList.push({name: "李四",pwd: "123"});   
userList.push({name: "張三",pwd: "332"});   
$.ajax({
        type: "POST",
        url: "http://localhost:8080/ajaxPost",
        data: JSON.stringify(userList),
        contentType:'application/json;charset=utf-8'
    });

后端SpringMvc:

public void ajaxPost(@ResponBody User[] user){
 }
public void ajaxPost(@ResponBody List<User> user){
 }
public void ajaxPost(@ResponBody List<Map<String,Object>> userMap){
 }

以上就是SpingMvc復(fù)雜參數(shù)傳收總結(jié)的詳細(xì)內(nèi)容,更多關(guān)于SpingMvc復(fù)雜參數(shù)傳收的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

泽库县| 连山| 阳信县| 应用必备| 丰原市| 天峻县| 县级市| 青铜峡市| 西华县| 西城区| 东至县| 普定县| 乐东| 滁州市| 临洮县| 闸北区| 大冶市| 临朐县| 东安县| 江津市| 新蔡县| 上饶县| 新建县| 安阳市| 沂源县| 黎城县| 通辽市| 乌兰县| 仙居县| 赤城县| 吴旗县| 古丈县| 封丘县| 朝阳市| 香港 | 阿拉善盟| 望城县| 龙山县| 芮城县| 红河县| 平利县|