controller接口跳轉到另一個controller接口的實現(xiàn)
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 轉發(fā)的方式,傳遞到另外一個Controller類中運行
3、在Controller 中注入的 service,如果直接用來作為實例變量傳遞會報空值
4、注意Controller 層不處理繁雜的邏輯,邏輯當交給Service層處理
5、靜態(tài)資源映射,也就是靜態(tài)資源放行,在前端控制器 攔截為 "/" 時,需要對.js, .jpg, .css 等靜態(tài)資源放行
6、/*,會造成jsp,js,jpg,。。。都被攔截,無法執(zhí)行,一般不采用
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Spring Data JPA進行數(shù)據(jù)分頁與排序的方法
這篇文章主要介紹了Spring Data JPA進行數(shù)據(jù)分頁與排序的方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11Spring?@EventListener?異步中使用condition的問題及處理
這篇文章主要介紹了Spring?@EventListener?異步中使用condition的問題及處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12解決?IDEA?Maven?項目中"Could?not?find?artifact"?
這篇文章主要介紹了解決IDEA Maven項目中Could not?find?artifact問題的常見情況和解決方案,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07