SpringBoot---視圖解析小實例(thymeleaf)


pom.xml


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

作用:

充當視圖解析器角色,渲染視圖


Controller:

@Controller
public class IndexController {

    @RequestMapping("/index")
    public String index() {
        return "index";
    }
}

作用:

返回字符串提供視圖解析器中的視圖名稱


springboot加載html默認到resources/templates裏面尋找;創建index.html;


訪問地址:

http://localhost/index

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章