如何实现controller接口跳转到另一个controller接口

这篇文章主要介绍如何实现controller接口跳转到另一个controller接口,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

controller接口跳转到另一个controller接口

@RestController
@RequestMapping("/aaa")
public class TestController{
	 @RequestMapping("/test1")
    public ModelAndView test1(HttpServletResponse response) {
    	ModelAndView view = new ModelAndView();
    	 view.setViewName("redirect:/aaa/test2");
		//        try {
		//            response.sendRedirect("/test2");
		//        } catch (IOException e) {
		//            e.printStackTrace();
		//        }
    	 return view ;
    }
     @RequestMapping("/test2")
    public ModelAndView test2() {    	
    	System.out.println("this is test2");
    }
}

Controller中调用另一个Controller的方法问题

1、不可以直接以类的方式调用

2、可以通过url 转发的方式,传递到另外一个Controller类中运行

3、在Controller 中注入的 service,如果直接用来作为实例变量传递会报空值

4、注意Controller 层不处理繁杂的逻辑,逻辑当交给Service层处理

5、静态资源映射,也就是静态资源放行,在前端控制器 拦截为 "/" 时,需要对.js, .jpg, .css 等静态资源放行

6、/*,会造成jsp,js,jpg,。。。都被拦截,无法执行,一般不采用

以上是“如何实现controller接口跳转到另一个controller接口”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!