1. 程式人生 > 實用技巧 >解決在IDEA中"Cannot find declaration to go to"的問題

解決在IDEA中"Cannot find declaration to go to"的問題

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

這個問題的原因是IDEA不識別正在點選的東西是什麼,於是嘗試解決這裡提示的問題。

新增Spring Module之後,這裡就沒有Unmapped Spring configuration files這個提示了。

更重要的是,按Ctrl+滑鼠左鍵點選return "index";中的index,也可以開啟index.jsp檔案了!

參考: