Home Web Front-end JS Tutorial How to get the value of the multi-select box value in a post in SpringMVC (code example)

How to get the value of the multi-select box value in a post in SpringMVC (code example)

Jun 12, 2018 pm 08:20 PM
post springmvc Checkbox

Now I will share with you an article about the value of the post checkbox multi-select box value in SpringMVC (hidden field method). It has a good reference value and I hope it will be helpful to everyone.

I pass the value of the checkbox multi-select box to the backend through a string. First, I call js to traverse the selected checkbox to obtain the selected box value, then write it into the hidden field, and finally write the composition object. Property submission. See code: `

Frontend:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<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">//实际存储的值,此处隐藏

      <p class="form-group" hidden>

       <form:input path="id" name="id" cssClass="form-control"></form:input>

      </p>

     </spring:bind>

     <spring:bind path="accessControl">//实际存储的值,此处隐藏

      <p class="form-group" hidden>

       <form:input path="accessControl" name="accessControl" cssClass="form-control"></form:input>

      </p>

     </spring:bind>

     <input type=&#39;button&#39; value=&#39;确定&#39; onclick="fun()"/>//调用脚本,给需要post的数据赋值

     <p class="form-group">

      <button type="submit" class="btn btn-primary">保存</button>

      <a class="btn btn-success pull-right" href="/user/list" rel="external nofollow" >返回</a>

     </p>

 </form:form>

Copy after login

Script:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

<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 + &#39;,&#39;;

   }

  }

  $("#accessControl").val(str)

//  alert(atr);

//  alert(val);

 }

</script>

Copy after login

Backend:

1

2

3

4

5

6

7

@RequestMapping(value = "editaccesscontrol", method = RequestMethod.POST) //后端方法,

public String editAccessControlPost(User user,ModelMap model ) {//接收参数对象user

 userMapper.updateUserAccessControl(user);

 model.addAttribute("user",user);

 model.addAttribute("success", "权限修改成功");

 return "redirect:/user/editaccesscontrol?id="+user.getId();

}

Copy after login

The above article briefly talks about the post checkbox multi-select box value in SpringMVC (hidden field method) is what I share with you. All the content

Related articles:

How to upload and compress images in js (detailed tutorial)

How to use vue Implementing CSS transition effects

How to use WeChat applet to implement image upload function

The above is the detailed content of How to get the value of the multi-select box value in a post in SpringMVC (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1654
14
PHP Tutorial
1252
29
C# Tutorial
1225
24
Comparison and difference analysis between SpringBoot and SpringMVC Comparison and difference analysis between SpringBoot and SpringMVC Dec 29, 2023 am 11:02 AM

SpringBoot and SpringMVC are both commonly used frameworks in Java development, but there are some obvious differences between them. This article will explore the features and uses of these two frameworks and compare their differences. First, let's learn about SpringBoot. SpringBoot was developed by the Pivotal team to simplify the creation and deployment of applications based on the Spring framework. It provides a fast, lightweight way to build stand-alone, executable

How to use python requests post How to use python requests post Apr 29, 2023 pm 04:52 PM

Python simulates the browser sending post requests importrequests format request.postrequest.post(url,data,json,kwargs)#post request format request.get(url,params,kwargs)#Compared with get request, sending post request parameters are divided into forms ( x-www-form-urlencoded) json (application/json) data parameter supports dictionary format and string format. The dictionary format uses the json.dumps() method to convert the data into a legal json format string. This method requires

How does java initiate an http request and call the post and get interfaces? How does java initiate an http request and call the post and get interfaces? May 16, 2023 pm 07:53 PM

1. Java calls post interface 1. Use URLConnection or HttpURLConnection that comes with java. There is no need to download other jar packages. Call URLConnection. If the interface response code is modified by the server, the return message cannot be received. It can only be received when the response code is correct. to return publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

How to use Vue to implement multi-select boxes and radio buttons How to use Vue to implement multi-select boxes and radio buttons Nov 07, 2023 am 11:42 AM

How to use Vue to implement multi-select boxes and radio buttons Vue is a popular JavaScript framework that is widely used in web development. In Vue, we can easily implement various interactive effects, including multi-select boxes and radio button boxes. This article will introduce how to use Vue to implement multi-select boxes and radio buttons, and provide specific code examples. Implementing a multi-select box A multi-select box is used to allow the user to select multiple options. In Vue, we can use the v-model directive to implement two-way data binding of multi-select boxes. Here is a simple example

A brief analysis of the POST method in PHP with parameters to jump to the page A brief analysis of the POST method in PHP with parameters to jump to the page Mar 23, 2023 am 09:15 AM

For PHP developers, using POST to jump to pages with parameters is a basic skill. POST is a method of sending data in HTTP. It can submit data to the server through HTTP requests. The jump page processes and jumps the page on the server side. In actual development, we often need to use POST with parameters to jump to pages to achieve certain functional purposes.

The relationship between multi-select box check and select all function in Vue document The relationship between multi-select box check and select all function in Vue document Jun 21, 2023 am 09:33 AM

With the continuous development and advancement of front-end technology, the application of the Vue framework is becoming more and more popular. In practical applications of Vue, the functions of checking multiple boxes and selecting all are often used. In the Vue documentation, the implementation methods of checking multiple selection boxes and selecting all are also very detailed. Multi-select box in Vue In Vue, the implementation method of multi-select box is very simple. You only need to use &lt;inputtype="checkbox"&gt; where you need to use multi-select box. When multiple selections need to be made

How to determine whether a post has been submitted in PHP How to determine whether a post has been submitted in PHP Mar 21, 2023 pm 07:12 PM

PHP is a widely used server-side scripting language that can be used to create interactive and dynamic web applications. When developing PHP applications, we usually need to submit user input data to the server for processing through forms. However, sometimes we need to determine whether form data has been submitted in PHP. This article will introduce how to make such a determination.

How to implement PHP to jump to the page and carry POST data How to implement PHP to jump to the page and carry POST data Mar 22, 2024 am 10:42 AM

PHP is a programming language widely used in website development, and page jumps and carrying POST data are common requirements in website development. This article will introduce how to implement PHP page jump and carry POST data, including specific code examples. In PHP, page jumps are generally implemented through the header function. If you need to carry POST data during the jump process, you can do it through the following steps: First, create a page containing a form, where the user fills in the information and clicks the submit button. Acti in the form

See all articles