命令+mybatis-generator插件自动生成Mapper映射文件
2017-03-30 14:03
387 查看
自己写各种 *Mapper.xml和 *Mapper.Java,注意各种sql语句中的 id 是否匹配,xml中的namespace是否正确,很麻烦有木有?今天博客内容就是高大上的自动构建~需要的工具包、文件
下面来介绍一下generator.xml
6.可能有的小伙伴会因为编码格式而引发一些错误,我们来看一下下面这种情况怎么解决
改一下编码格式就可以了
下面来介绍一下generator.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> <!-- 数据库驱动包位置 :注意写你自己的包路径--> <!-- <classPathEntry location="D:\software\lib\mysql-connector-java-5.1.21.jar" /> --> <classPathEntry location="E:\mysql-connector-java-5.1.29-bin.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 jdbc\:mysql\://localhost\:3306/cinema--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/cinema" userId="root" password="a"> <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa"> --> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.rindy.cinema.entity" targetProject="E:\src"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject="E:\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.rindy.cinema.mapper" targetProject="E:\src"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成那些表(更改tableName和domainObjectName就可以)这里是生成两张表的映射文件,多表可自行增加,确保你的数据库中已经建好表,并且表名没有写错~ --> <table tableName="filminfo" domainObjectName="FILMINFO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> <table tableName="filmtype" domainObjectName="FILMTYPE" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context></generatorConfiguration>3.上图中的 src是为生成的映射文件新建的空目录,构建成功,该目录下将会有你需要的文件。4.自动生成Mapper映射文件命令:
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite115.下面来看一下我的运行结果:
6.可能有的小伙伴会因为编码格式而引发一些错误,我们来看一下下面这种情况怎么解决
改一下编码格式就可以了
相关文章推荐
- 命令+mybatis-generator插件自动生成Mapper映射文件
- 简单三步快速学会使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件(postgre使用实例)
- Mybatis--使用mybatis generator插件映射数据库,自动生成pojo对象,dao接口,mapper.xml文件的方法
- 使用mybatis-generator自动生成实体类,接口实现类和Mapper映射配置文件
- maven插件mybatis-generator自动生成实体类、mapper.xml、mapper.java文件
- 使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件
- 使用mybatis的generator自动生成po及mapper映射文件
- mybatis-generator-maven-plug生成model、mapper、xml映射文件
- Mybatis-Generator插件自动生成Dao、Model、Mapping相关文件
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件
- Mybatis使用generator自动生成映射配置文件信息
- 使用mybatis的generator自动生成映射文件
- mybatis自动生成mapper,dao,映射文件
- Mybatis中使用mybatis-generator结合Ant脚本快速自动生成Model、Mapper等文件 推荐
- 使用Mybatis Generator结合Ant脚本快速自动生成Model、Mapper等文件的方法
- Mybatis-Generator自动生成映射配置文件和CRUD操作
- Mybatis使用generator自动生成映射配置文件信息
- 使用generator自动生成Mybatis映射配置文件
- Mybatis使用generator自动生成映射配置文件信息