超级简单的通用mapper (MavenWeb工程)
前提是ssm整合完成才能使用
1、在pom中引入插件和jar
在build标签中引入
<!--mybais逆向工程的插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!--允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 自动生成的配置,${basedir}表示项目根目录 ,configurationFile默认在resource目录下-->
<!--<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>-->
</configuration>
<dependencies>
<!--内部依赖,只为当前插件服务-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.14</version>
</dependency>
</dependencies>
</plugin>
在resources文件夹下创建一个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>
<!--这个路径就是你maven仓库中的mysql的jar包路径 直接复制过来就行-->
<classPathEntry location="A:\\B\\java\\maven\\apache-maven-3.6.3-1\\mysql\\mysql-connector-java\\5.1.14\\mysql-connector-java-5.1.14.jar"/>
<context id="mybatisGenerator" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息(数据源):驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/114project?characterEncoding=utf8&useSSL=true"
userId="root"
password="root">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.ssm.entity"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.ssm.mapper"
targetProject=".\src\main\resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.ssm.mapper"
targetProject=".\src\main\java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 简单的增删改查以及选择修改 选择新增-->
<!-- tableName 写的是你的数据库字段 domainObjectName写的是你想生成对应实体的名称--?
<table tableName="tab_emp" domainObjectName="TabEmployee"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" ></table>
<table tableName="tab_department" domainObjectName="TabDepartment"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="tab_role" domainObjectName="TabRole"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="tab_account"
domainObjectName="TabAccount"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>