[Java Spring] Apply default Modelttribute values with @ControllerAdivce

@ControllerAdvice
public class DefaultAttributeController {
    // apply default value
    @ModelAttribute("newuser")
    public User getDefaultUser() {
        return new User();
    }
}

After Validation, ModelAttribite will no longer be available. We can use @ControllerAdivce which apply to all the controller to re-set the default values

posted @ 2021-01-13 19:40  Zhentiw  阅读(115)  评论(0编辑  收藏  举报