Java后端接收Get、Post方式传值


Get方式传递数组与集合, Java后端接收

  1. Get方式传递
/**
 * @param Integer[] ids or List<Integer> list
 * @author code.Map
 * @version 创建时间:2021年3月9日 下午10:02:24
 * 请求地址: http://localhost:8888/Company/GetTransmit?list=4&list=2
 * 返回参数: [4,2]
 */
@GetMapping("/GetTransmit")
@ResponseBody
public List<Integer> GetTransmit(@RequestParam List<Integer> list) {
	List<Integer> varList = new ArrayList<>();
	if (null != list) {
		list.forEach(key -> varList.add(key));
		return varList;
	}
	return varList;
}

  1. Post方式传递, Java后端接收
/**
 * @param MapVo mapVo
 * @author code.Map
 * @version 创建时间:2021年3月9日 下午10:12:58
 * 请求地址: http://localhost:8888/Company/PostTransmit {"list": [2,4]}
 * 返回参数: [2,4]
 */
@PostMapping("/PostTransmit")
@ResponseBody
public List<Integer> PostTransmit(@RequestBody MapVo mapVo) {
	List<Integer> varList = new ArrayList<>();
	if (null != mapVo.getList()) {
		mapVo.getList().forEach(key -> varList.add(key));
		return varList;
	}
	return varList;
}

2.1 Post入参封装对象

// 对象入参
class MapVo {
	private List<Integer> list;

	public List<Integer> getList() {
		return list;
	}

	public void setList(List<Integer> list) {
		this.list = list;
	}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM