pom文件中引入Thymeleaf模板

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

在h5页面头部

引入

后台代码保存实现比喻

@RequestMapping("/hello")
    public String hello(ModelMap model){ 
        User user=new User();
        user.setId(1);
        user.setName("zhangsan");
    model.addAttribute("user",user ); 
    return "index"; 
  }

前端值的获取(方式一):将model中的值赋给input,然后Js获取隐藏域的值。

<input type="text" th:value="${user.name}" id="user_name"/>

在javascript中访问model(方式二):直接在js中取值,需要在script上添加th:inline=”javascript”的属性

<script th:inline="javascript"> 
	var single = [[${user}]];
	 console.log(user.name+"/"+user.id)
</script>

Thymeleaf如何拼接href \src

//src示例:
<img th:src="@{/img/research/{filename}(filename=${research.filename})}">
//href示例:
<a th:href="@{'https://'+${url.url}}" th:text="${url.urlName}"></a>
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐