SpringBoot后台接收前台的字符串数据
时间:2019-04-04 17:40:08
收藏:0
阅读:211
需求
将前台传入的字符串数据转为int类型。
操作
不同于接收其他数据,接收String类型的数据,不可以直接@GetMapping(“/{rowId}”),需要使用RequestMapping。
这里ids传入的数据为ids={“1,2,3”…}
@RequestMapping(value = "/Ids/{Ids}", method = {RequestMethod.GET})
@ResponseBody
public R getByIds(@PathVariable("Ids") String ids) {
List<String> idsStringList = Arrays.asList(ids.split(","));
List<Integer> idsList = new ArrayList<>();
CollectionUtils.collect(idsStringList, new Transformer() {
public Object transform(Object o) {
return Integer.valueOf(o.toString());
}
}, idsList);
return new R<>(materialHouseService.listByIds(idsList));
}
最终输出的结果样式为int类型的1,2,3。
结果
postman测试结果正确,over。
原文:https://www.cnblogs.com/XYYCKL/p/10656063.html
评论(0)