SpringBoot菜鸟入门(一)---返回一个html页面

其实SpringBoot不适合做视图,还是做服务比较好一点

controller层,新建一个IndexController的类

package com.example.cloudprophet.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import sun.font.EAttribute;

@Controller
public class IndexController {
    @RequestMapping(value = "/index")
    public String index(){
        return "index";
    }

pom.xml添加模板引擎thymeleaf

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
</dependencies>
 

开启thymeleaf热部署

application.properties

# set to false for hot refresh
spring.thymeleaf.cache=false 

注意,此时需要Ctrl+F9重新build一下,再回到浏览器刷新,就能看到效果,每次都要哦

在resources->templates下新建一个index.html,访问http://127.0.0.1:8080/index即可

发布了219 篇原创文章 · 获赞 78 · 访问量 152万+

猜你喜欢

转载自blog.csdn.net/ssjdoudou/article/details/104109080
今日推荐