简体   繁体   中英

What is the order of executing @ModelAttribute and @InitBinder in spring mvc?

if i have code like this:

@InitBinder
protected void initBinder(WebDataBinder binder){

}
@ModelAttribute
protected User initModel(){

}

which one will be executed first?

spring documentation said that @InitBinder annotated method can accept any argument @RequestMapping annotated method can have except command object, does that mean it accept @ModelAttribute argument? can i have a code like this:

@ModelAttribute
protected User initModel(){

}
@InitBinder
protected void initBinder(WebDataBinder binder, @ModelAttribute User user){

}

where a generated model attribute injected in initBinder method?

Thanks

@ModelAttribute
void init() {
    LOGGER.error("init @ModelAttribute");
}

@InitBinder
void initBinder() {
    LOGGER.error("init @InitBinder");
}

Output 12:48:06.357 [main] ERROR rest.controller.TestController - init @InitBinder

12:48:07.341 [main] ERROR rest.controller.TestController - init @ModelAttribute

12:48:07.388 [main] ERROR codixrest.controller.TestController - init @InitBinder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM