码农网

网站首页> 后端开发> Java

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

众衡网络科技

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

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

二:依赖如下:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      <version>2.1.2.RELEASE</version>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

三:配置文件: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";
  }
}

六:访问如下,完成

SpringBoot Thymeleaf模板引擎

本文地址:https://m.manongw.com/article/67.html

文章来源:转载于CSDN,转载网址为https://blog.csdn.net/qq_35101267/article/details/109181638

版权申明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 ezhongheng@126.com 举报,一经查实,本站将立刻删除。

最近更新
热门素材
html5卡通章鱼素材,几何图形抽象设计

html5卡通章鱼素材,几何图形抽象设计

图片素材

html文字动画特效,文字虚线边框

html文字动画特效,文字虚线边框

文字特效

Bootstrap点击左侧垂直导航菜单全屏网页切换特效

Bootstrap点击左侧垂直导航菜单全屏网页切换特效

导航菜单

js+css3透明渐变风格导航菜单特效

js+css3透明渐变风格导航菜单特效

导航菜单

8款经典的css网站顶部导航栏样式

8款经典的css网站顶部导航栏样式

图片素材

js+css3网站顶部自适应导航栏菜单特效

js+css3网站顶部自适应导航栏菜单特效

图片素材

jQuery自定义添加删除表格行内容特效

jQuery自定义添加删除表格行内容特效

图片素材

jQuery+CSS3漂亮的下拉菜单选择框美化特效

jQuery+CSS3漂亮的下拉菜单选择框美化特效

css3实例

jQuery文字公告无限滚动轮播特效

jQuery文字公告无限滚动轮播特效

css3实例

jQuery+Layui省市区城市三级联动菜单选择特效

jQuery+Layui省市区城市三级联动菜单选择特效

css3实例