"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : SpringBootMVC Development Date : 10/12/2024 (Session - 82) _____________________________________________________________________________________________________________________________ Last Session ============ * We have completed FileUploading & File Downloading Concepts in Spring Boot MVC Today Session : Thymeleaf ========================= * It is another UI Technology which build on the top of the HTML for dynamic webpages. * HTML Technology is purely used for developing the Static Web pages i.e.,fixed content of the web page. When we are developing the Html Page(Html Tags) with Thymeleaf tags that page will comes as "Dynamic Web Page". * So far we developing the view pages in spring mvc (or) spring boot mvc either html pages (or) JSP pages. Every JSP Page will be converted into Underlying Java Equivalent Servlet(JES) which will requires the lot of memory and lot of cpu time and also will create an implicit objects is required to translate from jsp page into servlet program. index.jsp(JSP Page) >>>>>>>>>>>>>>>>>> index_jsp.java(JES) display.jsp >>>>>>>>>>>>>>>>>>>>>>>>>> display_jsp.java(JES) * To overcome the above problem of JSP Pages we need to use Thymeleaf as lightweight alternate for rendering dynamic webpages. * Thymeleaf is a server-side Java-based template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text. It is more powerful than JSP and responsible for dynamic content rendering on UI. * In the Spring Web Application development always view pages will be picked DispatcherServlet based prefix and suffix of the ViewResolver. Spring MVC >>>>>>>>>>>> ViewResolver >>>>>>>>>>>>> InternalResourceViewResolver Spring Boot Web MVC >>>>>>>>>>>> View Resolver Class will get through AutoConfiguration and programmer need to configure the prefix and suffix in application.properties file. * In order to place Thymeleaf pages in spring boot mvc application the belows are the prefix and suffix values. prefix >>>>>>>>>>>>>>>>>> /resources/templates/ suffix >>>>>>>>>>>>>>>>>> .html * In order to develop the view pages using Thymeleaf in spring boot webapplication development and we need to include to one starter i.e.,spring-boot-starter-thymeleaf. * After including the above starter in spring boot mvc project as programmer we need to activate thymeleaf in html page
****** th:action="@{/saveCustomer}" ****** th:object="${cust}" ****** ModelAttribute property of is from spring mvc tags. th:object is equivalent to ModelAttribute * Thymeleaf uses a set of tags and attributes that are embedded within your HTML templates to control the dynamic content rendering process. * These tags and attributes are used to interact with data from the server, apply conditions, iterate over collections, and more. Here are some of the commonly used Thymeleaf tags and their purposes 1) th:text ========== * This attribute is used to set the text content of an element. It replaces the existing content of the element with the value of the provided expression. Example =======

Default Name

2) th:if ======== * This attribute is used to conditionally render elements based on a condition. Example =======

Admin User

3) th:unless ============ * The opposite of th:if, this attribute renders elements if the provided condition is false. Example =======

Welcome, Registered User

4) th:each ========== * This attribute is used to iterate over a collection and generate content for each item. Example =======
  • Product Name