首先 pom.xml 文件 引入 generator 插件:
<build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.4</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
然后 在目录 src/main/resources 下 新建 文件 generatorConfig.xml, 该文件中的详细配置不做描述,
参考网址: http://blog.csdn.net/isea533/article/details/42102297
生成 model 和 mapper文件之后,整合springBoot框架,启动类Application代码如下:
@SpringBootApplication @MapperScan("com.weidai.testMBG.dao.mapper") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
启动时报错: java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis ...
因为 @MapperScan 的扫描路径: AreaCodeMapper 和 AreaCodeMapper.xml 的包路径 没有统一成 com.weidai.testMBG.dao.mapper 。
由于网络原因,无法提交源码,就放一张项目结构图: