【学习笔记】使用Springboot开发post接口

本文介绍了如何在Springboot中开发POST接口,并利用SwaggerUI生成接口文档。同时,详细阐述了Lombok库的使用,使得Java Bean无需手动编写getter和setter。此外,还讲解了通过JMeter验证接口及cookie的有效性的步骤,包括添加Debug Sampler和配置Cookie Manager。
摘要由CSDN通过智能技术生成
  1. 类似使用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");
        
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值