1、前端页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>内敛表达式</title>
</head>
<body>
<!--
th:inline="text":表明内敛表达式用于文本中
-->
<div th:inline="text">
[[${data}]]
</div>
<button th:onclick="getData()">按钮</button>
<!--
th:inline="javascript":表明内敛表达式用于java脚本中
-->
<script type="text/javascript" th:inline="javascript">
function getData(){
alert("---------");
alert([[${data}]]);
}
</script>
</body>
</html>
2、后台控制器
package com.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MyController {
@RequestMapping("/first")
public String doFirst(Model model) {
model.addAttribute("data", "springboot inline");
return "/inline";
}
}