Skip to content

Commit

Permalink
#1 - add controller and stub thymeleaf view
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensystems committed Mar 2, 2021
1 parent 7c3ea34 commit f1e2dac
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package systems.eventstream.field.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class RootController {

@Value("${welcome.message}")
private String message;

private List<String> tasks = Arrays.asList("a", "b", "c", "d", "e", "f", "g");

@GetMapping("/")
public String main(Model model) {
model.addAttribute("message", message);
model.addAttribute("tasks", tasks);

return "welcome"; //view
}

// /hello?name=kotlin
@GetMapping("/command")
public String mainWithParam(
@RequestParam(name = "name", required = false, defaultValue = "")
String name, Model model) {
model.addAttribute("message", name);
return "welcome";
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
spring.security.user.name=user
spring.security.user.password=password

welcome.message=Event Stream
28 changes: 28 additions & 0 deletions src/main/resources/templates/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Event Stream</title>
<link rel="stylesheet" th:href="@{webjars/bootstrap/4.2.1/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/main.css}"/>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Event Stream</a>
</nav>
<main role="main" class="container">
<div class="starter-template">
<h1>Event Stream</h1>
<h2>
<span th:text="'Hello, ' + ${message}"></span>
</h2>
</div>
<ol>
<li th:each="task : ${tasks}" th:text="${task}"></li>
</ol>
</main>
<!-- /.container -->
<script type="text/javascript" th:src="@{webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>
</body>
</html>

0 comments on commit f1e2dac

Please sign in to comment.