mybatis逆向工程使用idea详细介绍
时间: 2023-08-14 20:05:26 浏览: 70
好的,下面详细介绍在IDEA中使用MyBatis逆向工程的具体步骤:
1. 在pom.xml文件中添加MyBatis Generator的依赖:
```xml
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.4.0</version>
</dependency>
```
2. 创建MyBatis Generator的配置文件generatorConfig.xml,并配置数据库连接信息、生成代码的规则等。具体配置可以参考MyBatis官方文档。
3. 在IDEA中打开"Maven Projects"窗口,选择要生成代码的项目,展开"Plugins",找到MyBatis Generator插件。
4. 双击"mybatis-generator:generate",在弹出的"Edit Configuration"中,配置如下:
- Main Class:org.mybatis.generator.api.ShellRunner
- VM options:-Dfile.encoding=UTF-8
- Working directory:$MODULE_DIR$
- Command line:-configfile ${PROJECT_DIR}/src/main/resources/generatorConfig.xml -overwrite
其中,-configfile参数指定了配置文件的路径,-overwrite参数表示覆盖已有文件。
5. 点击"OK"保存配置,再次双击"mybatis-generator:generate",即可生成代码。
执行完毕后,即可在指定的目录下生成Java Bean、Mapper XML及Mapper接口等代码。
另外,如果需要生成代码后自动刷新项目,可以在"Before Launch"中添加"Build",具体步骤如下:
- 点击"Add"添加一个新的Before Launch操作。
- 选择"Build",并选择要执行的"Build Project"操作。
- 点击"OK"保存配置。
这样,在生成代码之后,IDEA会自动编译项目,生成的代码就会显示在项目中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)