Further refined the example: Simplified the setup
authorKai Moritz <kai@juplo.de>
Sun, 27 Sep 2020 09:23:03 +0000 (11:23 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 2 Oct 2020 17:17:55 +0000 (19:17 +0200)
commit757fd57c38f39666d8cd7339cfe306e464bb70f0
tree2312521303e739cbca5f420e4d022993329abef0
parent64108e90d14f6e85c76c463b460ba92307ef15cd
Further refined the example: Simplified the setup

* Goal: Do not rely on knowledge about Thymeleaf
* Goal: Separate MVC (controller) from business logic (service)
* Introduced an ExampleService
* The service checks the answer for
  The Ultimate Question Of Life, The Universe And Everything
* Requests without any answer are tolarated, so that the page with the
  question can be rendered
* Only numbers (Integer) are allowed as answer.
* Negative numbers are not allowed as answers: the service answers with an
  empty Optional.
* The view contains a bug, that results in a 503 for negative answers:
  Optional.get() is called, regardless of the state of the Optional

* The view renders the question, if no answer is specified (initial request!)
* If a valid request is specified, the answer and the outcome is rendered
* If an invalid request (negative number!) is specified, the view generates
  an exception, because it tries to resolve the Optional anyway
src/main/java/de/juplo/demo/ExampleController.java
src/main/java/de/juplo/demo/ExampleService.java [new file with mode: 0644]
src/main/resources/templates/a.html [deleted file]
src/main/resources/templates/b.html [deleted file]
src/main/resources/templates/view.html [new file with mode: 0644]
src/test/java/de/juplo/demo/ExceptionHandlingApplicationTests.java