(一)SpringBoot 初学者之 HelloWorld

1.准备工具

jdk1.8,Apache-maven3.5.2(都需要配置环境变量,可百度),Intellij IDEA

2.目录结构

3.编码部分

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>com.atguigu</groupId>
    <artifactId>spring-boot-01-helloworld</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>
    <!--这是 web 启动器-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!--这个插件,将应用打包成一个可执行的 jar 包,直接在 dos 窗口使用命令就能运行-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

HelloController类

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }
}

HelloWorldApplication类

/**
 * SpringBootApplication 用来标注一个主程序类,说明这是一个Spring Boot
 */
@SpringBootApplication
public class HelloWorldApplication {

    public static void main(String[] args) {
        //Spring 应用启动
        SpringApplication.run(HelloWorldApplication.class,args);
    }
}

4.启动

猜你喜欢

转载自blog.csdn.net/qq_19987491/article/details/82894626