1 新建项目

新建项目,选择Spring Initializr

【微服务记录】intellij 建立spring boot 项目一路默认,然后选择web

【微服务记录】intellij 建立spring boot 项目

2 代码修改

在java目录下新建controller包,在controller包下新建SampleController类

【微服务记录】intellij 建立spring boot 项目

代码为

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

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

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

 

修改配置文件,设置监听端口(默认880)

【微服务记录】intellij 建立spring boot 项目

右键运行

【微服务记录】intellij 建立spring boot 项目

在浏览器登录http://127.0.0.1:9090

【微服务记录】intellij 建立spring boot 项目

相关文章: