Skip to content

Commit 9509a2f

Browse files
committed
Add invocation counter
1 parent 8b1719d commit 9509a2f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/main/java/hello/GreetingController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ public class GreetingController {
1515
@Value("${background-color:white}")
1616
private String backgroundColor;
1717

18+
private int invocationCount = 0;
19+
1820
@GetMapping("/")
1921
public String greeting(Model model) {
2022
model.addAttribute("name", System.getenv().getOrDefault("GREETING_DEFAULT", "World!"));
2123
model.addAttribute("hostname", System.getenv().getOrDefault("HOSTNAME", "unknown"));
2224
model.addAttribute("backgroundColor", backgroundColor);
2325
model.addAttribute("userDir", System.getProperty("user.dir"));
2426
model.addAttribute("password", System.getenv().getOrDefault("PASSWORD", "unknown"));
27+
model.addAttribute("invocationCount", ++invocationCount);
2528
return "greeting";
2629
}
2730

src/main/resources/templates/greeting.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<p th:text="'Hello, ' + ${name} + ' , this is host ' + ${hostname} + '!'"/>
1010
<p th:text="'My working directory is: ' + ${userDir}"/>
1111
<p th:text="'The password is: ' + ${password}"/>
12+
<p th:text="'This page has been invoked ' + ${invocationCount} + ' times since application start.'"/>
1213
</body>
1314
</html>

0 commit comments

Comments
 (0)