Hello,Spring Boot

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhouxianling233/article/details/89304787

前言

长风破浪会有时,直挂云帆济沧海。----李白

介绍

Spring
Boot简化了Spring,是一个低配置的框架。并且提供管理Spring容器、第三方各种插件、通过starter来提供默认的各种系统服务等。

优点

  • 快速开发,开发体验一流;
  • 内置Tomcat;
  • jar包管理,自动装配技术;
  • 支持热加载;

Hello,Spring Boot

本节完成一个简单输出Hello ,Spring
Boot的例子。开始之前确保,安装了Java环境(我用的JDK8),开发工具(我用的idea)等。

  1. 打开idea,选择Create New Project,如图所示:

在这里插入图片描述
2. 选择Spring Initializr,点击Next,如图所示:
在这里插入图片描述
3. 填写项目相关信息,如图所示,直接点击Next
在这里插入图片描述
4. 勾选项目所需要依赖的服务,我们搭建的Web应用,必须添加spring-boot-starter-web,如图所示,点击Next:
在这里插入图片描述
5. 输入项目名称,点击Finish。
6. 项目结构介绍:
在这里插入图片描述
7. 项目启动类DemoApplication介绍:
在这里插入图片描述

package com.example.demo;//包路径

//导包
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication //该注解使其成为一个springboot应用
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
  1. 实现输出hello,Spring Boot,新建类HelloController,加入以下功能,重新启动项目。
package com.example.demo;

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

/**
* <p>
* </p>
*
* @author xianLing.zhou
* @since 2019/4/15
*/
@Controller //Spring MVC注解。表示用于负责Web请求
public class HelloController {

   @GetMapping("/hello.html")  //表示请求路径
   public @ResponseBody String hello(){
       return "Hello,Spring Boot";
   }
}
//@ResponseBody 表示返回的是文本而不是视图名称。

如图所示:

在这里插入图片描述
然后我们就可以在浏览器输入http://localhost:8080/hello.html
在这里插入图片描述

结尾

点击下载项目源码
到这里我们的一个springboot项目就算搭建成功了,大家有什么不明白和不清楚的欢迎留言。

猜你喜欢

转载自blog.csdn.net/zhouxianling233/article/details/89304787
今日推荐