diff --git a/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java index 3721e5f..a72a807 100644 --- a/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java +++ b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java @@ -3,10 +3,7 @@ package com.inmind.controller; import com.inmind.pojo.User; import jakarta.servlet.http.HttpServletRequest; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; import java.util.Arrays; @@ -67,7 +64,7 @@ public class RequestController { return "OK"; } - //日期参数 + //json参数 @RequestMapping( "/jsonParam") //@RequestBody: 将请求体中的json数据,映射为java对象 public String jsonParam(@RequestBody User user){ @@ -75,4 +72,13 @@ public class RequestController { return "OK"; } + //路径参数 + @RequestMapping( "/path/{id}/{name}") + //@PathVariable: 将路径参数映射为方法参数 + public String pathParam(@PathVariable Integer id,@PathVariable String name){ + System.out.println("id:"+id); + System.out.println("name:"+name); + return "OK"; + } + }