springboot-helloworld

用idea搭建springboot

1、首先先配置好maven

链接:https://editor.csdn.net/md/?articleId=109404762

2、创建项目,选择maven

在这里插入图片描述
右下角,next

3、然后就是取名,项目位置

在这里插入图片描述

然后就是finish了

4、修改pom.xml

在这里插入图片描述
要添加springboot,

也可以看spring boot官网链接
https://spring.io/guides/gs/rest-service/

复制下面的,注意spring-boot-starter-parent的version和Java的version

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <name>rest-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>   
        </plugins>
    </build>

复制好后,要下载导入包,需要时间。

在这里插入图片描述

5、创建main类(我的是test)和hello类

在这里插入图片描述

main类:

package com.nineManagement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class test {
    public static void main(String[] args) {
        SpringApplication.run(test.class, args);
    }
}

hello类:

package com.nineManagement.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class Hello {

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

6、最后就是启动spring了

右上角,三角形运行,不行就进入main类右键run
在这里插入图片描述

稍等,好了之后,进入浏览器
localhost:8080

然后在后面加hello
localhost:8080/hello

就有输出了
在这里插入图片描述

至于里面的原理,就自行学spring和spring boot等等。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值