逆向工程配置及报错
一 配置
pom文件配置
放在build中即可
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<!--暴露配置文件的位置-->
<configurationFile>GeneratorMapper.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
<!--控制mapper编译后放置的位置-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
GeneratorMapper.xml 需要修改的地方
指定mysql jar包的位置
需要在路径后加上jar包的文件名示例中为 mysql-connector-java-5.1.46.jar
jar包版本过低报错.
<!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
<classPathEntry location="D:\mysql-connector-java-5.1.46.jar"/>
数据库连接信息配置
1.IP地址 端口号 被连接的数据库名 账号 密码
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.19.129:3306/springboot"
userId="root"
password="root">
</jdbcConnection>
数据库连接信息配置
被逆向生成的表 tableName="t_user
逆向后生成的类名 domainObjectName="User"
<table tableName="t_user"
domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
其它
1 给所有逆向生成的实体类实现序列化接口
public class User implements Serializable
2 让实体类被spring管理
1.在实体类上加@Mapper
注解
@Mapper
public class User implements Serializable
2.在主程序入口加包扫描注解,多个包用逗号分隔开即可
@MapperScan(basePackages = {"com.springboot.mapper","com.springboot.mapper2"})