eclipse中创建SpringBoot+mybatis

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"?>
(4)使用mybatis generator运行配置文件生成代码 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200726163936497.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80OTY1MTM4NQ==,size_16,color_FFFFFF,t_70)

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值