好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

controller接口跳转到另一个controller接口的实现

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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

@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,。。。都被拦截,无法执行,一般不采用

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/qq_37519791/article/details/89477150

查看更多关于controller接口跳转到另一个controller接口的实现的详细内容...

  阅读:11次