- 类似使用springboot开发get接口, 创建post接口如下:
package com.gracie.server;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
@RestController
@Api(value="/", description = "这是我全部的post请求")
@RequestMapping("/V1") //此处的注释的作用是:需要在后续的所有的方法前加/V1
public class MyPostMethod {
//此变量用来装我们的cookie信息
private static Cookie cookie;
//用户登录成功获取到cookie信息,再访问其他接口获取到列表
@RequestMapping(value="/login", method = RequestMethod.POST)
@ApiOperation(value="登录接口, 成功后获取cookies信息", httpMethod = "POST")
public String login(HttpServletResponse response,
@RequestParam(value="userName", required = true) String username,
@RequestParam(value="passWord", required = true) String password){
if(username.equals("gracie")&& password.equals("123456")){
cookie=new Cookie("login", "success");