Directory
Recently entered the Java Pit, learning Spring boot. Keep a record of the problems you are having.
Question One
Problem with request parameters
/get/bob
I want to getbob
@RequestMapping(value = "/get/{name}") public String GetName(@PathVariable String name){ return "Hello world "+name; }
/get/?name=alice
I want to get the value of namealice
Method One
@RequestMapping(value = "/get") public String GetName(@RequestParam String name){ return "Hello world "+name; }
Note: This notation enforces that name must have a value. If the URL is /get
, you get an error message: Name must be present
Method Two
@RequestMapping(value = "/get") public String GetName( String name){ return "Hello world "+name; }
Note: The name is not very large in the field. The request URL can be a /get
value of name, null
or it can be /get/?name=xxxx
.
Note
Spring Boot Url 是区分大小写的
Spring Boot Rookie Starter (continuous update)