当前位置:   article > 正文

使用idea快速搭建一个springboot项目(遇到的小坑)_idea创建spring boot项目出现不了包名

idea创建spring boot项目出现不了包名

作为一个开发经验一年半的Java小学生,对于springboot还处于使用,并没有自己搭建过,此处记录一下自己搭建springboot项目的过程及踩过的坑。(此项目是springboot+MySQL+mybatis)

1.打开idea-new-project,选择spring initializr,这就是创建一个spring boot项目,然后next,下一步

2.设置文件包名以及项目名

3.设置好之后继续next,下一步,web项目选择这里并勾选上

此处可同时选上MySQL和mybatis的功能(Oracle和其他数据库根据自己需要自行勾选,此处只做演示),如图:

4.这里就是最后一步,直接finish就好了

5.项目结构如下

6.pom.xml文件根据个人使用具体设置,练手的可以选择先不设置后期根据需要添加,设置maven,刷新jar包

maven我现在用的配置文件内容如下:挺快的,仅供参考

  1. <mirror>
  2. <id>alimaven</id>
  3. <name>aliyun maven</name>
  4. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  5. <mirrorOf>central</mirrorOf>
  6. </mirror>
  7. <mirror>
  8. <id>alimaven</id>
  9. <mirrorOf>central</mirrorOf>
  10. <name>aliyun maven</name>
  11. <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
  12. </mirror>
  13. <mirror>
  14. <id>ibiblio</id>
  15. <mirrorOf>central</mirrorOf>
  16. <name>Human Readable Name for this Mirror.</name>
  17. <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  18. </mirror>
  19. <mirror>
  20. <id>jboss-public-repository-group</id>
  21. <mirrorOf>central</mirrorOf>
  22. <name>JBoss Public Repository Group</name>
  23. <url>http://repository.jboss.org/nexus/content/groups/public</url>
  24. </mirror>
  25. <mirror>
  26. <id>central</id>
  27. <name>Maven Repository Switchboard</name>
  28. <url>http://repo1.maven.org/maven2/</url>
  29. <mirrorOf>central</mirrorOf>
  30. </mirror>
  31. <mirror>
  32. <id>repo2</id>
  33. <mirrorOf>central</mirrorOf>
  34. <name>Human Readable Name for this Mirror.</name>
  35. <url>http://repo2.maven.org/maven2/</url>
  36. </mirror>

7.启动项目,直接点击该类的run即可

8.写一个接口测试一下,此处有个小坑,注解使用@RestController才行,使用@controller会出现404,且@RestController注解是个聚合注解,已包含@controller,值得注意的是,当我们使用Spring Boot 2.0 想要返回页面而不是提供json或者xml数据接口的时候,切记不能再使用@RestController了,只能使用@Controller.因为 @RestController注解里还整合了@ResponseBody注解,启动成功后会显示端口号;

9.在浏览器输入http://localhost:8080/demo/index,看到下面场景说明一个简单的springboot项目已经搭建好

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/778658
推荐阅读
相关标签
  

闽ICP备14008679号