SpringBoot使用Thymeleaf模板引擎访问静态html的过程

网友投稿 740 2023-03-23

SpringBoot使用Thymeleaf模板引擎访问静态html的过程

SpringBoot使用Thymeleaf模板引擎访问静态html的过程

最近要做一个java web项目,因为页面不是很多,所以就没有前后端分离,前后端写在一起,这时候就用到thymeleaf了,以下是不动脑式的傻瓜教程。。。。。

一:创建spring boot的web项目,过程略;

二:依赖如下:

http:// org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-thymeleaf

2.1.2.RELEASE

org.springframework.boot

spring-boot-starter-test

test

<groupId>org.junit.vintage

junit-vintage-engine

&lhttp://t;/exclusion>

三:配置文件:application.properties

#端口号

server.port=8099

# 配置

#thymeleaf

spring.thymeleaf.cache=false

spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.check-template-location=true

spring.thymeleaf.suffix=.html

spring.thymeleaf.encoding=UTF-8

spring.thymeleaf.servlet.content-type=text/html

spring.thymeleaf.mode=HTML

四:项目的templates文件夹下新建页面success.html,如下

五:controller

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

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

/**

* @author liuhongyang

* @2020/10/20 14:35

* 文件说明:

*/

@Controller

public class FirstTestController {

@RequestMapping(value = "hello")

public String hello(ModelMap modelMap) {

modelMap.put("hei", "thymeleaf");

return "success";

}

}

六:访问如下,完成

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:小程序跳转(小程序跳转小程序)
下一篇:怎么自创小程序软件(怎么自创小程序软件图标)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~