SpringMVC接收Get请求参数

直接传参

http://localhost:8081/us/123

用@PathVariable 配合参数接收

	@RequestMapping("/us/{id}")
	@ResponseBody
	public String submitForm(@PathVariable(value = "id") String id) {
		System.out.println("str=" + id);
		return "提交成功";
	}

使用问号( ? ) 拼接传参

http://localhost:8081/us?name=nazha&age=18

用@RequestParam(value = “name”)接收参数,value的值为url 问号( ? )后参数的key值

	@RequestMapping("/us")
	@ResponseBody
	public String submitForm(@RequestParam(value = "name") String name
			, @RequestParam(value = "age")Integer age ) {
		System.out.println("str=" + name);
		System.out.println("age=" + age);
		return "提交成功";
	}

你可能感兴趣的:(java,url)