spring boot用ide新建項目遇到的restcontroller不能導入的問題

纔開始學習spring boot,第一個程序helloworld就碰到@RestController和@RequestMapping(/hello)的註解都會報錯的問題。 

我個人的解決方法:

1.springboot默認有

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
    </dependency>

</dependencies>
這時要引入Web模塊,需在pom.xml添加spring-boot-starter-web模塊

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

2. 然後用maven reimport 更新下依賴包。

3.Invalidate and restart 重啓下。

4.我使用intellj idea,這時重啓後的編輯器會自動提示要按alt+enter。如果不提示,就手動引入

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
應該就好了。  

希望新手不要被再調入這個坑了。嚴重打擊新手對java和spring學習的動力。

發佈了17 篇原創文章 · 獲贊 0 · 訪問量 775
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章