SpringBoot的第一个HelloWorld工程

我的第一个SpringBoot工程是用 IntelliJ IDEA 2019.3.3 x64 编写的,IDEA的安装和破解我就先不说了。

1)、首先新建一个maven项目

2)、导入springboot依赖包

    <!--导入springboot依赖包-->
    <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>

3)、新建一个主程序类 HelloWorldMainApplication.java

package com.smxy.ljj;

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

/**
 * @SpringBootApplication 来标注一个主程序类,说明这是一个spring boot应用
 */
@SpringBootApplication
public class HelloWorldMainApplication {

    public static void main(String[] args) {

        //spring应用启动起来
        SpringApplication.run(HelloWorldMainApplication.class,args);
    }
}

4)、新建helloworld工程的Controller控制器

package com.smxy.ljj.controller;

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 world!";
    }
}

在主程序类中运行,如下

运行结果:

欢迎留言交流,互相学习

发布了19 篇原创文章 · 获赞 2 · 访问量 6360

猜你喜欢

转载自blog.csdn.net/fjzzpljj/article/details/104473012