【学生信息管理】创建SpringBoot项目完成简单的接口访问---HHH

本文介绍了如何使用IDEA初始化SpringBoot项目,添加必要依赖,创建并测试一个简单的StudentController接口。通过这个过程,不仅可以复习SpringBoot的基础知识,也能提升动手实践能力。
摘要由CSDN通过智能技术生成

在这里插入图片描述

前言

开始我们的第一个系统Demo的开发吧,这是我第一次在CSDN上面写这种系列文章,其主要目呢就是回归自己之前所学,积累沉淀一下,同时也是希望能够帮助到小白朋友提升动手能力
开发这项工作本来就是偏工科,多动手才能看到一些实际的问题,所以让我们动起来吧!!!

操作

  1. 使用idea工具初始化一个SpringBoot 项目
    在这里插入图片描述
    !](https://img-blog.csdnimg.cn/6504004837a841a9be3243ca26c3d356.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA57qv5rSB6Zi_6L-Q,size_20,color_FFFFFF,t_70,g_se,x_16)
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  2. 使用maven 引用一些必要的依赖包

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

  1. 编写一个接口
    新建一个Student的Controller 类在这里插入图片描述
    编写测试代码
package com.example.stu.demo.controller;

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

/**
 * @ClassName StudentController
 * @Description TODO
 * @Author hhh
 * @Date 2021/11/22 14:55
 * @Version 1.0
 */
@RestController
@RequestMapping("/stu")
public class StudentController {


    @GetMapping("/{id}")
    public String byId(@PathVariable("id") Integer id){
        return new StringBuffer().append("ok").append(id).toString();
    }


}

  1. 来来来,我们测试一下吧
    这就说明我们的接口已经通了,成功接收到了返回数据
    在这里插入图片描述

总结

就是这样,是不是蛮简单的 嘻嘻嘻。动起手来 撸它!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

纯洁阿运

打赏我的都能暴富

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值