Exercise 18: Views - jkneal/spring-angular-train GitHub Wiki
Learn how to forward to views and redirect. Learn how to create Thymeleaf templates.
-
In
src/main/resources/templates, create a new folder named 'shop' -
Now in
src/main/resources/templates/shop, create a new file named 'index.html' -
In index.html, add the standard HTML 5 doctype, followed by the html tag that imports thymeleaf into the 'th' namespace
-
Next add the following content to index.html:
<head th:replace="home :: head">
</head>
<body>
<header th:replace="home :: header">
</header>
<main class="container">
</main>
<footer th:replace="home :: footer">
</footer>
<div th:replace="home :: scripts">
</div>
</body>-
Now within the main tag, add a hyperlink for the path '/shop/back'. Display 'Back' for the link text, and add the CSS class 'right'
-
After the link you created in step 5, add a blockquote. The blockquote should display the external message with key 'msgs.todaysSales', and default to the text "Today's Sales" (for natural templating). Finally add the CSS classes 'red-text' and 'text-lighten-1'
-
In
src/main/resourcescreate a new file named 'messages.properties' -
In messages.properties, add a message with key 'msgs.todaysSales' and value "50% Off All Items!"
-
In
edu.train.shop.ShopController, change the methodgetAllProductsto return the logical view name for the view you created in step 2 -
In the same controller, add a new method named 'back' that maps to the request path '/shop/back' and accepts Http Get methods. Within this method, redirect to the path "/"
- Start the training application and go to the app home page
- Click on the link 'Exercise 18'. Verify the returned page looks like the following:

- Not click the link with text 'Back' and verify you are returned to the app home page (menu)