1.获取Mybatis逆向工程所需项目。
gitee地址:
[Mybatis逆向工程项目: 该项目用于生成对应的数据库表的mapper映射文件和pojo实体类]:
2.IDEA打开该项目,找到generatorConfig.xml配置文件,进行如下修改:
<1>修改数据库连接的信息:驱动类、连接地址、用户名、密码。
<jdbcConnection
driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/数据库名?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true"
userId="xxxx"
password="xxxx">
</jdbcConnection>
以上四个连接数据库必须的属性,按照自己数据库来做响应设置
<2>修改生成的pojo实体类的位置(我这里是com.msn.pojo,按照自己项目需求设置)
<javaModelGenerator targetPackage="com.msn.pojo"
targetProject=".\src">
<3>修改mapper映射文件生成位置(我这里是com.msn.mapper,按照自己项目需求设置)
<sqlMapGenerator targetPackage="com.msn.mapper"
targetProject=".\src">
<4>修改mapper接口生成的位置(mapper映射文件和mapper接口需在同一个包下,所以我这里设置为:com.msn.mapper)
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.msn.mapper"
targetProject=".\src">
<5>设置需要生成mapper映射文件、mapper接口和Pojo实体类的数据库表(我这里只设置了三张表,根据自己项目需求来即可)
<table schema="" tableName="admin"></table>
<table schema="" tableName="product_info"></table>
<table schema="" tableName="product_type"></table>