用Maven中实现MyBatis逆向工程(IDEA版)
2017-11-30 21:17
495 查看
用Maven中实现MyBatis逆向工程(IDEA版)
MyBatis逆向工程介绍
MyBatis逆向工程是指用数据库的表直接生成Java代码,利用MyBatis官方提供的逆向工程,可以针对单表自动生MyBatis执行所需要的代码(如pojo,mapper接口和mapper.xml)。首先
使用idea中的Maven生成MyBatis所需要的mapper类和xml文件,非常方便。首先在IDEA中要有MyBatis的这款插件,它为idea提供mybatis的xml的模版文件、接口类与xml文件对应导航。
安装成功后,在maven的resources文件右击使用mybatis-generator-config模版文件,
内容如下:
<?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> <!--数据库驱动jar包的真实路径 --> <classPathEntry location="C:\Users\Hoictas\.m2\repository\mysql\mysql-connector-java\5.1.32\mysql-connector-java-5.1.32.jar"/> <context id="context" targetRuntime="MyBatis3"> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <commentGenerator> <property name="suppressAllComments" value="false"/> <property name="suppressDate" value="true"/> </commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/db_wechat" userId="tk" password="tk"/> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!--指定包名生成实体类 以及生成的地址 (可以自定义地址,如果路径不存在会自动创建) --> <javaModelGenerator targetPackage="com.mybatis.demo.entity" targetProject=".\src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- !!!! Mapper XML Configurations !!!! --> <sqlMapGenerator targetPackage="com.mybatis.demo.mapper.impl" targetProject=".\src\main\java"> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!-- !!!! Mapper Interface Configurations !!!! --> <javaClientGenerator targetPackage="com.mybatis.demo.mapper" targetProject=".\src\main\java" type="XMLMAPPER"> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <!-- 指定数据库表 --> <table schema="db_wechat" tableName="t_commandcontent" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/> <table schema="db_wechat" tableName="t_automessage" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/> <table schema="db_wechat" tableName="t_command" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/> </context> </generatorConfiguration>
配置简单,没什么难度,再把我的项目结构比对上面的代码,你就知道该怎么根据自己的项目来配置文件。
最后点击右侧的maven project 找到mybatis-generator运行即可。
2017/11/30 19:41:19
相关文章推荐
- eclipse中利用Maven逆向工程生成PO类以及mapper(mybatis)
- IDEA中使用maven创建mybatis的逆向工程
- 使用Maven插件来完成Mybatis逆向工程
- mybatis的逆向工程使用实现
- Mybatis逆向工程的pojo实现序列化接口的代码
- Mybatis逆向工程的pojo实现序列化接口代码
- Idea搭建maven mybatis工程,并实现最简单的数据库连接
- IDEA中用通过maven使用mybatis逆向工程
- maven搭建ssm框架之mybatis逆向工程
- Mybatis逆向工程_使用maven
- Maven下SSM项目整合笔记02:mybatis配置文件以及逆向工程
- Mybatis逆向工程增强版-Maven插件
- maven逆向工程生成myBatis代码,pojo有jpa注解
- Mybatis-逆向工程实现
- IDEA使用maven的进行mybatis的逆向工程
- Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】
- mybatis逆向工程之maven工程
- Mybatis逆向工程的实现
- eclipse中利用Maven逆向工程生成PO类以及mapper(mybatis)
- Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】