首页 > 代码库 > mybatis的逆向工程
mybatis的逆向工程
由数据库的表生成代码,然后生成代码配置文件,指定mubatis表,再执行生成程序。
接下来我们的项目连接数据库可能要用到,看了很多代码,感觉一知半解,继续努力~
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value=http://www.mamicode.com/"true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://120.25.162.238:3306/mybatis001?characterEncoding=utf-8"
userId="root"
password="123">
</jdbcConnection>
<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
userId="yycg"
password="yycg">
</jdbcConnection> -->
<javaTypeResolver>
<property name="forceBigDecimals" value=http://www.mamicode.com/"false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.iot.ssm.po"
targetProject=".\src">
<property name="enableSubPackages" value=http://www.mamicode.com/"false" />
<property name="trimStrings" value=http://www.mamicode.com/"true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.iot.ssm.mapper"
targetProject=".\src">
<property name="enableSubPackages" value=http://www.mamicode.com/"false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.iot.ssm.mapper"
targetProject=".\src">
<property name="enableSubPackages" value=http://www.mamicode.com/"false" />
</javaClientGenerator>
<table tableName="items"></table>
<table tableName="orders"></table>
<table tableName="orderdetail"></table>
<table tableName="user"></table>
<!-- <table schema="" tableName="sys_user"></table>
<table schema="" tableName="sys_role"></table>
<table schema="" tableName="sys_permission"></table>
<table schema="" tableName="sys_user_role"></table>
<table schema="" tableName="sys_role_permission"></table> -->
<table schema="" tableName="">
<columnOverride column="" javaType="" />
</table> -->
</context>
</generatorConfiguration>
public void generator() throws Exception{
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
mybatis的逆向工程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。