开发获得cookie的Post登录接口
@RequestMapping(value = "/v1")
的作用是把这个value和方法上的登录地址进行拼接,比如:/v1/login
@RestController
标识该接口可以被托管
方法参数@RequestParam(value = "userName", required = true) String userName
,代码中的required = true
起到必填的作用
举个栗子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| @RestController @Api(value = "/", tags = {SwaggerConfig.TagPost}) @RequestMapping(value = "/v1") public class MyPostMethod {
private static 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("zhangsan") && password.equals("123456")){ cookie = new Cookie("login","true"); response.addCookie(cookie); return "恭喜你登录成功!"; } return "用户名或密码错误!";
}
|