首先附上我扩展后项目的github地址:点击打开链接,接下来的目标是实现生成的java代码的合并,
而不是目前的简单覆盖。
1、增加了获取sqlServer数据库字段注释的功能(官网给出的解释是JDBC不支持获取sqlServer字段注释)。
2、扩展生成Bo,table里添加boObjectName属性,对应的XML配置如下:
<javaBoGeneratortargetPackage="com.btjf.business.authentication.custcertification.Bo"
targetProject="java-generator-core/src/main/java">
<propertyname="enableSubPackages" value="true" />
<propertyname="trimStrings" value="true" />
</javaBoGenerator>
3、(1)table里增加了
enableInsertSelective
enableUpdateByExampleSelective属性,其默认值为true;
(2)对应的enableUpdateByExample
enableUpdateByPrimaryKey
enableInsert默认改成了false ;
(3)新增enableSelectAll
enableSelectNotDele
enableSelectNotDeleteByPrimaryKey属性,默认为false;
对应的则在Mapper中添加了相应的方法。
4、结合freemarker和XML生成了简单的Service和domain,对应的XML配置如下:
<javaServiceGenerator targetPackage="com.btjf.business.authentication.custcertification.service"
targetProject="java-generator-core/src/main/java">
<propertyname="enableSubPackages" value="true" />
</javaServiceGenerator>
<javaDomainGenerator targetPackage="com.btjf.business.authentication.custcertification.domain"
targetProject="java-generator-core/src/main/java">
</javaDomainGenerator>
5、 注意:javaBoGenerator、javaServiceGenerator均为可选不进行配置,javaDomainGenerator和javaServiceGenerator成对出现(要么都配置,要么都不配置)
6、附上整个的generatorConfig.xml,。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://192.168.100.142/PUBLIC/DTD/mybatis-generator-config_1_0.dtd" > <!--配置生成器--> <generatorConfiguration> <!-----------------------------------------------------------------------------------------------------------------> <!--配置数据库驱动,location属性指明加载jar/zip包的全路径--> <classPathEntry location="D:\tools\libs\com\microsoft\sqlserver\sqljdbc4\4.4\sqljdbc4-4.4.jar" /> <!-----------------------------------------------------------------------------------------------------------------> <!-- context:生成一组对象的环境 id:必选,上下文id,用于在生成错误时提示 defaultModelType:指定生成对象的样式 1,conditional:类似hierarchical; 2,flat:所有内容(主键,blob)等全部生成在一个对象中; 3,hierarchical:主键生成一个XXKey对象(key class),Blob等单独生成一个对象,其他简单属性在一个对象中(record class) targetRuntime: 1,MyBatis3:默认的值,生成基于MyBatis3.x以上版本的内容,包括XXXBySample; 2,MyBatis3Simple:类似MyBatis3,只是不生成XXXBySample; introspectedColumnImpl:类全限定名,用于扩展MBG --> <context id="beitaijinfu" targetRuntime="MyBatis3"> <!-----------------------------------------------------------------------------------------------------------------> <!-- 自动识别数据库关键字,默认falseÿ