Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
来源:互联网 发布:ubuntu atom 编辑:程序博客网 时间:2024/05/16 13:32
1、IDEA创建maven工程(略)
2、 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件和MySQL数据库驱动依赖
<build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin> </plugins></build><dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.34</version></dependency>
3、在maven项目下的src/main/resources 目录下建立名为 generatorConfig.xml的配置文件,作为mybatis-generator-maven-plugin 插件的执行目标,模板如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration> <!-- 配置mysql 驱动jar包路径.用了绝对路径 --> <classPathEntry location="/Users/wangyongzhi/.m2/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar" /> <context id="wangyongzhi_mysql_tables" targetRuntime="MyBatis3"> <!-- 防止生成的代码中有很多注释,加入下面的配置控制 --> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="suppressDate" value="true" /> </commentGenerator> <!-- 数据库连接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8" userId="root" password="123456"> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 数据表对应的model层 --> <javaModelGenerator targetPackage="me.zhige.domain" targetProject="src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- sql mapper 映射配置文件 --> <sqlMapGenerator targetPackage="me.zhige.mapper" targetProject="src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- mybatis3中的mapper接口 --> <javaClientGenerator type="XMLMAPPER" targetPackage="me.zhige.dao" targetProject="src"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 数据表进行生成操作 schema:相当于库名; tableName:表名; domainObjectName:对应的DO --> <table schema="test" tableName="users" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context></generatorConfiguration>
4、使用maven运行mybatis-generator-maven-plugin插件:工程名->Plugins->mybatis-generator->mybatis-generator:generate->Run Maven Build
5、自动生成的结构如下:
阅读全文
0 0
- Intellij IDEA中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- Intellij IDEA中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA中使用Mybatis-generator自动生成Mtbatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA中使用MyBatis-generator自动生成MyBatis代码(Oracle)
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- java语言基础(70)——集合框架(泛型高级之通配符)
- 删除root密码重启后卡住
- ffmpeg解码H.264视频数据,MFC播放视频
- [Docker-集成] Docker、Jenkins
- 第5章 理解remoteview
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- 一种新的移动APP保持登陆的实现机制介绍
- Kafka的producer案例,Kafka的consumer案例
- Nginx优化
- 如何正确理解api网关
- slidingmenustyle侧拉和主题日夜切换
- 数据库
- fatal error C1189: #error : "No Target Architecture"
- 单引号,双引号,三单引号,三双引号