上次有人在评论里面说现在用IDEA的开发者越来越多了,我也换了,确实比价好用。本文还是老习惯,针对小白,大神们可以不用看了。
新建项目
IDEA选择新建项目,选择Spring Initializr进行初始化

基本的项目名称包名之类的

选择添加相关的依赖,这里的勾选相当于在pom文件中提前加了相关的第三方依赖库,这里我只选择了Web这一项,后面每用到一个依赖库的时候我们就手动加一下。

项目名称

新建完成后的项目结构

老规矩完成Hello World!
在com.wuhu.zhoumo下面新建一个包名controller,和ZhouMoApplication同一级别,SpringBoot默认配置中会自动进行扫描。
package com.wuhu.zhoumo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("hello")
public String hello(){
return "hello.html";
}
}
在static文件夹下新建hello.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
HELLO
</body>
</html>
运行项目
可以在IDEA右上角选择项目点击运行按钮,也右键点击ZhouMoApplication选择运行项目。

浏览器访问localhost:8080/hello即可访问到相应的页面

以前没用过SpringBoot的同学可能会问在哪里配置的8080端口,SpringBoot框架是一个约定大于配置的框架,很多地方的配置都会采用默认配置,如果需要自己制定,可以在application.properties这个文件中进行配置。
网友评论