阅读723 返回首页    go 阿里云 go 技术社区[云栖]


Maven项目创建mybatis generator步骤


Maven项目创建mybatis generator


1.参考资料中说的

<dependency>

<groupId>org.mybatis.generator</groupId>


<artifactId>mybatis-generator</artifactId>


<version>1.3.2</version>


</dependency>
这个没必要使用,使用了会一直下载不到jar 报错

2.

mysql-connector-java的jar如果是使用6.0.5版本会报错,建议降低版本到5.1.39(本地mysql server是5.7.18)

3.

generatorConfig.xml这个文件需要配对targetProject路径

4.pom文件:


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion></modelVersion>

<groupId></groupId>
<artifactId></artifactId>
<version></version>


<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency>

</dependencies>


<build>
<finalName></finalName>
<plugins>
<plugin>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<configuration>
<verbose></verbose>
<overwrite></overwrite>
</configuration>
</plugin>
</plugins>
</build>

</project>






5.generatorConfig.xml文件:


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "https://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 指定数据连接驱动jar地址 -->
<classPathEntry
location="/Users/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar" />
<!-- 一个数据库一个context -->
<context id="context" defaultModelType="flat" targetRuntime="MyBatis3">
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="false" /><!-- 是否取消注释 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
</commentGenerator>
<!-- jdbc连接 --> <!--jdbc:mysql://xxxxxxx:8406/CL_DEMO?useUnicode=true&amp;characterEncoding=UTF-8-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/cms?useUnicode=true&amp;characterEncoding=UTF-8" userId="root"
password="newpass" />

<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="com.cd.dao.pojo"
targetProject="src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
<!-- 是否针对string类型的字段在set的时候进行trim调用 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- 生成mapxml文件 -->
<sqlMapGenerator targetPackage="com.cd.dao.mapper"
targetProject="src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>

<!-- 生成mapxml对应client,也就是接口dao -->
<javaClientGenerator targetPackage="com.cd.dao.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>

<table schema="cms" tableName="application_permission"
domainObjectName="ApplicationPermission" selectByExampleQueryId="false"
enableCountByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" enableUpdateByExample="false"
enableDeleteByPrimaryKey="false" />


</context>


</generatorConfiguration>





6.参考资料:

https://www.tuicool.com/articles/NBnUr2E

https://www.cnblogs.com/smileberry/p/4145872.html

最后更新:2017-06-29 09:02:15

  上一篇:go  Java语言零基础菜鸟入门, Java程序学习的要点
  下一篇:go  6月28日云栖精选夜读:重要通知|针对新一轮比特币勒索蠕虫病毒的安全建议