feat(wip): add function call examples

This commit is contained in:
exaucae
2022-06-17 16:55:28 +00:00
parent cd033c2109
commit 7adea75450
3 changed files with 101 additions and 0 deletions
@@ -0,0 +1,16 @@
package com.baeldung.thymeleaf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class FunctionCallController {
@RequestMapping(value = "/function-call", method = RequestMethod.GET)
public String getExampleHTML(Model model) {
model.addAttribute("num", 2);
return "functionCall.html";
}
}
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Thymeleaf: Javascript function call</title>
</head>
<body>
<header>
<div> Thymeleaf: Javascript function call </div>
</header>
<main>
<section>
<div>Inline function call</div>
<div>
<header>Without a variable</header>
<button th:onclick="'alert(\'a\');'">Without variable</button>
</div>
<div>
<header>With a variable</header>
<button th:onclick="'alert(\'' + ${num} + '\');'">With variable</button>
</div>
</section>
</main>
</body>
</html>