diff --git a/thymeleaf/src/main/java/com/example/thymeleaf/basic/BasicController.java b/thymeleaf/src/main/java/com/example/thymeleaf/basic/BasicController.java index eafb3ac6..6c40e4cb 100644 --- a/thymeleaf/src/main/java/com/example/thymeleaf/basic/BasicController.java +++ b/thymeleaf/src/main/java/com/example/thymeleaf/basic/BasicController.java @@ -1,11 +1,13 @@ package com.example.thymeleaf.basic; import lombok.Data; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -49,6 +51,19 @@ public class BasicController { return "basic/variable"; } + @GetMapping("/basic-objects") + public String basicObject(HttpSession session) { + session.setAttribute("sessionData", "Hello Session"); + return "basic/basic-objects"; + } + + @Component("helloBean") + static class HelloBean { + public String hello(String data) { + return "Hello" + data; + } + } + @Data static class User { private String username; diff --git a/thymeleaf/src/main/resources/templates/basic/basic-objects.html b/thymeleaf/src/main/resources/templates/basic/basic-objects.html new file mode 100644 index 00000000..e71d33f7 --- /dev/null +++ b/thymeleaf/src/main/resources/templates/basic/basic-objects.html @@ -0,0 +1,24 @@ + + +
+ +