S
S
s2018-07-07 02:27:20
Java
s, 2018-07-07 02:27:20

How to pass post request using Spring MVC methods?

I have a panel in which there are numbers and comboboxes, next to each of them there is a sumbit button.
I need to transfer the selected value from the combobox and the number (let's say id) by clicking on this button.
How can this be implemented with spring mvc method?

Snippet using jstl:

<c:forEach items="${list}" var="user">
                <tr>
                    <td>${user.id}</td>
                    <td>${user.login}</td>
                    <td>${user.email}</td>
                    <td>${user.role}</td>
                    <td><form method="post" action="changerole">
                        <label> Изменить роль на: </label>
                            <select>
                                <c:forEach items="${roles}" var="role">
                                    <option id="role" value="${role.name()}">${role}</option>
                                </c:forEach>
                            </select> <input type="submit" value="Изменить роль"></p>
                        </form></td>
                </tr>
     </c:forEach>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
s, 2018-07-08
@solovladys

In order not to create classes for spring forms, I decided to use ajax and json. Changed all id to classes and sent the following object:

var data=  { 
        "id": $(this).children("input.id").val(),
        "role" : $(this).children("select.role").val()
        };

On the backend received a string using the jackson library - processed the data in the Map and performed the necessary processing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question