Spring mvc RESTful parameter transfer and URL calling method

Recently, I used spring cloud to develop a project, and I needed to provide an interface to the outside world. At the beginning of the test process, the postmen call was unsuccessful. Finally, I researched it and finally got it. To sum up:

Directly on the dry goods, see the code

@RestController
@RequestMapping("/col")
public class TestController{
@RequestMapping(value = "/test/{hello}/{name}")
public String test(@PathVariable("hello") String param,@PathVariable String name){
    System.out.println("==========================");
    return "say " + param+","+name;

} 

}

 

illustrate:

The two parameters of the test method are written slightly differently. The name of the first parameter can be written casually, but the second parameter must be the same as that defined in requestMapping, otherwise the parameter cannot be received:

Call URL in postman: http://127.0.0.1:8080/col/test/456/abc

 

 

 

Guess you like

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