利用mybatis-generator自动生成代码
一、在pom.xml中添加plugin
其中generatorConfig.xml的位置,自行调整。
二、generatorConfig.xml配置文件
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
password="***"/>enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
几个要点:
a) 因为生成过程中需要连接db,所以第3行指定了驱动jar包的位置
b) 15-17行为连接字符串
c) 19-33行指定生成“entity实体类、mybatis映射xml文件、mapper接口”的具体位置
d) 40-46行为具体要生成的表,如果有多个表,复制这一段,改下表名即可
三、使用方式
mvn mybatis-generator:generate
如果是在intellij 环境,直接鼠标点击即可