import javax.ws.rs.PathParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/requestmapping")
public class RequestMappingController {
// http://localhost:8078/requestmapping/query1 null query success
// http://localhost:8078/requestmapping/query1?name=123 123 query success
@RequestMapping("/query1")
public String query1(String name) {
return name + " query success";
}
// http://localhost:8078/requestmapping/query2/name?name=123 123 query success
@RequestMapping("/query2/{name}")
public String query2(@PathParam(value = "name") String name) {
return name + " query success";
}
// http://localhost:8078/requestmapping/query3/123 123 query success
@RequestMapping("/query3/{name}")
public String query3(@PathVariable(value = "name") String name) {
return name + " query success";
}
// http://localhost:8078/requestmapping/query4?name=123 123 query success
@RequestMapping("/query4")
public String query4(@RequestParam(value = "name") String name) {
return name + " query success";
}
}
@RequestMapping=====使用====@PathParam、@PathVariable和@RequestParam
最新推荐文章于 2024-05-09 10:58:46 发布