新建springBoot+mybatis Demo,基于IDEA
1、新建springboot项目
1.1、文件-新建项目-Spring Initialzr,下一步
Group Id、Artifact Id、Project name等可根据实际情况填写,下一步。
web选择spring web
Template Engines选择 Thymeleaf
SQL选择Spring Data JPA、MySQL Driver、MyBatis Famework,下一步,
项目位置及项目名称可按实际情况填写,然后点击完成,等待IDEA配置项目中所需要的jar包
2、等待项目中的jar包加载完成后创建自己的第一个demo
springboot启动类DemoApplication,这里在注解@SpringBootApplication中添加了一个
在项目目录下新建controller包,再新建一个controller类
运行DemoApplication就可以显示自己的第一个demo了
3、创建过程中遇到了问题:
3.1、数据库未连接,导致报如下错误:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
解决方式,比较直接,在启动类的注解中添加:@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)如图,即可:
3.2、启动完成后,在浏览器中输入:http://localhost:8080报错
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
原因:1、地址写错:应该写成:http://localhost:8080/index
2、在启动类的注解中添加了如下内容:scanBasePackages = “controller”
结尾:整体的过程不是很难,百度解决大部分问题0^0