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:

    运行结果

  • 相关阅读:
    sublime text3配置javascript运行环境
    TCP/IP协议详解
    markdown基本语法
    pytest失败重跑
    pytest参数化
    Httprunner初步学习
    基础面向对象
    面试题
    包和loggging模块
    常用模块
  • 原文地址:https://www.cnblogs.com/xkxf/p/14380223.html
Copyright © 2011-2022 走看看