1、生成Mybatis插件,方法很多这里直接在Eclipse marketplaces安装,打开help -- Eclipse marketplace。在search输入:Mybatis,选中mybatis 1.4,这里可以根据需要选择自己的版本,一般使用新版本。
2、新建generatorConfig.xml,位置如下图。这里需要注意:默认是生成注解的方式的,需要添加下面的说明才会生成xml ,targetRuntime="MyBatis3"
完整内容如下:
<?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">
<classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\8.0.21\mysql-connector-java-8.0.21.jar"/>
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection connectionURL="jdbc:mysql://localhost:3306/springdemo?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&serverTimezone=UTC" driverClass="com.mysql.cj.jdbc.Driver" password="123456" userId="luckday" />
<!-- 生成的对象类 -->
<javaModelGenerator targetPackage="com.springstudy.domain" targetProject="springdemo" />
<!-- 生成的xml文件 -->
<sqlMapGenerator targetPackage="com.springstudy.mapper" targetProject="springdemo" />
<!-- 生成的xml文件 -->
<javaClientGenerator targetPackage="com.springstudy.dao" targetProject="springdemo" type="XMLMAPPER" />
<table schema="springdemo" tableName="az_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
3、选择中generatorConfig.xml文件,右键以mybatis运行,即可生成 生成xml、domain、mapper