GET
请求 默认的
Content-Type = "application/x-www-form-urlencoded"
所以 当Spring 使用
@RequestMapping(value = "/pets", method=RequestMethod.GET,consumes = "application/x-www-form-urlencoded")
//进行注解时不会返回415 错误[UNSUPPORTED_MEDIA_TYPE]。参数直接放在方法里
@RequestMapping(value = "/pets", method =RequestMethod.GET,consumes = "application/x-www-form-urlencoded" )
public void getPet(String id, Model model) {
System.out.println(id);
}
//请求参数 localhost:8080/pets?id=1
//打印结果 1-
含有参数的对象放在方法里
@RequestMapping(value = "/pets", method =RequestMethod.GET,consumes = "application/x-www-form-urlencoded" ) public void getPet(PetForm dataForm, Model model) { System.out.println(dataForm.getId()); } //请求参数 localhost:8080/pets?id=1 //打印结果 1