赞
踩
作为一个开发经验一年半的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我现在用的配置文件内容如下:挺快的,仅供参考
- <mirror>
- <id>alimaven</id>
- <name>aliyun maven</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
- <mirrorOf>central</mirrorOf>
- </mirror>
- <mirror>
- <id>alimaven</id>
- <mirrorOf>central</mirrorOf>
- <name>aliyun maven</name>
- <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
- </mirror>
-
- <mirror>
- <id>ibiblio</id>
- <mirrorOf>central</mirrorOf>
- <name>Human Readable Name for this Mirror.</name>
- <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
- </mirror>
- <mirror>
- <id>jboss-public-repository-group</id>
- <mirrorOf>central</mirrorOf>
- <name>JBoss Public Repository Group</name>
- <url>http://repository.jboss.org/nexus/content/groups/public</url>
- </mirror>
-
- <mirror>
- <id>central</id>
- <name>Maven Repository Switchboard</name>
- <url>http://repo1.maven.org/maven2/</url>
- <mirrorOf>central</mirrorOf>
- </mirror>
- <mirror>
- <id>repo2</id>
- <mirrorOf>central</mirrorOf>
- <name>Human Readable Name for this Mirror.</name>
- <url>http://repo2.maven.org/maven2/</url>
- </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项目已经搭建好
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。