From 9de876c5fb510a0ec6ec439aaa371673d6382c58 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 21 Jan 2020 23:48:25 +0100 Subject: [PATCH] Added checkboxes, that are stored in a map --- src/main/java/de/juplo/demo/DemoController.java | 11 ++++++++++- src/main/java/de/juplo/demo/Form.java | 5 +++++ src/main/resources/templates/form.html | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/juplo/demo/DemoController.java b/src/main/java/de/juplo/demo/DemoController.java index 3f8d0dd..b841780 100644 --- a/src/main/java/de/juplo/demo/DemoController.java +++ b/src/main/java/de/juplo/demo/DemoController.java @@ -1,6 +1,7 @@ package de.juplo.demo; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; @@ -18,7 +19,15 @@ public class DemoController @RequestMapping("/") public String display(@ModelAttribute Form form) { - log.info("option={}, inner={}", form.option, form.inner.option); + log.info( + "option={}, inner={}{}", + form.option, + form.inner.option, + form.map + .entrySet() + .stream() + .map(entry -> entry.getKey() + "=" + entry.getValue()) + .collect(Collectors.joining(", ", ", ", ""))); return "form"; } } diff --git a/src/main/java/de/juplo/demo/Form.java b/src/main/java/de/juplo/demo/Form.java index e7a40af..c44eb6c 100644 --- a/src/main/java/de/juplo/demo/Form.java +++ b/src/main/java/de/juplo/demo/Form.java @@ -1,6 +1,9 @@ package de.juplo.demo; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.Data; @@ -13,6 +16,8 @@ public class Form { Boolean option; Inner inner = new Inner(); + Map map = + Stream.of( "foo", "bar" ).collect(Collectors.toMap(a -> a, a -> false)); } @Data diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html index 10ebfaa..533758e 100644 --- a/src/main/resources/templates/form.html +++ b/src/main/resources/templates/form.html @@ -24,6 +24,11 @@ +
+ + + +