概述
1.话不多说,我们创建一个工程........
2.拷贝pom文件, 里面需要手动配置生成文件的目录,,,,,,记住了,,,
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<targetJavaProject>${basedir}/src/main/java</targetJavaProject>
<targetMapperPackage>cn.csdn.mapper</targetMapperPackage>
通用mapper,生成的文件位置
<targetModelPackage>cn.csdn.pojo</targetModelPackage>
pojo生成的文件目录
<!--
XML生成路径
-->
<targetResourcesProject>${basedir}/src/main/resources</targetResourcesProject>
<targetXMLPackage>mapper</targetXMLPackage>
<!--
依赖版本
-->
<mapper.version>3.4.6</mapper.version>
<mysql.version>5.1.29</mysql.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
3.在resources创建目录以及文件,
4.配置genertorConfig.xml 配置文件,
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPEgeneratorConfiguration PUBLIC"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <properties resource="config.properties"/> <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!--支持序列化--> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <plugin type="${mapper.plugin}"> <property name="mappers" value="${mapper.Mapper}"/> <property name="forceAnnotation" value="${mapper.forceAnnotation}" /> </plugin> <jdbcConnection driverClass="${jdbc.driverClass}" connectionURL="${jdbc.url}" userId="${jdbc.user}" password="${jdbc.password}"> </jdbcConnection> <javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/> <sqlMapGenerator targetPackage="${targetXMLPackage}" targetProject="${targetResourcesProject}"/> <javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}" type="XMLMAPPER"/> <table tableName="%"> <generatedKey column="id" sqlStatement="Mysql" identity="true"/> </table> </context> </generatorConfiguration>5.resources目录增加config.properties文件,
# 数据库配置 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis jdbc.user=root jdbc.password=1039191520 # 通用Mapper固定配置 mapper.plugin=tk.mybatis.mapper.generator.MapperPlugin mapper.Mapper=tk.mybatis.mapper.common.Mapper mapper.forceAnnotation=true
6.最后运行命令,
mybatis-generator:generate
7.错误解决:我运行后,只在resource目录下生成了mapper配置文件,并没有生成mapper 接口啊,啥的, 解决方案步骤如下 1.手动创建一个java目录
2.
最后就生成成功啦,如果还有问题的话,留言出问题所在,
最后
以上就是轻松香水为你收集整理的maven逆向工程生成myBatis代码,pojo有jpa注解的全部内容,希望文章能够帮你解决maven逆向工程生成myBatis代码,pojo有jpa注解所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复