javaEEday05-请求响应-请求-路径参数

This commit is contained in:
2026-05-13 10:42:27 +08:00
parent a3a0b4ce0d
commit b1221251bc

View File

@@ -3,10 +3,7 @@ package com.inmind.controller;
import com.inmind.pojo.User; import com.inmind.pojo.User;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
@@ -67,7 +64,7 @@ public class RequestController {
return "OK"; return "OK";
} }
//日期参数 //json参数
@RequestMapping( "/jsonParam") @RequestMapping( "/jsonParam")
//@RequestBody: 将请求体中的json数据映射为java对象 //@RequestBody: 将请求体中的json数据映射为java对象
public String jsonParam(@RequestBody User user){ public String jsonParam(@RequestBody User user){
@@ -75,4 +72,13 @@ public class RequestController {
return "OK"; 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";
}
} }