• 用controller实现一个简单的post请求和get请求(并用postman测试)


    package  com.sundear.demo;

    import lombok.extern.slf4j.Slf4j;
    import org.springframework.web.bind.annotation.*;

    @RestController
    @Slf4j
    @RequestMapping("/datasync")
    public class testController {
    @PostMapping("/test")
    public String DatasyncMemberTest(@RequestBody(required = true) String id) {
    System.out.println(id);
    return "ceshi";
    }

    @GetMapping("/test2")
    public String testPage1(int id){
    System.out.println(id);
    return "成功";
    }

    @PostMapping("/servlet")
    public String DatasyncMemberTest2(HttpServletRequest request) {
    System.out.println(request.getParameter("name"));
    return "servlet";
    }


    }
    用postman测试如下:

     既有请求头又有请求体

     @GetMapping("/test3")
    public String testPage2(@RequestHeader int id,@RequestBody Info info){
    System.out.println(id);
    System.out.println(info.getName());
    return "成功";
    }

    有servlet 

    @PostMapping("/servlet")
    public String DatasyncMemberTest2(HttpServletRequest request,@RequestBody String id) {
    System.out.println(request.getHeader("name"));
    return "servlet";
    }
     
  • 相关阅读:
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业02
    C语言II博客作业04
    C语言II博客作业03
    C语言II博客作业02
    C语言II博客作业01
    学期总结
    C语言I博客作业08
  • 原文地址:https://www.cnblogs.com/yxj808/p/13432163.html
Copyright © 2020-2023  润新知