为了生成只读的接口和xml,并命名结尾为MapperR.java和MapperR.xml

前端之家收集整理的这篇文章主要介绍了为了生成只读的接口和xml,并命名结尾为MapperR.java和MapperR.xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

《一》首先从https://github.com/mybatis/generator下载源代码,然后找到org.mybatis.generator.api下面的IntrospectedTable文件修改以下两个方法,然后重新打个jar包。

1.修改calculateJavaClientAttributes方法

protected void calculateJavaClientAttributes() {
        if (context.getJavaClientGeneratorConfiguration() == null) {
            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(calculateJavaClientImplementationPackage());
        sb.append('.');
        sb.append(fullyQualifiedTable.getDomainObjectName());
        sb.append("DAOImpl"); //$NON-NLS-1$
        setDAOImplementationType(sb.toString());

        sb.setLength(0);
        sb.append(calculateJavaClientInterfacePackage());
        sb.append('.');
        sb.append(fullyQualifiedTable.getDomainObjectName());
        sb.append("DAO"); //$NON-NLS-1$
        setDAOInterfaceType(sb.toString());

        sb.setLength(0);
        sb.append(calculateJavaClientInterfacePackage());
        sb.append('.');
        sb.append(fullyQualifiedTable.getDomainObjectName());
        sb.append("Mapper"); //$NON-NLS-1$
        
        if(null!=calculateJavaClientInterfacePackage() && calculateJavaClientInterfacePackage().endsWith(".dro")){
        	setMyBatis3JavaMapperType(sb.toString()+"R");
        }else{
        	setMyBatis3JavaMapperType(sb.toString());
        }

        sb.setLength(0);
        sb.append(calculateJavaClientInterfacePackage());
        sb.append('.');
        sb.append(fullyQualifiedTable.getDomainObjectName());
        sb.append("sqlProvider"); //$NON-NLS-1$
        setMyBatis3sqlProviderType(sb.toString());
    }
2.修改calculateMyBatis3XmlMapperFileName方法
protected String calculateMyBatis3XmlMapperFileName() {
        StringBuilder sb = new StringBuilder();
        sb.append(fullyQualifiedTable.getDomainObjectName());
      
        if(null!=calculateJavaClientInterfacePackage() && calculateJavaClientInterfacePackage().endsWith(".dro")){
        	 sb.append("MapperR.xml"); //$NON-NLS-1$
        }else{
        	 sb.append("Mapper.xml"); //$NON-NLS-1$
        }
        
        return sb.toString();
    }

《二》generatorConfiguration的配置文件,javaClientGenerator的targetPackage这个包的名字需要以 ".dro" 结尾

《三》使用命令

java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig-dro.xml -overwrite

即可生成只读的接口和xml了,并命名结尾为MapperR.java和MapperR.xml。

原文链接:https://www.f2er.com/xml/297035.html

猜你在找的XML相关文章