一、环境

1.1、Idea 2020.1

1.2、JDK 1.8

二、目的

初识Spring Boot

三、步骤

3.1、点击File -> New Project -> Spring Initializer,点击next

 

3.2、在对应地方修改自己的项目信息

3.3、修改后如下,点击next

3.4、选择Web依赖,选中Spring Web。可以选择Spring Boot版本,本次默认为2.2.6,点击Next

3.5、编辑工程名和项目路径,确定后点击Finish完成

 

3.6、完成新建工程

 

四、代码分析

 

4.1、运行项目 执行SpringBootBeginHelloApplication下的main方法

 

4.2、测试运行

浏览器访问
 
显示结果如下,表示该web项目正常启动

4.3、新增测试接口

新建包controller,然后建立HelloController类,具体代码如下:
 package org.ouyushan.springboot.begin.controller;

 import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; /**
* @Description
* @Author ouyushan
* @Email ouyushan@hotmail.com
* @Date 2020/4/27
*/ @RestController
@RequestMapping("/springboot")
public class HelloController { @GetMapping("/hello")
public String hello() {
return "Hello,Spring Boot!";
} }

4.4、新接口测试

再次启动程序后浏览器访问:
 
接口请求返回如下:
 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.ouyushan</groupId>
<artifactId>spring-boot-begin-hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-begin-hello</name>
<description>Hello project for Spring Boot</description> <!--指定jdk版本-->
<properties>
<java.version>1.8</java.version>
</properties> <dependencies>
<!--指定spring boot web依赖-->
<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> </project>

五、知识点

5.1、spring boot 项目可通过以下方式指定jdk版本

     <!--指定jdk版本-->
<properties>
<java.version>1.8</java.version>
</properties>

5.2、spring boot 端口默认是8080

Spring boot Sample 001之spring-boot-begin-hello的更多相关文章

  1. Spring boot Sample 012之spring-boot-web-upload

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合web实现文件上传下载 三.步骤 3.1.点击File -> New Project -& ...

  2. Spring boot Sample 0010之spring-boot-web-freemarker

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合freemarker模板开发web项目 三.步骤 3.1.点击File -> New Pr ...

  3. Spring boot Sample 009之spring-boot-web-thymeleaf

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合thymeleaf模板开发web项目 三.步骤 3.1.点击File -> New Pro ...

  4. Spring boot Sample 006之spring-boot-custom-servlet

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.步骤 2.1.点击File -> New Project -> Spring Initializer,点击next 2 ...

  5. Spring boot Sample 005之spring-boot-profile

    一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 通过yaml文件配置spring boot 属性文件 三.步骤 3.1.点击File -> New Project - ...

  6. Spring Boot (五)Spring Data JPA 操作 MySQL 8

    一.Spring Data JPA 介绍 JPA(Java Persistence API)Java持久化API,是 Java 持久化的标准规范,Hibernate是持久化规范的技术实现,而Sprin ...

  7. Spring 5.x 、Spring Boot 2.x 、Spring Cloud 与常用技术栈整合

    项目 GitHub 地址:https://github.com/heibaiying/spring-samples-for-all 版本说明: Spring: 5.1.3.RELEASE Spring ...

  8. spring cloud教程之使用spring boot创建一个应用

    <7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...

  9. Spring Boot——2分钟构建spring web mvc REST风格HelloWorld

    之前有一篇<5分钟构建spring web mvc REST风格HelloWorld>介绍了普通方式开发spring web mvc web service.接下来看看使用spring b ...

随机推荐

  1. CtsSecurityTestCases#ListeningPortsTest定位tcp端口与pid

    CtsSecurityTestCases#ListeningPortsTest定位tcp端口与pid [问题描述] cts失败项 armeabi-v7a CtsSecurityTestCases an ...

  2. 工具类CountDownLatch的应用---百米赛跑案例

    package com.aj.thread; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Execu ...

  3. crontab自动启动小任务例子(每一分钟将当前日期打入一个文件)

      crontab -l #查看当前定时任务列表 显示没有,那么我们来安装一下(必须在root用户下) – yum install vixie-cron  – yum install crontabs ...

  4. Coursera课程笔记----C程序设计进阶----Week 5

    指针(二) (Week 5) 字符串与指针 指向数组的指针 int a[10]; int *p; p = a; 指向字符串的指针 指向字符串的指针变量 char a[10]; char *p; p = ...

  5. MongoDB最佳安全实践

    在前文[15分钟从零开始搭建支持10w+用户的生产环境(二)]中提了一句MongoDB的安全,有小伙伴留心了,在公众号后台问.所以今天专门开个文,写一下关于MongoDB的安全. 一.我的一次Mong ...

  6. [hdu4585]离线,并查集

    题意:把一些数加到集合里面,每个数有两个属性,分别是编号和值,加进去之前询问集合里面距离自己“最近”的数的编号.最近的意思是值的差的绝对值最小,如果有相等的,则取值小的.并且已知所有数的id和valu ...

  7. 2020版Adobe全家桶介绍及免费下载安装

    前言 Adobe公司创建于1982年,是世界领先的数字媒体和在线营销解决方案供应商.公司总部位于美国加利福尼亚州圣何塞.Adobe 的 客户包括世界各地的企业.知识工作者.创意人士和设计者.OEM合作 ...

  8. 12.1 Go nsq

    12.1 Go nsq 1.nsq是Go语言编写的,开源的内存分布式消息队列中间件 2.可以大规模的处理每天数以十亿级别的消息 3.分布式和去中心化拓扑结构,无单点故障 4.地址https://git ...

  9. 3.5 Go布尔型

    1.Go布尔型 一个布尔类型的值只有两种:true 和 false. if 和 for 语句的条件部分都是布尔类型的值,并且==和<等比较操作也会产生布尔型的值. package main im ...

  10. Excel导出到DataSet

    #region 导入excel 返回Dataset public DataSet ExecleDataSet(string filename, string file, string Type) { ...