1. Controller
@Controller
public class myViewController{
@RequestMapping("myMainPage") public void myMainPage(Model model){
model.addAttribute("logoImg", "site_logo.png");
}
}
2. Aspect
@Around("execution(* com.gas..controller.*Controller.*(..))")
public Object checkAuth(ProceedingJoinPoint joinPoint) throws Throwable{
// this aspect is check "Auth Level" before view Controller running
// if "User Auth Level" is lower then return error page(new ModelAndView("error");)
// ... auth Level check
Object resultObject = null;
if (authLevel > 0){
resultObject = joinPoint.proceed();
} else {
// permission denied
resultObject = new ModelAndView("error");
}
}
3. Test
My expectation is that I should see an error page, but... it didn't work(I can see mainPage)
always show mainPage
why is not worked when return type is void?
is works, LOL... but I don't understand difference void and modelAndView
help teach me.
4. Solution
@Controller
public class myViewController{
@RequestMapping("myMainPage") public ModelAndView myMainPage(Model model){
model.addAttribute("logoImg", "site_logo.png");
return new ModelAndView("myMainPage");
}
}