1.安装SpringBooT插件
(1)在打开help—>marketplace
(2)安装完成sprongboot插件后重启eclipse。
2.新建工程
(1)打开file
(2)在输入框中输入Spring找到SpringBoot
(3)在输入框中输入项目名称
(4)选择框架
(5)点击filsh完成创建
3.创建完工程直接启动项目可能出现的异常:
(1)Eclipse下“找不到或无法加载主类”的错误
(2)java.lang.UnsupportedClassVersionError: com/example/demo/SpringbootMybatisDemoApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0:是因为jvm与jdk版本不一致所导致的
解决办法:右击项目–>properties–>java compiler,将jvm和jdk使用相同版本
(3)启动失败
这是因为添加了数据库组件,所以autoconfig会去读取数据源配置,而新建的项目还没有配置数据源/URL地址错误,所以会导致异常出现。
解决方案:
在启动类的@EnableAutoConfiguration @SpringBootApplication 中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。
4.整理项目目录
(1).手动创建项目包编写代码
(2).自动生成项目包
(1)安装mybatis generator插件
(2)在pom文件中添加反向工程插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
(3)添加配置文件generatorConfig.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>