Comment on the value of the post checkbox multi-choice box (hidden domain mode) and springmvccheckbox in SpringMVC
Here, the value of the checkbox multi-choice box passed in the back end is passed in the string mode. First, call js to traverse the selected checkbox to obtain the selected boxvalue, and then write it into the hidden domain, finally, the attributes of the essay object are submitted. See the code :'
Front end:
<Form: form commandName = "user" method = "post"> <c: forEach items = "$ {deploys}" var = "deploy" varStatus = "deployStatus"> <input type = "checkbox" name = "checkbox" value = "$ {deploy. id} "/>$ {deploy. systemName} <br> </c: forEach> <spring: bind path = "id"> // actual storage value, <div class = "form-group" hidden> <form: input path = "id" name = "id" cssClass = "form-control"> </form: input> </div> </spring: bind> <spring: bind path = "accessControl"> // actual stored value, <div class = "form-group" hidden> <form: input path = "accessControl" name = "accessControl" cssClass = "form-control"> </form: input> </div> </spring: bind> <input type = 'button 'value = ''onclick = "fun ()"/> // call the script, assign <div class = "form-group"> <button type = "submit" class = "btn-primary"> Save </button> <a class = "btn-success pull-right" href = "/user/list" rel = "external nofollow"> return </a> </div> </form: form>
Script:
<script type="text/javascript"> function fun() { var boxes = document.getElementsByTagName("input");// var val = [] var str = ""; for (var i = 0; i < boxes.length; i++) { if (boxes[i].name == "checkbox" && boxes[i].checked == true) {// val.push(boxes[i].value); str += boxes[i].value + ','; } } $("#accessControl").val(str)// alert(atr);// alert(val); }</script>
Backend:
@ RequestMapping (value = "editaccesscontrol", method = RequestMethod. POST) // backend method, public String editAccessControlPost (User user, ModelMap model) {// receives the parameter Object User userMapper. updateUserAccessControl (user); model. addAttribute ("user", user); model. addAttribute ("success", "permission modified successfully"); return "redirect:/user/editaccesscontrol? Id = "+ user. getId ();}
In SpringMVC, the value of the post checkbox multi-choice box value (the hidden domain method) is all the content that I have shared with you. I hope to give you a reference, we also hope that you can support the customer's home.