zoukankan      html  css  js  c++  java
  • 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学习的动力。

  • 相关阅读:
    css样式的调用方法
    分页的实现 (占个位)
    获取当前脚本的进程PID号
    Mail插件 (占个位 后面补充)
    ovs-vswitchd的启动分析
    OPCServer:使用Matrikon OPC Server Simulation
    OPCServer:使用KEPServer
    Java OPC 代码
    OPC 协议认识
    OPC 技术学习总结
  • 原文地址:https://www.cnblogs.com/hikoukay/p/11405839.html
Copyright © 2011-2022 走看看