generatorConfig.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 > <context id="context1" > <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/jiubao" userId="root" password="" /> <javaModelGenerator targetPackage="generator.model" targetProject="jiubao" /> <sqlMapGenerator targetPackage="generator.map" targetProject="jiubao" /> <javaClientGenerator targetPackage="generator.client" targetProject="jiubao" type="XMLMAPPER" /> <table schema="jiubao" tableName="diancan" /> </context> </generatorConfiguration>
把生成的generator文件夹delete掉.重新生成一个generator文件夹.
<?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 > <context id="context1" > <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/jiubao" userId="root" password="" /> <javaModelGenerator targetPackage="generator.model" targetProject="jiubao" /> <sqlMapGenerator targetPackage="generator.map" targetProject="jiubao" /> <javaClientGenerator targetPackage="generator.client" targetProject="jiubao" type="XMLMAPPER" /> <table schema="jiubao" tableName="diancan" /> <table schema="jiubao" tableName="caipu" /> </context> </generatorConfiguration>
增加一个表,只需要到generatorConfig.xml多增加一条记录
<table schema="jiubao" tableName="caipu" />
如果菜谱表caipu增加一个字段price的话,那么
<?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 > <context id="context1" > <commentGenerator> <property name="suppressAllComments" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/jiubao" userId="root" password="" /> <javaModelGenerator targetPackage="generator.model" targetProject="jiubao" /> <sqlMapGenerator targetPackage="generator.map" targetProject="jiubao" /> <javaClientGenerator targetPackage="generator.client" targetProject="jiubao" type="XMLMAPPER" /> <table schema="jiubao" tableName="diancan" /> <table schema="jiubao" tableName="caipu" /> </context> </generatorConfiguration>