麻麻~我会用小黑鸟自动生成SQL啦 mybatis-generator的使用
2017-12-05 20:45
387 查看
mybatis-generator可以根据数据库的表来生成POJO类、mapper.xml和DAO接口,用这个插件会大大地提高开发的效率,但是在MyEclipse中使用变得好复杂.经过1小时拿来主义总结下
1.在myEclipse中找到如下位置开启市场
2.在市场页面点击Ecipse市场,并搜索mybatis-generator
3.安装后新建配置文件到工程的任意位置,文件名为GeneratorMapper.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>
<!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
<classPathEntry location="D:/JAVA work/Level_7/repository/mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar"/>
<!-- 配置table表信息内容体,targetRuntime指定采用MyBatis3的版本 -->
<context id="tables" targetRuntime="MyBatis3">
<!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 配置数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.43.128:3306/p2padmin"
userId="root"
password="123456">
</jdbcConnection>
<!-- 生成model类,targetPackage指定model类的包名, targetProject指定生成的model放在eclipse的哪个工程下面-->
<javaModelGenerator targetPackage="com.h2.p2p.admin.model" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<!-- 生成MyBatis的Mapper.xml文件,targetPackage指定mapper.xml文件的包名, targetProject指定生成的mapper.xml放在eclipse的哪个工程下面 -->
<sqlMapGenerator targetPackage="com.h2.p2p.admin.mapper" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成MyBatis的Mapper接口类文件,targetPackage指定Mapper接口类的包名, targetProject指定生成的Mapper接口放在eclipse的哪个工程下面 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.h2.p2p.admin.mapper" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 数据库表名及对应的Java模型类名 -->
<table tableName="u_user_info"
domainObjectName="UserInfo"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
4.右键运行配置文件,运行后不会有任何输出,直接看是否增加了想要的文件即可
1.在myEclipse中找到如下位置开启市场
2.在市场页面点击Ecipse市场,并搜索mybatis-generator
3.安装后新建配置文件到工程的任意位置,文件名为GeneratorMapper.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>
<!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
<classPathEntry location="D:/JAVA work/Level_7/repository/mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar"/>
<!-- 配置table表信息内容体,targetRuntime指定采用MyBatis3的版本 -->
<context id="tables" targetRuntime="MyBatis3">
<!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 配置数据库连接信息 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.43.128:3306/p2padmin"
userId="root"
password="123456">
</jdbcConnection>
<!-- 生成model类,targetPackage指定model类的包名, targetProject指定生成的model放在eclipse的哪个工程下面-->
<javaModelGenerator targetPackage="com.h2.p2p.admin.model" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<!-- 生成MyBatis的Mapper.xml文件,targetPackage指定mapper.xml文件的包名, targetProject指定生成的mapper.xml放在eclipse的哪个工程下面 -->
<sqlMapGenerator targetPackage="com.h2.p2p.admin.mapper" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成MyBatis的Mapper接口类文件,targetPackage指定Mapper接口类的包名, targetProject指定生成的Mapper接口放在eclipse的哪个工程下面 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.h2.p2p.admin.mapper" targetProject="18-p2p-admin">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 数据库表名及对应的Java模型类名 -->
<table tableName="u_user_info"
domainObjectName="UserInfo"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
4.右键运行配置文件,运行后不会有任何输出,直接看是否增加了想要的文件即可
相关文章推荐
- Mybatis 使用maven插件mybatis-generator自动生成entities和SQL和mapper
- 一双跑鞋的mybatis(六)---使用generator自动生成mybatis映射代码
- MyBatis使用Generator自动生成代码
- 使用Mybatis Generator自动生成Mybatis相关代码
- 使用Mybatis Generator自动生成Mybatis相关代码
- MyBatis使用Generator自动生成代码
- 使用Mybatis Generator自动生成Mybatis相关代码
- 使用Mybatis Generator自动生成Mybatis相关代码
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- Mybatis使用Generator插件自动生成Mapper,实体类
- Mybatis使用generator自动生成映射配置文件信息
- mybatis 之 generator插件使用 集成到了eclipse 自动生成实体,example,mapper
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- 使用Mybatis Generator自动生成Mybatis相关代码
- MyBatis使用Generator自动生成代码
- 使用Mybatis Generator自动生成Mybatis相关代码
- mybatis使用generator自动生成代码时的类型转换
- MyBatis使用Generator自动生成代码
- maven+mybatis+mybatis-generator+sql server 2005自动生成代码,加上自定义分页插件和批量插入更新插件