解決在IDEA中"Cannot find declaration to go to"的問題
阿新 • • 發佈:2020-09-01
1.Ctrl+滑鼠左鍵
在IDE工具中,我們經常使用Ctrl+滑鼠左鍵來檢視一個東西。
藉助檢視解析器org.springframework.web.servlet.view.InternalResourceViewResolver
,根據請求跳轉到指定頁面。
<!-- springDispatcherServlet-servlet.xml --> <!-- 配置檢視解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean>
@RequestMapping("/index")
public String index(){
return "index"; // 跳轉到index.jsp頁面
}
在IDEA中,按Ctrl+滑鼠左鍵點選return "index";
中的index
,會開啟index.jsp
檔案。
但是,這裡遇到了Cannot find declaration to go to的問題。
2.解決問題
在開啟IDEA時,出現了以下提示。
考慮到跳轉頁面是檢視解析器的作用,而檢視解析器需要在Spring的配置檔案中配置。猜測出現Cannot find declaration to go to
新增Spring Module之後,這裡就沒有Unmapped Spring configuration files這個提示了。
更重要的是,按Ctrl+滑鼠左鍵點選
return "index";
中的index
,也可以開啟index.jsp
檔案了!
參考: