springboot或springmvc传递复杂参数
2018-10-24 11:02
871 查看
本文使用的框架为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 }
相关文章推荐
- springboot 关于controller层传递单个参数的校验
- spring ajax前后端传递复杂参数
- springmvc 传递复杂对象参数报 property path is neither an array nor a List nor a Map
- [转载]SpringBoot系列: SpringMVC 参数绑定注解解析
- Spring MVC Ajax 复杂参数的批量传递
- 关于SpringBoot自定义注解(解决post接收String参数 null(前台传递json格式))
- SpringBoot中Rest风格接口传递多个参数
- SpringBoot入坑-请求参数传递
- SpringBoot 415状态参数传递问题
- SpringCloud使用feign时的复杂参数传递
- Spring Boot/VUE中路由传递参数的实现代码
- Spring cloud restTemplate 传递复杂参数的方式(多个对象)
- 第三十六章:基于SpringBoot架构重写SpringMVC请求参数装载
- springboot解决传递json字符串时获取某个参数为null
- springboot重写SpringMVC请求参数装载
- SpringBoot 参数传递与网页展现
- springMVC 参数传递之:数组,Map,List,Set以及自定义复杂类型参数
- SpringMVC或SpringBoot请求时间参数报错处理方法
- spring boot项目获取application配置文件参数的两种方式
- SpringMVC中,前台jsp封装参数,绑定参数,传递参数到后台controller的过程详解