zoukankan      html  css  js  c++  java
  • Spring Boot笔记 #01# 快速入门(官方)

    步骤1:开始一个新的Spring Boot项目

    在https://start.spring.io/中创建,配置如下图

    点击generate按钮下载zip然后找个文件夹解压。

    步骤2:添加你的代码

    用集成开发环境打开这个项目找到src/main/java/com/example/demo文件夹中的DemoApplication.java文件,然后把下面的代码复制进去

                  package com.example.demo;
                  import org.springframework.boot.SpringApplication;
                  import org.springframework.boot.autoconfigure.SpringBootApplication;
                  import org.springframework.web.bind.annotation.GetMapping;
                  import org.springframework.web.bind.annotation.RequestParam;
                  import org.springframework.web.bind.annotation.RestController;
                  
                  @SpringBootApplication
                  @RestController
                  public class DemoApplication {
                    
                      
                      public static void main(String[] args) {
                      SpringApplication.run(DemoApplication.class, args);
                      }
                      
                      @GetMapping("/hello")
                      public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
                      return String.format("Hello %s!", name);
                      }
                    
                  }
                

    步骤3:尝试

    在项目的根目录下打开命令行(终端),windows下执行

    mvnw spring-boot:run

    linux或者“windows下的shell”执行

    ./mvnw spring-boot:run

    以上是官方教程,但是采用上面的指令我都没有运行出来。结果我把mvnw指令改成mvn指令就成功运行了。

    启动浏览器访问http://localhost:8080/hello:

    运行结果

  • 相关阅读:
    php上传excle文件,csv文件解析为二维数组
    transition的使用
    数组
    快捷键
    SCSS历史介绍与配置
    18-async函数
    this的指向问题
    媒体查询
    13-Set和Map数据结构
    15-Iterator和for…of循环
  • 原文地址:https://www.cnblogs.com/xkxf/p/14380223.html
Copyright © 2011-2022 走看看