diff --git a/backend/springboot/Thymeleaf.md b/backend/springboot/Thymeleaf.md new file mode 100644 index 0000000..2f86b07 --- /dev/null +++ b/backend/springboot/Thymeleaf.md @@ -0,0 +1,72 @@ +# Thymeleaf Quick Guide + + + +* sample.java + +```java +@Controller +public class JavascriptController { + + @RequestMapping("/") + public String greeting(Model model) { + int someReferenceId = 1234; + //Deliver Results Array to the DOM + model.addAttribute("referenceId", someReferenceId); + return "index"; + } +} +``` + + + +* index.html + * use thymeleaf syntax `/*[[${...}]]*/`to access the model data + * [**JavaScript natural templating**! ](https://attacomsian.com/blog/thymeleaf-set-javascript-variable) + +```html + + + +``` + + + +* index.js + +```js +// within js file, can access 'referenceId' dclared in inline script under html + +function doSomething() { + $.ajax({ + type: 'GET', + url: '/api/' + referenceId , + contentType: 'application/json', + beforeSend: beforeSend + }) +} +``` + + + +* alternative method using `` tag + +```html + +``` + +* external javascript file + +```js +function myFunction(){ + var val = $("#yourId").val(); +} +``` +