From 56209d00b7c54163e6cabbabdf041bc4e2e3795c Mon Sep 17 00:00:00 2001 From: slankka Date: Mon, 9 Jul 2018 18:03:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E2=80=9CDAO=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E6=96=B9=E6=B3=95=E6=8A=BD=E5=87=BA=E5=88=B0=E7=88=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E2=80=9D=E6=94=AF=E6=8C=81=E6=97=A0=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E5=92=8C=E5=A4=9A=E4=B8=BB=E9=94=AE=E7=9A=84=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/CommonDAOInterfacePlugin.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zzg/mybatis/generator/plugins/CommonDAOInterfacePlugin.java b/src/main/java/com/zzg/mybatis/generator/plugins/CommonDAOInterfacePlugin.java index 5e6508a0..f761226f 100644 --- a/src/main/java/com/zzg/mybatis/generator/plugins/CommonDAOInterfacePlugin.java +++ b/src/main/java/com/zzg/mybatis/generator/plugins/CommonDAOInterfacePlugin.java @@ -25,9 +25,6 @@ public class CommonDAOInterfacePlugin extends PluginAdapter { private List methods = new ArrayList<>(); - // 扩展 - private String expandDaoSuperClass; - private ShellCallback shellCallback = null; public CommonDAOInterfacePlugin() { @@ -36,14 +33,13 @@ public CommonDAOInterfacePlugin() { @Override public List contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) { - + boolean hasPk = introspectedTable.hasPrimaryKeyColumns(); JavaFormatter javaFormatter = context.getJavaFormatter(); String daoTargetDir = context.getJavaClientGeneratorConfiguration().getTargetProject(); String daoTargetPackage = context.getJavaClientGeneratorConfiguration().getTargetPackage(); - List mapperJavaFiles = new ArrayList(); + List mapperJavaFiles = new ArrayList<>(); String javaFileEncoding = context.getProperty("javaFileEncoding"); Interface mapperInterface = new Interface(daoTargetPackage + DEFAULT_DAO_SUPER_CLASS); - GeneratedJavaFile mapperJavafile = null; if (stringHasValue(daoTargetPackage)) { mapperInterface.addImportedType(PARAM_ANNOTATION_TYPE); @@ -53,8 +49,8 @@ public List contextGenerateAdditionalJavaFiles(IntrospectedTa mapperInterface.setVisibility(JavaVisibility.PUBLIC); mapperInterface.addJavaDocLine("/**"); mapperInterface.addJavaDocLine(" * " + "DAO公共基类,由MybatisGenerator自动生成请勿修改"); - mapperInterface.addJavaDocLine(" * " + "@param The Model Class"); - mapperInterface.addJavaDocLine(" * " + "@param The Primary Key Class"); + mapperInterface.addJavaDocLine(" * " + "@param The Model Class 这里是泛型不是Model类"); + mapperInterface.addJavaDocLine(" * " + "@param The Primary Key Class 如果是无主键,则可以用Model来跳过,如果是多主键则是Key类"); mapperInterface.addJavaDocLine(" * " + "@param The Example Class"); mapperInterface.addJavaDocLine(" */"); @@ -64,11 +60,9 @@ public List contextGenerateAdditionalJavaFiles(IntrospectedTa daoBaseInterfaceJavaType.addTypeArgument(new FullyQualifiedJavaType("E")); if (!this.methods.isEmpty()) { - for (Method method : methods) { mapperInterface.addMethod(method); } - } List generatedJavaFiles = introspectedTable.getGeneratedJavaFiles(); @@ -79,7 +73,7 @@ public List contextGenerateAdditionalJavaFiles(IntrospectedTa if (modelName.endsWith("DAO")) { } } - mapperJavafile = new GeneratedJavaFile(mapperInterface, daoTargetDir, javaFileEncoding, javaFormatter); + GeneratedJavaFile mapperJavafile = new GeneratedJavaFile(mapperInterface, daoTargetDir, javaFileEncoding, javaFormatter); try { File mapperDir = shellCallback.getDirectory(daoTargetDir, daoTargetPackage); File mapperFile = new File(mapperDir, mapperJavafile.getFileName()); @@ -111,7 +105,14 @@ public boolean clientGenerated(Interface interfaze, FullyQualifiedJavaType baseModelJavaType = new FullyQualifiedJavaType(targetPackage + "." + domainObjectName); daoSuperType.addTypeArgument(baseModelJavaType); - FullyQualifiedJavaType primaryKeyTypeJavaType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType(); + FullyQualifiedJavaType primaryKeyTypeJavaType = null; + if (introspectedTable.getPrimaryKeyColumns().size() > 1) { + primaryKeyTypeJavaType = new FullyQualifiedJavaType(targetPackage + "." + domainObjectName + "Key"); + }else if(introspectedTable.hasPrimaryKeyColumns()){ + primaryKeyTypeJavaType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType(); + }else { + primaryKeyTypeJavaType = baseModelJavaType; + } daoSuperType.addTypeArgument(primaryKeyTypeJavaType); String exampleType = introspectedTable.getExampleType();