From: Kai Moritz Date: Tue, 21 Jan 2020 16:46:34 +0000 (+0100) Subject: WIP X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=675ae50396fef70c7e95cd5e9ba3ea92836c5fce;p=demos%2Fspring-boot WIP --- diff --git a/src/main/java/de/juplo/demo/DemoController.java b/src/main/java/de/juplo/demo/DemoController.java new file mode 100644 index 0000000..ddf4e06 --- /dev/null +++ b/src/main/java/de/juplo/demo/DemoController.java @@ -0,0 +1,77 @@ +package de.juplo.demo; + + +import java.util.HashMap; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +/** + * + * @author Kai Moritz + */ +@Controller +public class DemoController +{ + private static final Logger LOG = + LoggerFactory.getLogger(DemoController.class); + + + @RequestMapping("/") + public String display( + @ModelAttribute("form") Map> form) + { + for (Integer id : form.keySet()) + for (String entry : form.get(id).keySet()) + LOG.info("{} - {}: {}", id, entry, form.get(id).get(entry)); + + return "form"; + } + + @RequestMapping(path = "/", params = "row") + public String addRow( + @ModelAttribute("form") Map> form, + @RequestParam Integer row) + { + LOG.info("Adding row #{}", row); + form.put(row, new HashMap<>()); + return "form"; + } + + @RequestMapping(path = "/", params = "row") + public String removeRow( + @ModelAttribute("form") Map> form, + @RequestParam Integer row) + { + Map content = form.remove(row); + LOG.info("Removed row #{} with content: {}", row, content); + return "form"; + } + + @RequestMapping(path = "/", params = { "row", "entry" }) + public String addEntry( + @ModelAttribute("form") Map> form, + @RequestParam Integer row, + @RequestParam String entry) + { + LOG.info("Adding entry {} to row #{}", entry, row); + form.get(row).put(entry, Boolean.FALSE); + return "form"; + } + + @RequestMapping(path = "/", params = { "row", "entry" }) + public String removeEntry( + @ModelAttribute("form") Map> form, + @RequestParam Integer row, + @RequestParam String entry) + { + Boolean value = form.get(row).remove(entry); + LOG.info("Removed entry {} with value {} from row #{}", entry, value, row); + return "form"; + } +}