springboot 简单demo

1.Annotation
Spring MVC annotations (not specific to Spring Boot)

  • @RestController

    handling incoming web requests

  • @RequestMapping

    provides “routing” information

  1. configure
  • @EnableAutoConfiguration.

    want to configure Spring

  1. The “main” Method run goal
 public static void main(String[] args) {
        SpringApplication.run(Test.class, args);
    }

  1. Running the Example
  • Creating an Executable Jar

mvn package

  • To run that application, use the java -jar command, as follows:
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar

  • If you want to peek inside, you can use jar tvf, as follows:
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar

mvn



    4.0.0

    com.example
    SpringBootLearn
    1.0-SNAPSHOT

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.3.RELEASE
    

    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

code

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Test {

    public static void main(String[] args) {
        SpringApplication.run(Test.class, args);
    }

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }
}

你可能感兴趣的:(springboot)