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接口的实现】以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 2020-04-07vue中Axios的封装和API接口的管理
- 调取接口时报404错误(ID:16)
- CICC(脑机接口,科幻几近成真())
- 泰拳居家打卡十九天
- 接口|axios接口报错-参数类型错误解决
- Swift|Swift ----viewController 中addChildViewController
- 190403|190403 - Jmeter压测接口
- JavaScript|vue 基于axios封装request接口请求——request.js文件