Spring annotation (1) @RequestMapping @RequestParam @PathVariable

@RequestMapping maps HTTP requests to MVC and REST controller handlers

@RequestParam takes the value from the request request, such as the current request http://localhost:8080/springMVC/helloworld?a=1&b=2

public String test() {

    @RequestParam(name="a", required=true, defaultValue = "1")

    String abbbb;

}

There are four properties:

name The name of the parameter, which needs to be the same as the parameter name passed by the url

Whether the required parameter is required

alias for value name

defaultValue default value

@PathVariable takes the value from the URL, http://localhost:8080/springMVC/helloworld?a=1&b=2

@RequestMapping("/springMVC/{id}")

public String test(@PathVariable(value = "id") String name) {

    @RequestParam(name="a", required=true, defaultValue = "1")

    String abbbb;

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325401303&siteId=291194637