IDEA从无到有搭建Springboot Hello Web

Springboot Hello Web

最近在学习通过springboot写一个hello页面,通过百度以及结合项目中的使用,Mark一下其实现过程。本文通过IDEA实现。

创建项目
  1. 打开IDEA,点击 [File] ->[New] ->[Project…](如下图)。
    在这里插入图片描述
  2. 创建项目(如下图)
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

到此项目已近创建完毕。创建完成后,其结构如下:
在这里插入图片描述

接下来进行代码实现。

创建Controller类

创建Controller类,其内容如下

@Controller
public class HelloController {
    @RequestMapping(value = "/hello")
    public ModelAndView sayHello(){
        return  new ModelAndView("/hello");
    }
}
修改Springboot启动类,在该java文件里面添加@ComponentScan注解,其内容如下所示:
@SpringBootApplication
@ComponentScan("com.demo")
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}
在templates里面添加hello.html文件,其内容如下:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8">
    <!-- 页面标题-->
    <title>Springboot</title>
    <!-- 替换默认图标-->
    <link th:href="@{icon.png}"  rel="shortcut icon" type="image/x-icon">
</head>
<body>
HELLO
</body>
</html>

到此,代码已经实现或修改完毕。

启动springboot(如下图)

在这里插入图片描述

当springboot启动完成后,在浏览器输入http://localhost:8080/hello,将在页面显示HELLO内容。如下图:
在这里插入图片描述

完结:
通过简单的步骤,一个简单的springboot web hello页面搭建成功。相比通过spring mvc来搭建,效率不止快一倍。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值