An online markdown blog and knowledge repository.
Notes taken while reading the reference materials.
Serving Web Content by spring.io guides
Thymeleaf by thymeleaf.org docus
Requirements to build a simple website:
Helpful Utilities:
Drop all static resource files into subfolder /static
or /public
The default index page is used (by default) as the root or home page of the webapp.
Spring uses Controllers to render pages (like MVC). Annotation: @Controller
.
Each Controller defines a 'Route'.
HTTP Web Requests are trapped and directed to "method_name" using annotation @GetMapping
.
Annotation @RequestParam
binds QueryString value to a named parameter e.g. @RequestParam(name="username", required=false, defaultView=String:default_value)
.
ThymeLeaf performs server-side rendering of the HTML.
String attributes are passed to the HTML file via elements with attribute th:text
(expression).
Enables:
maven compile
or gradle build
forces a ClassPath change. Some IDEs may change ClassPath on Save. Additional paths can be configured to trigger restarts.Devtools is not enabled in a JAR, but can be enabled by setting properties in Maven or Gradle files e.g. 'excludeDevtools=false'
Utilize Spring Initializr: Select Project, Language, and Boot version, JAR/WAR file generation, and JDK version. Can also add "Dependencies". Generates a downloadable Zip file.
Controllers Templates
./gradlew bootrun
and ./gradlew build
=> Return an executable JAR file.
JAR files are stored in the Project path 'build/libs/application-name-version.jar'
The following is a very high-level overview of Thymeleaf, based on the paged linked in References, above.
Website paths, model data, and template views are considered a 'model map'.
Thymeleaf takes a model map and transforms it into a Thymeleaf context object.
Model Attributes are data that can be accessed during view execution.
Context Variables are the Thymeleaf equivalent of Model Attributes.
Request parameters can be viewed with params
dot notation.
Multi-valued Request Params can be accessed using bracket notation.
Session atributes are accessed using session.
Get direct access to 'java.servlet.http.HttpSession' object by using #session
Shared between Requests and Sessions.
Access them using #servletContext.method
Beans registered with the Spring Application Context carry methods defined in @Configuration
.
Use Beans in the HTML via the 'th:text=` attribute.
Return to Parent Readme.md