mabatis逆向工程

本文使用idea编译器,安装Mybatisplus插件后可以使用逆向工程。

配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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>

<classPathEntry location="C:/Users/34924/Desktop/mysql-connector-java-5.1.46.jar"/>
<context id="context" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="false"/>
</commentGenerator>


<!--<jdbcConnection userId="root" password="123456" driverClass="com.mysql.jdbc.Driver"-->
<!--connectionURL="jdbc:mysql://localhost:3306/sss"/>-->

<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>

<javaModelGenerator targetPackage="org.model" targetProject=".">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>


<sqlMapGenerator targetPackage="org.mapper" targetProject=".">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>

<javaClientGenerator targetPackage="org.mapper" type="MIXEDMAPPER" targetProject=".">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>

<table schema="sn349245467" tableName="polls_question" enableCountByExample="false" enableDeleteByExample="false"
enableUpdateByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
<table schema="sn349245467" tableName="polls_choice" enableCountByExample="false" enableDeleteByExample="false"
enableUpdateByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>

注意:jdbc版本最好用5.x左右的,targetRuntime使用Mybatis3,使用简略版的会少东西。javaClientGenerator的type选用MIXEDMAPPER。

使用了逆向工程后,在一对多等关系的时候,需要把默认的查找方式由select param1,param2,…改为select *,以及改resultMap的BaseResultMap。

-------------本文结束 感谢您的阅读-------------