SpringBoot 集成 Jsp、Thymeleaf 模板引擎 ,这操作真香

spring.thymeleaf.encoding=UTF-8

使用模板响应类型

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

默认无法直接访问templates下的页面, 需要设置

以后static下放css与js, templates下放页面

spring.resources.static-locations=classpath:/templates, classpath:/static




引入下面的依赖是为了可以直接访问 html 页面:



spring.resources.static-locations=classpath:/templates, classpath:/static




例如 **不经过控制器** 访问 `resources/templates/hello.html`:如果不配置上面则无法访问。



http://localhost:8080/index.html




[](https://codechina.csdn.net/m0_60958482/java-p7)控制器访问 html 页面

--------------------------------------------------------------------------------



使用 Thymeleaf **模板页面** 默认放在 `resources/templates` 目录中



创建一个 `/resources/templates/hello.html` 页面:



<meta charset="UTF-8">

<title>hello</title>

SpringBoot 集成 Thymeleaf!!!




编写控制器:



@Controller

@RequestMapping("/hello")

public class HelloController {

@GetMapping("/hello")

public String hello() {

    System.out.println("hello spring boot!");

    return "hello";

}

}




测试访问:



http://localhost:8080/hello/hello




![在这里插入图片描述](https://img-blog.csdnimg.cn/20200621020219341.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzczNDA5NQ==,size_16,color_FFFFFF,t_70)



[](https://codechina.csdn.net/m0_60958482/java-p7)Thymeleaf 基本使用

=======================================================
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值