Search code examples
springspring-mvcdelete-row

How to do multiple delete in Spring MVC?


I am learning Spring MVC, I am wondering how to delete multiple rows (similar to when you select rows from Yahoo or Gmail then delete them)?


Solution

  • Some homework for you:

    1. Create a form which displays your data in tabular format
    2. Each row contains a checkbox (checkbox name can be "foo"). Checkbox value can be IDs of your data
    3. Create a form object (java bean) which has list of strings List<String> foo. This list will store the ids of selected checkbox
    4. Create a controller which accepts form (see pt. 3) as model object.
    5. On submit of your form (the one on tabular format page > see pt 1) send the POST request to controller (see pt 4). In controller you'll have list of all IDs that user has selected. Now all you need is to delete those from database using some logic (<

    Hope that'll get you started.

    Extra exercise: Read more about Checkboxes, Spring MVC and Binding checkboxes in spring mvc

    P.S. You get code examples only when you try yourself and post some :)