【问题标题】:@GetMapping is not getting imported@GetMapping 没有被导入
【发布时间】:2020-09-17 16:15:53
【问题描述】:

Image for clarification 我是 Spring MVC 的新手,我正在 maven 上做这个项目。我试图导入 @GetMapping 但它没有被导入。可能是什么问题?有人可以帮我吗?

<!-- Spring dependencies --!>
        <!-- Spring IOC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>

        <!-- Spring container -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>

        <!-- Spring JDBC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>


        <!-- Spring MVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.3.RELEASE</version>
        </dependency>

【问题讨论】:

  • 应该可以的。但是,如果您是 Spring 新手,您应该从使用 Spring Initializr 生成的项目开始,它会为您的所有依赖项设置适当的版本等,并让您学习编写自己的代码。

标签: java spring maven model-view-controller


【解决方案1】:

你需要描述import org.springframework.web.bind.annotation.GetMapping;like this

Eclipse quick fix 函数很有用。

【讨论】:

  • @yukihane,我照你说的做了,但没用。它带有红色下划线,表示可以导入。我确定我已经使用了所需的依赖项。我用了Ctrl空格自动导入但是也不行
  • org.springframeworkspring-web5.2.6.RELEASE 我修好了通过添加较新的版本。
猜你喜欢
  • 2017-08-10
  • 2018-10-16
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
相关资源
最近更新 更多