1

The requirement is letting users to upload a list of tickets with something like:

@RequestMapping(value="/tickets", method=RequestMethod.POST)
public void uploadTickets(
            @RequestBody List<Ticket> tickets) {
        // Do something with the list of tickets
    }

I know how to upload a single ticket. I just need to create a html form with three fields (section, row, seat) and a submit button. Then spring will automatically convert the uploaded form to a Ticket object. But I am not sure how to upload a list of Tickets with Spring controllers. Any help? Thanks!

2
  • You mean uploading a list from a client side, instead of a single ticket? Commented May 31, 2015 at 20:27
  • @Arpit Yes exactly. I don't know how to write the client side code and make spring support it. Commented May 31, 2015 at 21:05

2 Answers 2

1

This depends on your configuration. Assuming a normal spring configuration.

You normally upload a single ticket with a json request

{ "section":"", "seat":"", "row":"" }

To get the list of tickets, just use a json array.

[
    { "section":"", "seat":"", "row":"" },
    .......,
    { "section":"", "seat":"", "row":"" }
]

To get the data into this format, it of course depends on the front end. You might need to do some javascript on the frontend to get it into this format.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer. I think it will work. However do you think there is a javascript free solution?
Without JavaScript, I think you need to bind your input elements like tickets[0].id, tickets[0].name etc which associate to first Ticket in list and tickets[1].id, tickets[1].name etc which associate to second Ticket.
0

you can just put it in model object and get the data from the model object as given below example

@RequestMapping(value="/tickets", method=RequestMethod.POST)
    public String uploadTickets(Map<String, Object> model) {

    Ticket t = new Ticket();   
    model.put("ticket", t);
    return "page";//return page or redirect.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.