解決在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文件了!

參考:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM