Когда точно вызывается аннотированный метод @ModelAttribute?

Ниже приведен простой контроллер формы Spring для обработки пользовательских запросов «добавить элемент» :

@Controller
@RequestMapping("/addItem.htm")
public class AddItemFormController {

    @Autowired
    ItemService itemService;

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(ModelMap model) {
        return "addItem";
    }

    @ModelAttribute("item")
    public Item setupItem() {
        Item item = new Item();
        return item;
    }

    @RequestMapping(method = RequestMethod.POST)
    protected String addItem(@ModelAttribute("item") Item item) {
        itemService.addItem(item);
        return "itemAdded";
    }

}

. Я где-то читал, что:(...) the @ModelAttribute is also pulling double duty by populating the model with a new instance of Item before the form is displayed and then pulling the Item from the model so that it can be given to addItem() for processing.

Мой вопрос в том, когда и как часто будет вызываться setupItem()? Будет ли Spring сохранять отдельную копию модели, если пользователь запрашивает несколько элементов добавления?

5
задан gkamal 15 July 2012 в 17:15
поделиться