Springboot概述以及用springboot搭建一个web工程

Springboot概述

什么是: Spring Boot是Spring项目中的一个子工程,与我们所熟知的Spring-framework 同属于spring的产品
作用:帮助开发人员快速的构建庞大的spring项目,并且尽可能的减少一切xml配置,做到开箱即用,迅速上手,让开发人员关注业务而非配置
设计目的:用来简化 Spring 应用的初始搭建以及开发过程
优点: 简单、快速、方便

用springboot搭建一个web工程

步骤

  1. 创建Maven工程
  2. 添加依赖(springboot父工程依赖 , web启动器依赖)
  3. 编写启动引导类(springboot项目运行的入口)
  4. 编写处理器Controller
  5. 启动项目

创建Maven工程
在这里插入图片描述
在这里插入图片描述
给pom添加依赖
1.springboot父工程依赖

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
 </parent>

2.web启动器依赖

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

3.配置jdk

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

编写启动引导类

package com.xxx;

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

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

编写controller

package com.xxx.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String sayHello(){
        return "hello spring boot!!" ;
    }
}

启动测试
运行启动类的main方法 :
在这里插入图片描述
控制台输出
在这里插入图片描述
通过输出的日志我们知道了以下信息 :
1.监听的端口是8080
2.项目的上下文路径是""
打开浏览器,访问:http://localhost:8080/hello
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值