命令
mybatis-generator:generate
和spring-mvc.xml同路径下加入generatorConfig.xml文件
以下generatorConfig.xml
<?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>
<!--数据库驱动jar -->
<!-- <classPathEntry location="D:\tomcat\lib\mysql-connector-java-5.1.5.jar" /> -->
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--去除注释 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/databasename?useSSL=false" userId="root" password="123456">
</jdbcConnection>
<!--默认false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建 使用Maven生成在target目录下,会自动创建) -->
<javaModelGenerator targetPackage="com.javen.model" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成SQLMAP文件 -->
<sqlMapGenerator targetPackage="com.javen.mapping" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现 context id="DB2Tables" 修改targetRuntime="MyBatis3" -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.javen.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 对应数据库表 mysql可以加入主键自增 字段命名 忽略某字段等 -->
<table tableName="care" domainObjectName="CAREsh" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"
delimitIdentifiers="true">
<property name="useActualColumnNames" value="true" />
</table>
<!-- <table tableName="article" domainObjectName="Article" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_order" domainObjectName="Order" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_news" domainObjectName="News" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_patient" domainObjectName="Patient" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_message" domainObjectName="Message" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_manager" domainObjectName="Manager" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_idtype" domainObjectName="Idtype" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_doctor" domainObjectName="Doctor" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
<!-- <table tableName="t_department" domainObjectName="Department" enableCountByExample="false" -->
<!-- enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" -->
<!-- delimitIdentifiers="true"> -->
<!-- <property name="useActualColumnNames" value="true" /> -->
<!-- </table> -->
</context>
</generatorConfiguration>
在pom最下面的标签里引入mybatis
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>Generate MyBatis Files</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate</phase>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
</plugin>
以上为学习期间整理的学习笔记