The most basic spring boot-- hello world

The most basic hello world:

Project directory structure:

卷 software_home 的文件夹 PATH 列表
卷序列号为 7E58-1E96
D:.
│  .txt
│  pom.xml
│  springboot_0_hello.iml
│  
├─.idea
│      compiler.xml
│      encodings.xml
│      misc.xml
│      uiDesigner.xml
│      workspace.xml
│      
├─src
│  ├─main
│  │  ├─java
│  │  │  └─com
│  │  │      └─swq
│  │  │              HelloController.java
│  │  │              Helloworld.java
│  │  │              
│  │  └─resources
│  └─test
│      └─java
└─target
    │  springboot_0_hello-1.0-SNAPSHOT.jar
    │  springboot_0_hello-1.0-SNAPSHOT.jar.original
    │  
    ├─classes
    │  └─com
    │      └─swq
    │              HelloController.class
    │              Helloworld.class
    │              
    ├─generated-sources
    │  └─annotations
    ├─maven-archiver
    │      pom.properties
    │      
    └─maven-status
        └─maven-compiler-plugin
            ├─compile
            │  └─default-compile
            │          createdFiles.lst
            │          inputFiles.lst
            │          
            └─testCompile
                └─default-testCompile
                        inputFiles.lst
                        

pom.xml:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>springboot_0_hello</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


</project>

Helloworld:

package com.swq;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

}

HelloController:

package com.swq;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "hello swq !";
    }
}

 

 

 

Labeled jar package, direct interface to run CMD:

run:

access:

 

OK! 

Published 592 original articles · won praise 1353 · Views 1.15 million +

Guess you like

Origin blog.csdn.net/weixin_42859280/article/details/105147332