Comment on the value of the post checkbox multi-choice box (hidden domain mode) and springmvccheckbox in SpringMVC

Source: Internet
Author: User
Tags button type

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.