• spring boot Hello World


    package com.example.myFirstproject;
    
    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);
      }
    }
    package com.example.myFirstproject;
    
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @EnableAutoConfiguration
    public class Example {
    
      @RequestMapping("/")
      String home() {
        return "Hello World!";
      }
    
      @RequestMapping("/hello/{myName}")
      String index(@PathVariable String myName) {
        return "Hello " + myName + "!!!";
      }
    }
    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.example</groupId>
      <artifactId>myFirstproject</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>jar</packaging>
    
      <name>myFirstproject</name>
      <url>http://maven.apache.org</url>
    
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <parent>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-parent</artifactId>  
            <!-- <version>1.4.0.BUILD-SNAPSHOT</version>   -->
            <version>1.5.9.RELEASE</version>  
            <relativePath/> <!-- lookup parent from repository -->  
      </parent>  
        
        
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
        </dependency>
        
         <dependency>  
                <groupId>org.springframework.boot</groupId>  
                <artifactId>spring-boot-starter-web</artifactId>  
         </dependency>  
            
      </dependencies>
      
       <!-- Package as an executable jar -->  
        <build>  
            <plugins>  
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
                <plugin>  
                    <groupId>org.springframework.boot</groupId>  
                    <artifactId>spring-boot-maven-plugin</artifactId>  
                </plugin>  
            </plugins>  
        </build>  
      
        <!-- Add Spring repositories -->  
        <!-- (you don't need this if you are using a .RELEASE version) -->  
       <!--  <repositories>  
            <repository>  
                <id>spring-snapshots</id>  
                <url>http://repo.spring.io/snapshot</url>  
                <snapshots><enabled>true</enabled></snapshots>  
            </repository>  
            <repository>  
                <id>spring-milestones</id>  
                <url>http://repo.spring.io/milestone</url>  
            </repository>  
        </repositories>  
        <pluginRepositories>  
            <pluginRepository>  
                <id>spring-snapshots</id>  
                <url>http://repo.spring.io/snapshot</url>  
            </pluginRepository>  
            <pluginRepository>  
                <id>spring-milestones</id>  
                <url>http://repo.spring.io/milestone</url>  
            </pluginRepository>  
        </pluginRepositories>   -->
    </project>

    运行Application打开网址

    http://localhost:8080/

    http://localhost:8080/hello/123

  • 相关阅读:
    根据 谷歌官网写一个 该浏览器上的扩展
    深度学习
    华为在线学习
    pandas 常规操作大全
    猎奇有些意思的
    LINUX 必知必会检测表--通读无关语言
    自动化部署三剑客 gitlab + ansible + jenkins
    python 框架
    delphi 多线程之System.TMonitor
    函数和对象 及 prototype和__proto__
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/8371393.html
Copyright © 2020-2023  润新知