IDEA通过MyBatisgenerator⽣成数据库表的对象
1. File-->New-->Module-->Maven-->Next-->输⼊GroupId、ArtifactId和Version-->Next-->输⼊Module name、Content root和Module file location-->Finish,完成创建。
2. Run/Debug Configurations --> "+"--->Maven--->输⼊Name、Working directory和Command line(mybatis-generator:generate)--->"OK"
3. 在resource⽬录下编辑l⽂件如下:
<!DOCTYPE generatorConfiguration
PUBLIC "-////DTD MyBatis Generator Configuration 1.0//EN"
"/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry location="C:\Users\xxx\.m2\repository\mysql\mysql-connector-java\5.1.22\mysql-conn
ector-java-5.1.22.jar"/>
<!--导⼊属性配置 -->
<context id="default" targetRuntime="MyBatis3">
<property name="javaFileEncoding" value="UTF-8"/>
<jdbcConnection
driverClass="sql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:8080/union?useUnicode=true&characterEncoding=UTF-8"
userId="root"
password="root"
/>
<!-- Model模型⽣成器,⽤来⽣成含有主键key的类,记录类以及查询Example类
targetPackage 指定⽣成的model⽣成所在的包名
targetProject 指定在该项⽬下所在的路径 -->
<javaModelGenerator
targetPackage="com.ity"
targetProject="src/main/java">
<!-- 是否对model添加构造函数 -->
<property name="enableSubPackages" value="true" />
<!-- 给Model添加⼀个⽗类 -->
<!--<property name="rootClass" value="com.itfsw.base"/>-->
</javaModelGenerator>
<!--Mapper映射⽂件⽣成所在的⽬录为每⼀个数据库的表⽣成对应的SqlMap⽂件 -->
<sqlMapGenerator targetPackage="mappings"
targetProject="src/main/resources" />
<!-- 客户端代码,⽣成易于使⽤的针对Model对象和XML配置⽂件的代码
type="ANNOTATEDMAPPER",⽣成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",⽣成基于注解的Java Model 和相应的Mapper对象
idea debugtype="XMLMAPPER",⽣成SQLMap XML⽂件和独⽴的Mapper接⼝ -->
<javaClientGenerator targetPackage="com.guwz.union.dao"
targetProject="src/main/java"
type="XMLMAPPER"/>
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要⾃动⽣成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <table tableName="table">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
</context>
</generatorConfiguration>
View Code
4. run generator配置即可
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论