用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";
}

 

 

 

 

posted @ 2020-08-04 11:29  下饭  阅读(2065)  评论(0编辑  收藏  举报