修改插件配置文件,并逆向工程(如GoodsInfo表和AdminInfo表)
右键自己的项目 -> 选择New -> 选择other
出现如下页面
点击Finish
创建好之后效果
第二步: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>
<context id="sqlserverTables" targetRuntime="MyBatis3">
<!-- 生成的pojo,将implements Serializable-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/community?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&nullCatalogMeansCurrent = true"
userId="root"
password="123456">
</jdbcConnection>
<!--
默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer
true,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal
-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--
生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java,
也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下
-->
<!--<javaModelGenerator targetPackage="com.joey.mybaties.test.pojo" targetProject="MAVEN">-->
<javaModelGenerator targetPackage="com.czc.entity" targetProject="javaweb05/src/">
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--对应的mapper.xml文件 -->
<sqlMapGenerator targetPackage="mappers" targetProject="javaweb05/src/">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 对应的Mapper接口类文件 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.czc.dao" targetProject="javaweb05/src/">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 列出要生成代码的所有表,这里配置的是不生成Example文件 -->
<table tableName="db45" domainObjectName="Db45"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
<property name="useActualColumnNames" value="false"/>
</table>
</context>
</generatorConfiguration>
修改配置文件
community是你的数据库表名
root是数据库用户名
123456是数据库密码
继续修改配置文件
com.czc.entity是实体存放目录
javaweb05是我的项目名称
mappers是数据库mapper文件存放目录
com.czc.dao是数据库接口目录
再继续修改配置文件
db45是我的数据库表名
Db45是生成java实体类名,为了符合java命名规范,所以第一个字母大写
最后需要在lib目录下添加jar包
jar包下载地址:
链接:https://pan.baidu.com/s/1CGvs-46oZaaCEBfNfyV_GQ
提取码:ycsl
复制这段内容后打开百度网盘手机App,操作更方便哦–来自百度网盘超级会员V4的分享