使用idea搭建spring boot + maven工程并运行hello world!

1.使用idea搭建spring boot项目工程,选择Spring Initializr,选中jdk然后next
使用idea搭建spring boot + maven工程并运行hello world!
2.输入Group,Artifact,选中Maven Project,然后next
使用idea搭建spring boot + maven工程并运行hello world!
3.选择web->web 然后next,再finish
使用idea搭建spring boot + maven工程并运行hello world!
4.搭建后项目目录如下
使用idea搭建spring boot + maven工程并运行hello world!
DemoApplication.java为项目启动入口

package com.example.demo;

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

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

在DemoApplication.java所在包或所在包的子包下创建HelloController.java

package com.example.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/")
    public String hello(){
        return "hello world!";
    }
}

运行项目,起来后在浏览器输入如下地址即可访问。
使用idea搭建spring boot + maven工程并运行hello world!