写一个简单的兼容GET/POST请求的登录接口

安装JDK17

参考:https://blog.csdn.net/tiehou/article/details/129575138

安装或者更新Intelij Idea 2024

安装2024版本,可以少很多bug。

第一次下载安装,参考: 2024最新版IntelliJ IDEA安装使用指南

旧版Intelij Idea 更新到2024,参考: IntelliJ IDEA 直接在软件中更新为最新版

SpringBoot生成项目压缩包

打开https://start.spring.io/,具体配置参考:https://www.bilibili.com/video/BV1uB4y1a7XZ/

下载maven,idea添加maven

参考Intellij IDEA 2021 Maven 配置指南

写POST接口

参考:https://www.bilibili.com/video/BV1uB4y1a7XZ/

同时支持GET/POST的代码:


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/login")
    @PostMapping
    @GetMapping
    public String login(String name,String password){
        if (name == null || password == null) {
            return "fail";
        }else if(name.equals("zj")&&password.equals("123456")){
            return "success";
        }else {
            return "message error";
        }
    }

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }
}

浏览器访问GET接口

如果浏览器输入127.0.0.1访问不了,参考:127.0.0.1 拒绝了我们的连接请求–访问本地IP时显示拒绝访问

PostMan安装及访问POST接口

参考:Postman下载安装使用

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值