springboot或springmvc传递复杂参数

本文使用的框架为springboot-2.0.4.RELEASE版本

1、传递List<实体类>

@PostMapping("/test")
public DataWrapper test(@RequestBody List<Jwt> jwts){
   return success(jwts);
}

这里使用的注解为@RequestBody、使用该注解、前台发送请求时的Content-Type应该为:application/json类型、否则可能会接受不到参数

let jwt = [];//声明一个数组
jwt.push({scope:'1111'});//加入数组中
jwt.push({scope:'1111'});//加入数组中
jwt.push({scope:'1111'});//加入数组中
$.ajax({
	url:'xxxxx',
	Content-Type:'application/json;charset=UTF-8',
	data:jwt,//jwt 作为参数传递、也就是个List<jwt>类型
	//其他的省略
});

2、传递list<常规类型>如String、int等类型

@PostMapping("/test")
public DataWrapper test(@RequestParam List<Integer> ids,@RequestParam type){
    return success(ids);
}

这里使用@RequestParam注解、Content-Type为application/x-www-form-urlencoded即可、至于其他的我没试、以下是js代码的一个小片段

let ids = new Array();//这是数组
for (var i = 0; i < length; i++) {
   ids.push(datas[i].id);
}
//这个是请求参数、请求为json类型、其中ids为数组类型、转换到后台也就是List<int>或者int[]
//剩下的发送请求等等省略      
let data = {
  'ids':ids,
  'type':type
}        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值