用Maven中实现MyBatis逆向工程(IDEA版)
来源:互联网 发布:海信电视看电影软件 编辑:程序博客网 时间:2024/06/06 02:05
用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
阅读全文
0 0
- 用Maven中实现MyBatis逆向工程(IDEA版)
- 用Intillij IDEA实现MyBatis逆向工程
- IDEA中使用maven创建mybatis的逆向工程
- mybatis逆向工程(idea版)
- Mybatis逆向工程_使用maven-Idea
- IDEA 中生成 MyBatis 逆向工程实践
- idea中使用mybatis逆向工程详解
- mybatis逆向工程(maven)
- IDEA中用通过maven使用mybatis逆向工程
- IDEA使用maven的进行mybatis的逆向工程
- Mybatis-逆向工程实现
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 在IDEA中使用MyBatis Generator逆向工程生成代码
- 解决git clone时报错:The requested URL returned error: 401 Unauthorized while accessing
- jQuery框架
- Python 多CPU并行处理数据
- Qt 编码问题QTextCodec
- 对SIFT算法的理解,尤其是尺度不变性
- 用Maven中实现MyBatis逆向工程(IDEA版)
- 直接排序、选择排序(Java实现)
- java中的运算符
- leetcode657. Judge Route Circle
- 图解单片机下载程序电路原理之USB转串口线、CH340、PL2303、MAX232芯片的使用!
- 移动端开发样式CSS Hack和一些问题的处理
- 业务参数判空和判断null
- 在centos7下搭建FTP,使本地电脑与虚拟机能上传下载文件
- 11.30学习计划