springboot渲染templates

一、引入依赖

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

二、设置配置

#thymeleaf配置
#模板的模式,支持如:HTML、XML、TEXT、JAVASCRIPT等
spring.thymeleaf.mode=HTML5
#编码,可不用配置
spring.thymeleaf.encoding=UTF-8
#内容类别,可不用配置
spring.thymeleaf.servlet.content-type=text/html
#开发配置为false,避免修改模板还要重启服务器
spring.thymeleaf.cache=false
#配置模板路径,默认就是templates,可不用配置
spring.thymeleaf.prefix=classpath:/templates/

三、配置控制类

@Controller
@RequestMapping("templates")
//@AccountBaseRight(roles = {"admin"})
public class testController {

    @Operation(summary = "根据ID获取数据详情")
    @RequestMapping("index")
    public String test(ModelMap map){
        map.addAttribute("username", "蘑菇头");
        map.addAttribute("password", "123456789");
        map.put("tes", "你好");
        return "index";
    }

四、加入template

 

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<p>在webapp下面的资源可以访问到templates下面的资源,原因是webapp在加载的时候会放到classpath下面去</p>
<p>所以可以进行交互,互相访问</p>
<a href="templates/index">index</a>
<a href="templates/back">more</a>
</body>
</html>

参考:https://www.cnblogs.com/1998xujinren/p/12352855.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值