http请求-json-路径参数-服务端接收

This commit is contained in:
2025-09-18 10:30:02 +08:00
parent cb31c17ce4
commit 1935eb352e

View File

@@ -2,9 +2,7 @@ package com.inmind.controller;
import com.inmind.pojo.User; import com.inmind.pojo.User;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -83,4 +81,19 @@ public class RequestController {
System.out.println(updateTime.getDayOfMonth()); System.out.println(updateTime.getDayOfMonth());
return "ok"; return "ok";
} }
//接收json请求数据
@RequestMapping("/jsonParam")
public String jsonParam(@RequestBody User user){
System.out.println(user);
return "OK";
}
//路径参数REST风格
@RequestMapping("/path/{id}/{name}")
public String pathParam(@PathVariable Integer id,@PathVariable String name) {
System.out.println("id:"+id+"name:"+name);
return "OK";
}
} }