4 import java.util.HashMap;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.springframework.stereotype.Controller;
9 import org.springframework.web.bind.annotation.ModelAttribute;
10 import org.springframework.web.bind.annotation.RequestMapping;
11 import org.springframework.web.bind.annotation.RequestParam;
19 public class DemoController
21 private static final Logger LOG =
22 LoggerFactory.getLogger(DemoController.class);
25 @RequestMapping(path = "/", params = { "!card", "!add", "!remove" })
26 public String display(@ModelAttribute Form form)
28 for (Integer id : form.cards.keySet())
29 for (String entry : form.cards.get(id).keySet())
30 LOG.info("{} - {}: {}", id, entry, form.cards.get(id).get(entry));
35 @RequestMapping(path = "/", params = "card=add")
36 public String addCard(@ModelAttribute Form form)
42 .reduce(0, (a, b) -> a > b ? a : b) + 1;
44 LOG.info("Adding new card #{}", next);
45 form.cards.put(next, new HashMap<>());
49 @RequestMapping(path = "/", params = "card!=add")
50 public String removeCard(@ModelAttribute Form form, @RequestParam Integer card)
52 Map<String, Boolean> content = form.cards.remove(card);
53 LOG.info("Removed card #{} with content: {}", card, content);
57 @RequestMapping(path = "/", params = "add")
58 public String addRow(@ModelAttribute Form form, @RequestParam Integer add)
60 LOG.info("Adding row {} to card #{}", form.row.get(add), add);
61 form.cards.get(add).put(form.row.get(add), Boolean.FALSE);
65 @RequestMapping(path = "/", params = "remove")
66 public String removeRow(@ModelAttribute Form form, @RequestParam String remove)
68 String[] parts = remove.split(":", 2);
69 Integer card = Integer.valueOf(parts[0]);
70 String row = parts[1];
71 Boolean value = form.cards.get(card).remove(row);
72 LOG.info("Removed row {} with value {} from card #{}", row, value, card);