How to manipulate multiple inputs with same name in Java?

3

How do I manipulate in the backend using multiple input 's with the same name ?

For example:

    <input type='text' name='telefone' ><br>
    <input type='text' name='telefone' ><br>
    <input type='text' name='telefone' ><br>
    <input type='text' name='telefone' >

I tried to get in the method parameter as a array(String[] telefone) but it did not work. I also tried to put [] in name but also did not work.

Ps: I'm using SpringMVC.

    
asked by anonymous 22.06.2016 / 01:52

1 answer

1

I will take into consideration that you are sending this data to the backend using form-data, if so, you can receive a List phones in your controllers, and spring will bind you, however your inputs should follow a notation similar to an array, something like:

    <input type='text' name='telefone[0]' ><br>
    <input type='text' name='telefone[1]' ><br>
    <input type='text' name='telefone[2]' ><br>
    <input type='text' name='telefone[3]' >

In your controller:

    public void salvaTelefones(List<String> telefones) {
      //faz algo.
    }
    
22.06.2016 / 14:26