How to target specific handlers with a @ControllerAdvice @ModelAttribute?

前端 未结 2 1694
别跟我提以往
别跟我提以往 2021-01-15 15:31

I\'d like to display a warning message on specific pages 5 minutes prior to a system shutdown. Rather than add it manually to each these pages I created a @ControllerAdvice

2条回答
  •  爱一瞬间的悲伤
    2021-01-15 15:40

    A controller advice can be limited to certain controllers (not methods) by using one of the values of the @ControllerAdvice annotation, e.g.

    @ControllerAdvice(assignableTypes = {MyController1.class, MyController2.class})
    

    If you need to do it on a method level I suggest to take a look at Interceptors.

提交回复
热议问题