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接口的实现】以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

    推荐阅读