Thymeleaf - How to add checked attribute to input conditionally

后端 未结 5 548
滥情空心
滥情空心 2020-12-08 07:18

As you know, input component has an attribute, checked to whether mark the checkbox as enabled by default or not.



        
5条回答
  •  爱一瞬间的悲伤
    2020-12-08 07:56

    I faced problem for showing checkbox (tick mark on/off) in thymeleaf based on true or false value for the property. I solved it by following way.

    Method in controller

    @RequestMapping(value = "/test")
    public String showCheckbox(Model model) {
     boolean myBooleanVariable = false;
     model.addAttribute("myBooleanVariable", myBooleanVariable);
     return "sample-checkbox";
    }
    

    In HTML page:

    
    

提交回复
热议问题