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);
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 = "add=card")
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 = "remove=card")
50 public String removeCard(
51 @ModelAttribute Form form,
52 @RequestParam Integer card)
54 Map<String, Boolean> content = form.cards.remove(card);
55 LOG.info("Removed card #{} with content: {}", card, content);
59 @RequestMapping(path = "/", params = "add=row")
60 public String addRow(@ModelAttribute Form form, @RequestParam Integer card)
62 LOG.info("Adding row {} to card #{}", form.row.get(card), card);
63 form.cards.get(card).put(form.row.get(card), Boolean.FALSE);
67 @RequestMapping(path = "/", params = "remove!=card")
68 public String removeRow(@ModelAttribute Form form, @RequestParam String remove)
70 String[] parts = remove.split(":", 2);
71 Integer card = Integer.valueOf(parts[0]);
72 String row = parts[1];
73 Boolean value = form.cards.get(card).remove(row);
74 LOG.info("Removed row {} with value {} from card #{}", row, value, card);