1.创建并初始化
点击Create New Project选择Spring Initializr,点next
2.输入项目信息
Group:是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构。
Artifact:是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称。
例如:你的项目是com.sample.demo,那么你的Group就是com.sample,你的Artifact就是demo。
需要注意的是,在底部Package默认填充的名称是com.sample.demo,即Group+Artifact,建议的是去掉Artifact,因为在后面多模块下这样的包名不利于包扫描。点击Next。
3.选择项目的类型
我们需要新建web项目,所以选择Web,Sping Web
4.在主程序包下新建一个controller包并且新建一个HelloController类
HelloSpring类
package com.example.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController@RequestMapping("/hello")
public class HelloSpring {
@GetMapping("/say")
public String sayHello(){
return "Helloword Spring Boot";
}
}
5.启动项目
运行这个Web项目的启动类WebApplication
6.访问网页
可以看到网页服务启动在本机的8080端口,浏览器输入http://localhost:8080/hello/say
参考文章:使用IDEA新建基于SpringBoot的Web项目(超详细)