从零开始搭建spring boot项目(1.新建spring boot项目)

首先使用idea新建一个maven项目,然后在pom.xml添加如下依赖

	<!--引入spring boot并设置版本-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>
    <dependencies>
        <!--开发web相关-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--springboot单元测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

然后编写启动类

/**
 *
 * @Author shiJb
 * @create 2020/10/29 10:09
 * @SpringBootApplication 开启了Spring的组件扫描和springboot的自动配置功能,相当于将以下三个注解组合在了一起
 * @Configuration 表名该类使用基于Java的配置,将此类作为配置类。
 * @ComponentScan 启用注解扫描。
 * @EnableAutoConfiguration 开启springboot的自动配置功能。
 */
@SpringBootApplication
public class SjbController {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SjbController.class, args);
    }

}

这样一个最基础的spring boot项目已经搭建好了,接下来我们编写一个欢迎页

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "<h1>Welcome to the world of shijinbo<h1>";
    }

}

然后我们启动刚才编写好的启动类来访问我们刚编写的欢迎页
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
至此,我们就搭建完成了一个最基础的spring boot项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值