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文件了!
參考:
