@@ -43,7 +43,6 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
4343 public static final String ID_FOR_PROPERTY_BASED_RESULT_MAP = "BasePropertyResultMap" ;
4444 private XmlElement selectByExampleSelectiveEle ;
4545 private XmlElement selectByPrimaryKeySelectiveEle ;
46- private XmlElement basePropertyResultMapEle ;
4746
4847 /**
4948 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@@ -73,7 +72,6 @@ public void initialized(IntrospectedTable introspectedTable) {
7372 // bug:26,27
7473 this .selectByExampleSelectiveEle = null ;
7574 this .selectByPrimaryKeySelectiveEle = null ;
76- this .basePropertyResultMapEle = null ;
7775 }
7876
7977 // =========================================== client 方法生成 ===================================================
@@ -163,8 +161,19 @@ public boolean clientSelectByPrimaryKeyMethodGenerated(Method method, TopLevelCl
163161 @ Override
164162 public boolean sqlMapDocumentGenerated (Document document , IntrospectedTable introspectedTable ) {
165163 // issues#16
166- if (this .basePropertyResultMapEle != null ) {
167- document .getRootElement ().addElement (0 , this .basePropertyResultMapEle );
164+ if (introspectedTable .isConstructorBased ()) {
165+ XmlElement resultMapEle = new XmlElement ("resultMap" );
166+ resultMapEle .addAttribute (new Attribute ("id" , ID_FOR_PROPERTY_BASED_RESULT_MAP ));
167+ resultMapEle .addAttribute (new Attribute ("type" , introspectedTable .getRules ().calculateAllFieldsClass ().getFullyQualifiedName ()));
168+ commentGenerator .addComment (resultMapEle );
169+
170+ for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns ()) {
171+ resultMapEle .addElement (XmlElementGeneratorTools .generateResultMapResultElement ("id" , introspectedColumn ));
172+ }
173+ for (IntrospectedColumn introspectedColumn : introspectedTable .getNonPrimaryKeyColumns ()) {
174+ resultMapEle .addElement (XmlElementGeneratorTools .generateResultMapResultElement ("result" , introspectedColumn ));
175+ }
176+ document .getRootElement ().addElement (0 , resultMapEle );
168177 }
169178
170179 // 1. selectByExampleSelective 方法
@@ -243,19 +252,6 @@ private XmlElement generateSelectSelectiveElement(String id, IntrospectedTable i
243252 selectSelectiveEle .addAttribute (new Attribute ("id" , id ));
244253 // issues#16
245254 if (introspectedTable .isConstructorBased ()) {
246- XmlElement resultMapEle = new XmlElement ("resultMap" );
247- resultMapEle .addAttribute (new Attribute ("id" , ID_FOR_PROPERTY_BASED_RESULT_MAP ));
248- resultMapEle .addAttribute (new Attribute ("type" , introspectedTable .getRules ().calculateAllFieldsClass ().getFullyQualifiedName ()));
249- commentGenerator .addComment (resultMapEle );
250-
251- for (IntrospectedColumn introspectedColumn : introspectedTable .getPrimaryKeyColumns ()) {
252- resultMapEle .addElement (XmlElementGeneratorTools .generateResultMapResultElement ("id" , introspectedColumn ));
253- }
254- for (IntrospectedColumn introspectedColumn : introspectedTable .getNonPrimaryKeyColumns ()) {
255- resultMapEle .addElement (XmlElementGeneratorTools .generateResultMapResultElement ("result" , introspectedColumn ));
256- }
257- this .basePropertyResultMapEle = resultMapEle ;
258-
259255 selectSelectiveEle .addAttribute (new Attribute ("resultMap" , ID_FOR_PROPERTY_BASED_RESULT_MAP ));
260256 } else if (introspectedTable .hasBLOBColumns ()) {
261257 selectSelectiveEle .addAttribute (new Attribute ("resultMap" , introspectedTable .getResultMapWithBLOBsId ()));
0 commit comments