Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

java - Spring MVC, forward

Is there any difference between

public class Controller1 extends AbstractController {
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        return new AnotherController().handleRequest(request, response);
    }
}

and

@Controller
public class Controller1 {

    @RequestMapping ...
    public String handleRequest() {
        return "forward:/path_to_my_another_controller";
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By creating controllers yourself, you will prevent Spring from injecting any dependencies into them. This may cause your self-created controllers to not work correctly.

If you really need to chain controllers like this, I would ask the Spring application context for an instance of the controller you want instead of creating one with the new operator.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...