package com.example.web.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalException {

    @ExceptionHandler({com.example.exception.UserException.class})
    public String userException(Exception e , Model model){
        System.out.println(e.getMessage());
        System.out.println("------------------------------");
        model.addAttribute("msg",e.getMessage());
        return "login";
    }
    /*
    * 从定向不经过视图解析器
    * */
    @ExceptionHandler({java.lang.Exception.class})
    public String exceptionHandle(Exception e){
        return "redirect:/page/error";
    }

}
