自学内容网 自学内容网

写一个简单的兼容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下载安装使用


原文地址:https://blog.csdn.net/zhangjin1120/article/details/140385916

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!