4 import java.util.stream.Collectors;
5 import lombok.extern.slf4j.Slf4j;
6 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.ModelAttribute;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RequestParam;
10 import org.thymeleaf.util.StringUtils;
14 * Controller to demonstrate the behavior of checkboxes
19 public class DemoController
22 public String display(@ModelAttribute Form form)
25 "option={}, inner={}{}",
31 .map(entry -> entry.getKey() + "=" + entry.getValue())
32 .collect(Collectors.joining(", ", ", ", "")));
36 @RequestMapping(path = "/", params = "add")
37 public String add(@ModelAttribute Form form, @RequestParam String name)
39 if (!StringUtils.isEmptyOrWhitespace(name))
41 form.map.put(name.trim(), Boolean.FALSE);
42 log.info("Added option \"{}\" to the map", name.trim());
46 log.info("Ignoring empty option-name");