spring-boot入门(一)——使用idea初始化一个项目

2021-09-23  本文已影响0人  前端来入坑
image.png
image.png
image.png
image.png
image.png
maven下载地址
image.png
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class loginController {
    @RequestMapping("/")
    public String loginPage(Map<String, Object> map) {
        //通过 map 向前台页面传递数据
        map.put("msg", "hello world");
        return "login";
    }
}

resources->templates文件夹下新建一个login.html

<!DOCTYPE html>
<!--导入thymeleaf的名称空间-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--th:text 为 Thymeleaf 属性,用于获取指定属性的值-->
<h1 th:text="${msg}"></h1>
</body>
</html>
<!--Thymeleaf 启动器-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

启动打开http://localhost:8080/

上一篇 下一篇

猜你喜欢

热点阅读