首页>代码>SpringCloud微服务的项目架构搭建及Springboot应用实例>/demo/src/main/java/com/example/controller/UserController.java
package com.example.controller; import com.example.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @Author:qianjc * 2019/2/21 */ @RestController @RequestMapping("/testBoot") public class UserController { @Autowired private UserService userService; //@PathVariable 映射 URL 绑定的占位符 // 带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义 // 通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。 @RequestMapping("getUser/{id}") public String GetUser(@PathVariable int id){ return userService.Sel(id).toString(); } }