mybatis 怎么生成javabean
展开全部
1.所需的jar 包
mybatis-3.0.4.jar 、mybatis-generator-core-1.3.1.jar 、 MySQL-connector-java-5.1.13.jar
2.新建文件夹
新建文件夹E://mygen,将以上三个文件放入夹
3.同目录创建
generator.xml 文件
内容如下 :
[html] view plain copy print?
<?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="E:\workspace10\mydemo\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.13.jar" />
<context id="MYSQLTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/renwu" userId="root" password="root">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.hc360.renwu.po" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\po">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.hc360.qiye.renwu.mapper" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\dao\mapper">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.hc360.renwu.dao" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\dao">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<table tableName="achievement" domainObjectName="Achievement" schema="renwu" enableInsert="true"
enableSelectByPrimaryKey="true" enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="city" domainObjectName="City" schema="renwu" enableInsert="true"
enableSelectByPrimaryKey="true" enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
4.执行命令完成。
cmd ----E:-----cd E://mygen----Java -jar mybatis-generator-core-1.3.1.jar -configfile generator.xml -overwrite 就ok 啦
mybatis-3.0.4.jar 、mybatis-generator-core-1.3.1.jar 、 MySQL-connector-java-5.1.13.jar
2.新建文件夹
新建文件夹E://mygen,将以上三个文件放入夹
3.同目录创建
generator.xml 文件
内容如下 :
[html] view plain copy print?
<?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="E:\workspace10\mydemo\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.13.jar" />
<context id="MYSQLTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/renwu" userId="root" password="root">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.hc360.renwu.po" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\po">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.hc360.qiye.renwu.mapper" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\dao\mapper">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.hc360.renwu.dao" targetProject="E:\workspace10\renwu\src\main\java\com\hc360\renwu\dao">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<table tableName="achievement" domainObjectName="Achievement" schema="renwu" enableInsert="true"
enableSelectByPrimaryKey="true" enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="city" domainObjectName="City" schema="renwu" enableInsert="true"
enableSelectByPrimaryKey="true" enableSelectByExample="false" enableDeleteByExample="false"
enableCountByExample="false" enableUpdateByExample="false">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
4.执行命令完成。
cmd ----E:-----cd E://mygen----Java -jar mybatis-generator-core-1.3.1.jar -configfile generator.xml -overwrite 就ok 啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询