前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mybatis 对于基本类型数据传值的问题

mybatis 对于基本类型数据传值的问题

作者头像
Gxjun
发布2018-03-27 11:06:01
1.8K0
发布2018-03-27 11:06:01
举报
文章被收录于专栏:ml

最近在开发的时候,遇到一个小问题:

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'DomainID' in 'class java.lang.Integer'

这是 mybatis 源文件

代码语言:javascript
复制
1  public ABLayer GetInfos(final int DomainID) {
2 
3   return sqlSession.selectOne("abLayer.GetInfos",DomainID);
4 }
代码语言:javascript
复制
 <!---->
    <select id="GetInfos" parameterType="java.lang.Integer" resultMap="ABLayer">
        select *
        from ab_layer
        <where>
            <if test="DomainID != null and DomainID !='' ">
                DomainID=#{DomainID}
            </if>
        </where>
        order by ID
    </select>

分析:

  当我去掉<if>条件之后

代码语言:javascript
复制
  <where>
            <if test="DomainID != null and DomainID !='' ">
                DomainID=#{DomainId}
            </if>
 </where>

有可以正常运行.仔细debug了一下源码并查看了一下官方文档,发现Mybatis解析使用的ognl表达式,我们知道ognl的上下文OgnlContext使用的时候Map接口

代码语言:javascript
复制
 1 public class OgnlContext implements Map {
 2     public static final String CONTEXT_CONTEXT_KEY = "context";
 3     public static final String ROOT_CONTEXT_KEY = "root";
 4     public static final String THIS_CONTEXT_KEY = "this";
 5     public static final String TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
 6     public static final String LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
 7     public static final String KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
 8     public static final String CLASS_RESOLVER_CONTEXT_KEY = "_classResolver";
 9     public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
10     public static final String MEMBER_ACCESS_CONTEXT_KEY = "_memberAccess";
11     private static final String PROPERTY_KEY_PREFIX = "ognl";

并且OgnlRutime中包含了许多的Bean类型,在源码中可以看到

代码语言:javascript
复制
   1 //
   2 // Source code recreated from a .class file by IntelliJ IDEA
   3 // (powered by Fernflower decompiler)
   4 //
   5 
   6 package org.apache.ibatis.ognl;
   7 
   8 import java.beans.IndexedPropertyDescriptor;
   9 import java.beans.IntrospectionException;
  10 import java.beans.Introspector;
  11 import java.beans.PropertyDescriptor;
  12 import java.lang.reflect.Constructor;
  13 import java.lang.reflect.Field;
  14 import java.lang.reflect.InvocationTargetException;
  15 import java.lang.reflect.Member;
  16 import java.lang.reflect.Method;
  17 import java.lang.reflect.Modifier;
  18 import java.lang.reflect.Proxy;
  19 import java.math.BigDecimal;
  20 import java.math.BigInteger;
  21 import java.security.Permission;
  22 import java.util.ArrayList;
  23 import java.util.Arrays;
  24 import java.util.Collections;
  25 import java.util.HashMap;
  26 import java.util.Iterator;
  27 import java.util.List;
  28 import java.util.Map;

  60 public abstract class OgnlRuntime {
  61     public static final Object NotFound = new Object();
  62     public static final List NotFoundList = new ArrayList();
  63     public static final Map NotFoundMap = new HashMap();
  64     public static final Object[] NoArguments = new Object[0];
  65     public static final Class[] NoArgumentTypes = new Class[0];
  66     public static final Object NoConversionPossible = "org.apache.ibatis.ognl.NoConversionPossible";
  67     public static int INDEXED_PROPERTY_NONE = 0;
  68     public static int INDEXED_PROPERTY_INT = 1;
  69     public static int INDEXED_PROPERTY_OBJECT = 2;
  70     public static final String NULL_STRING = "" + null;
  71     private static final String SET_PREFIX = "set";
  72     private static final String GET_PREFIX = "get";
  73     private static final String IS_PREFIX = "is";
  74     private static final Map HEX_PADDING = new HashMap();
  75     private static final String HEX_PREFIX = "0x";
  76     private static final int HEX_LENGTH = 8;
  77     private static final String NULL_OBJECT_STRING = "<null>";
  78     private static OgnlRuntime.ClassCache methodAccessors = new OgnlRuntime.ClassCache();
  79     private static OgnlRuntime.ClassCache propertyAccessors = new OgnlRuntime.ClassCache();
  80     private static OgnlRuntime.ClassCache elementsAccessors = new OgnlRuntime.ClassCache();
  81     private static OgnlRuntime.ClassCache nullHandlers = new OgnlRuntime.ClassCache();
  82     private static OgnlRuntime.ClassCache propertyDescriptorCache = new OgnlRuntime.ClassCache();
  83     private static OgnlRuntime.ClassCache constructorCache = new OgnlRuntime.ClassCache();
  84     private static OgnlRuntime.ClassCache staticMethodCache = new OgnlRuntime.ClassCache();
  85     private static OgnlRuntime.ClassCache instanceMethodCache = new OgnlRuntime.ClassCache();
  86     private static OgnlRuntime.ClassCache invokePermissionCache = new OgnlRuntime.ClassCache();
  87     private static OgnlRuntime.ClassCache fieldCache = new OgnlRuntime.ClassCache();
  88     private static List superclasses = new ArrayList();
  89     private static OgnlRuntime.ClassCache[] declaredMethods = new OgnlRuntime.ClassCache[]{new OgnlRuntime.ClassCache(), new OgnlRuntime.ClassCache()};
  90     private static Map primitiveTypes = new HashMap(101);
  91     private static OgnlRuntime.ClassCache primitiveDefaults = new OgnlRuntime.ClassCache();
  92     private static Map methodParameterTypesCache = new HashMap(101);
  93     private static Map ctorParameterTypesCache = new HashMap(101);
  94     private static SecurityManager securityManager = System.getSecurityManager();
  95     private static EvaluationPool evaluationPool = new EvaluationPool();
  96     private static ObjectArrayPool objectArrayPool = new ObjectArrayPool();
  97 
  98     static {
  99         ArrayPropertyAccessor p = new ArrayPropertyAccessor();
 100         Class var10000 = class$0;
 101         if(class$0 == null) {
 102             try {
 103                 var10000 = Class.forName("java.lang.Object");
 104             } catch (ClassNotFoundException var51) {
 105                 throw new NoClassDefFoundError(var51.getMessage());
 106             }
 107 
 108             class$0 = var10000;
 109         }
 110 
 111         setPropertyAccessor(var10000, new ObjectPropertyAccessor());
 112         var10000 = class$1;
 113         if(class$1 == null) {
 114             try {
 115                 var10000 = Class.forName("[B");
 116             } catch (ClassNotFoundException var50) {
 117                 throw new NoClassDefFoundError(var50.getMessage());
 118             }
 119 
 120             class$1 = var10000;
 121         }
 122 
 123         setPropertyAccessor(var10000, p);
 124         var10000 = class$2;
 125         if(class$2 == null) {
 126             try {
 127                 var10000 = Class.forName("[S");
 128             } catch (ClassNotFoundException var49) {
 129                 throw new NoClassDefFoundError(var49.getMessage());
 130             }
 131 
 132             class$2 = var10000;
 133         }
 134 
 135         setPropertyAccessor(var10000, p);
 136         var10000 = class$3;
 137         if(class$3 == null) {
 138             try {
 139                 var10000 = Class.forName("[C");
 140             } catch (ClassNotFoundException var48) {
 141                 throw new NoClassDefFoundError(var48.getMessage());
 142             }
 143 
 144             class$3 = var10000;
 145         }
 146 
 147         setPropertyAccessor(var10000, p);
 148         var10000 = class$4;
 149         if(class$4 == null) {
 150             try {
 151                 var10000 = Class.forName("[I");
 152             } catch (ClassNotFoundException var47) {
 153                 throw new NoClassDefFoundError(var47.getMessage());
 154             }
 155 
 156             class$4 = var10000;
 157         }
 158 
 159         setPropertyAccessor(var10000, p);
 160         var10000 = class$5;
 161         if(class$5 == null) {
 162             try {
 163                 var10000 = Class.forName("[J");
 164             } catch (ClassNotFoundException var46) {
 165                 throw new NoClassDefFoundError(var46.getMessage());
 166             }
 167 
 168             class$5 = var10000;
 169         }
 170 
 171         setPropertyAccessor(var10000, p);
 172         var10000 = class$6;
 173         if(class$6 == null) {
 174             try {
 175                 var10000 = Class.forName("[F");
 176             } catch (ClassNotFoundException var45) {
 177                 throw new NoClassDefFoundError(var45.getMessage());
 178             }
 179 
 180             class$6 = var10000;
 181         }
 182 
 183         setPropertyAccessor(var10000, p);
 184         var10000 = class$7;
 185         if(class$7 == null) {
 186             try {
 187                 var10000 = Class.forName("[D");
 188             } catch (ClassNotFoundException var44) {
 189                 throw new NoClassDefFoundError(var44.getMessage());
 190             }
 191 
 192             class$7 = var10000;
 193         }
 194 
 195         setPropertyAccessor(var10000, p);
 196         var10000 = class$8;
 197         if(class$8 == null) {
 198             try {
 199                 var10000 = Class.forName("[Ljava.lang.Object;");
 200             } catch (ClassNotFoundException var43) {
 201                 throw new NoClassDefFoundError(var43.getMessage());
 202             }
 203 
 204             class$8 = var10000;
 205         }
 206 
 207         setPropertyAccessor(var10000, p);
 208         var10000 = class$9;
 209         if(class$9 == null) {
 210             try {
 211                 var10000 = Class.forName("java.util.List");
 212             } catch (ClassNotFoundException var42) {
 213                 throw new NoClassDefFoundError(var42.getMessage());
 214             }
 215 
 216             class$9 = var10000;
 217         }
 218 
 219         setPropertyAccessor(var10000, new ListPropertyAccessor());
 220         var10000 = class$10;
 221         if(class$10 == null) {
 222             try {
 223                 var10000 = Class.forName("java.util.Map");
 224             } catch (ClassNotFoundException var41) {
 225                 throw new NoClassDefFoundError(var41.getMessage());
 226             }
 227 
 228             class$10 = var10000;
 229         }
 230 
 231         setPropertyAccessor(var10000, new MapPropertyAccessor());
 232         var10000 = class$11;
 233         if(class$11 == null) {
 234             try {
 235                 var10000 = Class.forName("java.util.Set");
 236             } catch (ClassNotFoundException var40) {
 237                 throw new NoClassDefFoundError(var40.getMessage());
 238             }
 239 
 240             class$11 = var10000;
 241         }
 242 
 243         setPropertyAccessor(var10000, new SetPropertyAccessor());
 244         var10000 = class$12;
 245         if(class$12 == null) {
 246             try {
 247                 var10000 = Class.forName("java.util.Iterator");
 248             } catch (ClassNotFoundException var39) {
 249                 throw new NoClassDefFoundError(var39.getMessage());
 250             }
 251 
 252             class$12 = var10000;
 253         }
 254 
 255         setPropertyAccessor(var10000, new IteratorPropertyAccessor());
 256         var10000 = class$13;
 257         if(class$13 == null) {
 258             try {
 259                 var10000 = Class.forName("java.util.Enumeration");
 260             } catch (ClassNotFoundException var38) {
 261                 throw new NoClassDefFoundError(var38.getMessage());
 262             }
 263 
 264             class$13 = var10000;
 265         }
 266 
 267         setPropertyAccessor(var10000, new EnumerationPropertyAccessor());
 268         ArrayElementsAccessor e = new ArrayElementsAccessor();
 269         var10000 = class$0;
 270         if(class$0 == null) {
 271             try {
 272                 var10000 = Class.forName("java.lang.Object");
 273             } catch (ClassNotFoundException var37) {
 274                 throw new NoClassDefFoundError(var37.getMessage());
 275             }
 276 
 277             class$0 = var10000;
 278         }
 279 
 280         setElementsAccessor(var10000, new ObjectElementsAccessor());
 281         var10000 = class$1;
 282         if(class$1 == null) {
 283             try {
 284                 var10000 = Class.forName("[B");
 285             } catch (ClassNotFoundException var36) {
 286                 throw new NoClassDefFoundError(var36.getMessage());
 287             }
 288 
 289             class$1 = var10000;
 290         }
 291 
 292         setElementsAccessor(var10000, e);
 293         var10000 = class$2;
 294         if(class$2 == null) {
 295             try {
 296                 var10000 = Class.forName("[S");
 297             } catch (ClassNotFoundException var35) {
 298                 throw new NoClassDefFoundError(var35.getMessage());
 299             }
 300 
 301             class$2 = var10000;
 302         }
 303 
 304         setElementsAccessor(var10000, e);
 305         var10000 = class$3;
 306         if(class$3 == null) {
 307             try {
 308                 var10000 = Class.forName("[C");
 309             } catch (ClassNotFoundException var34) {
 310                 throw new NoClassDefFoundError(var34.getMessage());
 311             }
 312 
 313             class$3 = var10000;
 314         }
 315 
 316         setElementsAccessor(var10000, e);
 317         var10000 = class$4;
 318         if(class$4 == null) {
 319             try {
 320                 var10000 = Class.forName("[I");
 321             } catch (ClassNotFoundException var33) {
 322                 throw new NoClassDefFoundError(var33.getMessage());
 323             }
 324 
 325             class$4 = var10000;
 326         }
 327 
 328         setElementsAccessor(var10000, e);
 329         var10000 = class$5;
 330         if(class$5 == null) {
 331             try {
 332                 var10000 = Class.forName("[J");
 333             } catch (ClassNotFoundException var32) {
 334                 throw new NoClassDefFoundError(var32.getMessage());
 335             }
 336 
 337             class$5 = var10000;
 338         }
 339 
 340         setElementsAccessor(var10000, e);
 341         var10000 = class$6;
 342         if(class$6 == null) {
 343             try {
 344                 var10000 = Class.forName("[F");
 345             } catch (ClassNotFoundException var31) {
 346                 throw new NoClassDefFoundError(var31.getMessage());
 347             }
 348 
 349             class$6 = var10000;
 350         }
 351 
 352         setElementsAccessor(var10000, e);
 353         var10000 = class$7;
 354         if(class$7 == null) {
 355             try {
 356                 var10000 = Class.forName("[D");
 357             } catch (ClassNotFoundException var30) {
 358                 throw new NoClassDefFoundError(var30.getMessage());
 359             }
 360 
 361             class$7 = var10000;
 362         }
 363 
 364         setElementsAccessor(var10000, e);
 365         var10000 = class$8;
 366         if(class$8 == null) {
 367             try {
 368                 var10000 = Class.forName("[Ljava.lang.Object;");
 369             } catch (ClassNotFoundException var29) {
 370                 throw new NoClassDefFoundError(var29.getMessage());
 371             }
 372 
 373             class$8 = var10000;
 374         }
 375 
 376         setElementsAccessor(var10000, e);
 377         var10000 = class$14;
 378         if(class$14 == null) {
 379             try {
 380                 var10000 = Class.forName("java.util.Collection");
 381             } catch (ClassNotFoundException var28) {
 382                 throw new NoClassDefFoundError(var28.getMessage());
 383             }
 384 
 385             class$14 = var10000;
 386         }
 387 
 388         setElementsAccessor(var10000, new CollectionElementsAccessor());
 389         var10000 = class$10;
 390         if(class$10 == null) {
 391             try {
 392                 var10000 = Class.forName("java.util.Map");
 393             } catch (ClassNotFoundException var27) {
 394                 throw new NoClassDefFoundError(var27.getMessage());
 395             }
 396 
 397             class$10 = var10000;
 398         }
 399 
 400         setElementsAccessor(var10000, new MapElementsAccessor());
 401         var10000 = class$12;
 402         if(class$12 == null) {
 403             try {
 404                 var10000 = Class.forName("java.util.Iterator");
 405             } catch (ClassNotFoundException var26) {
 406                 throw new NoClassDefFoundError(var26.getMessage());
 407             }
 408 
 409             class$12 = var10000;
 410         }
 411 
 412         setElementsAccessor(var10000, new IteratorElementsAccessor());
 413         var10000 = class$13;
 414         if(class$13 == null) {
 415             try {
 416                 var10000 = Class.forName("java.util.Enumeration");
 417             } catch (ClassNotFoundException var25) {
 418                 throw new NoClassDefFoundError(var25.getMessage());
 419             }
 420 
 421             class$13 = var10000;
 422         }
 423 
 424         setElementsAccessor(var10000, new EnumerationElementsAccessor());
 425         var10000 = class$15;
 426         if(class$15 == null) {
 427             try {
 428                 var10000 = Class.forName("java.lang.Number");
 429             } catch (ClassNotFoundException var24) {
 430                 throw new NoClassDefFoundError(var24.getMessage());
 431             }
 432 
 433             class$15 = var10000;
 434         }
 435 
 436         setElementsAccessor(var10000, new NumberElementsAccessor());
 437         ObjectNullHandler nh = new ObjectNullHandler();
 438         var10000 = class$0;
 439         if(class$0 == null) {
 440             try {
 441                 var10000 = Class.forName("java.lang.Object");
 442             } catch (ClassNotFoundException var23) {
 443                 throw new NoClassDefFoundError(var23.getMessage());
 444             }
 445 
 446             class$0 = var10000;
 447         }
 448 
 449         setNullHandler(var10000, nh);
 450         var10000 = class$1;
 451         if(class$1 == null) {
 452             try {
 453                 var10000 = Class.forName("[B");
 454             } catch (ClassNotFoundException var22) {
 455                 throw new NoClassDefFoundError(var22.getMessage());
 456             }
 457 
 458             class$1 = var10000;
 459         }
 460 
 461         setNullHandler(var10000, nh);
 462         var10000 = class$2;
 463         if(class$2 == null) {
 464             try {
 465                 var10000 = Class.forName("[S");
 466             } catch (ClassNotFoundException var21) {
 467                 throw new NoClassDefFoundError(var21.getMessage());
 468             }
 469 
 470             class$2 = var10000;
 471         }
 472 
 473         setNullHandler(var10000, nh);
 474         var10000 = class$3;
 475         if(class$3 == null) {
 476             try {
 477                 var10000 = Class.forName("[C");
 478             } catch (ClassNotFoundException var20) {
 479                 throw new NoClassDefFoundError(var20.getMessage());
 480             }
 481 
 482             class$3 = var10000;
 483         }
 484 
 485         setNullHandler(var10000, nh);
 486         var10000 = class$4;
 487         if(class$4 == null) {
 488             try {
 489                 var10000 = Class.forName("[I");
 490             } catch (ClassNotFoundException var19) {
 491                 throw new NoClassDefFoundError(var19.getMessage());
 492             }
 493 
 494             class$4 = var10000;
 495         }
 496 
 497         setNullHandler(var10000, nh);
 498         var10000 = class$5;
 499         if(class$5 == null) {
 500             try {
 501                 var10000 = Class.forName("[J");
 502             } catch (ClassNotFoundException var18) {
 503                 throw new NoClassDefFoundError(var18.getMessage());
 504             }
 505 
 506             class$5 = var10000;
 507         }
 508 
 509         setNullHandler(var10000, nh);
 510         var10000 = class$6;
 511         if(class$6 == null) {
 512             try {
 513                 var10000 = Class.forName("[F");
 514             } catch (ClassNotFoundException var17) {
 515                 throw new NoClassDefFoundError(var17.getMessage());
 516             }
 517 
 518             class$6 = var10000;
 519         }
 520 
 521         setNullHandler(var10000, nh);
 522         var10000 = class$7;
 523         if(class$7 == null) {
 524             try {
 525                 var10000 = Class.forName("[D");
 526             } catch (ClassNotFoundException var16) {
 527                 throw new NoClassDefFoundError(var16.getMessage());
 528             }
 529 
 530             class$7 = var10000;
 531         }
 532 
 533         setNullHandler(var10000, nh);
 534         var10000 = class$8;
 535         if(class$8 == null) {
 536             try {
 537                 var10000 = Class.forName("[Ljava.lang.Object;");
 538             } catch (ClassNotFoundException var15) {
 539                 throw new NoClassDefFoundError(var15.getMessage());
 540             }
 541 
 542             class$8 = var10000;
 543         }
 544 
 545         setNullHandler(var10000, nh);
 546         ObjectMethodAccessor ma = new ObjectMethodAccessor();
 547         var10000 = class$0;
 548         if(class$0 == null) {
 549             try {
 550                 var10000 = Class.forName("java.lang.Object");
 551             } catch (ClassNotFoundException var14) {
 552                 throw new NoClassDefFoundError(var14.getMessage());
 553             }
 554 
 555             class$0 = var10000;
 556         }
 557 
 558         setMethodAccessor(var10000, ma);
 559         var10000 = class$1;
 560         if(class$1 == null) {
 561             try {
 562                 var10000 = Class.forName("[B");
 563             } catch (ClassNotFoundException var13) {
 564                 throw new NoClassDefFoundError(var13.getMessage());
 565             }
 566 
 567             class$1 = var10000;
 568         }
 569 
 570         setMethodAccessor(var10000, ma);
 571         var10000 = class$2;
 572         if(class$2 == null) {
 573             try {
 574                 var10000 = Class.forName("[S");
 575             } catch (ClassNotFoundException var12) {
 576                 throw new NoClassDefFoundError(var12.getMessage());
 577             }
 578 
 579             class$2 = var10000;
 580         }
 581 
 582         setMethodAccessor(var10000, ma);
 583         var10000 = class$3;
 584         if(class$3 == null) {
 585             try {
 586                 var10000 = Class.forName("[C");
 587             } catch (ClassNotFoundException var11) {
 588                 throw new NoClassDefFoundError(var11.getMessage());
 589             }
 590 
 591             class$3 = var10000;
 592         }
 593 
 594         setMethodAccessor(var10000, ma);
 595         var10000 = class$4;
 596         if(class$4 == null) {
 597             try {
 598                 var10000 = Class.forName("[I");
 599             } catch (ClassNotFoundException var10) {
 600                 throw new NoClassDefFoundError(var10.getMessage());
 601             }
 602 
 603             class$4 = var10000;
 604         }
 605 
 606         setMethodAccessor(var10000, ma);
 607         var10000 = class$5;
 608         if(class$5 == null) {
 609             try {
 610                 var10000 = Class.forName("[J");
 611             } catch (ClassNotFoundException var9) {
 612                 throw new NoClassDefFoundError(var9.getMessage());
 613             }
 614 
 615             class$5 = var10000;
 616         }
 617 
 618         setMethodAccessor(var10000, ma);
 619         var10000 = class$6;
 620         if(class$6 == null) {
 621             try {
 622                 var10000 = Class.forName("[F");
 623             } catch (ClassNotFoundException var8) {
 624                 throw new NoClassDefFoundError(var8.getMessage());
 625             }
 626 
 627             class$6 = var10000;
 628         }
 629 
 630         setMethodAccessor(var10000, ma);
 631         var10000 = class$7;
 632         if(class$7 == null) {
 633             try {
 634                 var10000 = Class.forName("[D");
 635             } catch (ClassNotFoundException var7) {
 636                 throw new NoClassDefFoundError(var7.getMessage());
 637             }
 638 
 639             class$7 = var10000;
 640         }
 641 
 642         setMethodAccessor(var10000, ma);
 643         var10000 = class$8;
 644         if(class$8 == null) {
 645             try {
 646                 var10000 = Class.forName("[Ljava.lang.Object;");
 647             } catch (ClassNotFoundException var6) {
 648                 throw new NoClassDefFoundError(var6.getMessage());
 649             }
 650 
 651             class$8 = var10000;
 652         }
 653 
 654         setMethodAccessor(var10000, ma);
 655         primitiveTypes.put("boolean", Boolean.TYPE);
 656         primitiveTypes.put("byte", Byte.TYPE);
 657         primitiveTypes.put("short", Short.TYPE);
 658         primitiveTypes.put("char", Character.TYPE);
 659         primitiveTypes.put("int", Integer.TYPE);
 660         primitiveTypes.put("long", Long.TYPE);
 661         primitiveTypes.put("float", Float.TYPE);
 662         primitiveTypes.put("double", Double.TYPE);
 663         primitiveDefaults.put(Boolean.TYPE, Boolean.FALSE);
 664         primitiveDefaults.put(Byte.TYPE, new Byte((byte)0));
 665         primitiveDefaults.put(Short.TYPE, new Short((short)0));
 666         primitiveDefaults.put(Character.TYPE, new Character('\u0000'));
 667         primitiveDefaults.put(Integer.TYPE, new Integer(0));
 668         primitiveDefaults.put(Long.TYPE, new Long(0L));
 669         primitiveDefaults.put(Float.TYPE, new Float(0.0F));
 670         primitiveDefaults.put(Double.TYPE, new Double(0.0D));
 671         OgnlRuntime.ClassCache var52 = primitiveDefaults;
 672         Class var10001 = class$16;
 673         if(class$16 == null) {
 674             try {
 675                 var10001 = Class.forName("java.math.BigInteger");
 676             } catch (ClassNotFoundException var5) {
 677                 throw new NoClassDefFoundError(var5.getMessage());
 678             }
 679 
 680             class$16 = var10001;
 681         }
 682 
 683         var52.put(var10001, new BigInteger("0"));
 684         var52 = primitiveDefaults;
 685         var10001 = class$17;
 686         if(class$17 == null) {
 687             try {
 688                 var10001 = Class.forName("java.math.BigDecimal");
 689             } catch (ClassNotFoundException var4) {
 690                 throw new NoClassDefFoundError(var4.getMessage());
 691             }
 692 
 693             class$17 = var10001;
 694         }
 695 
 696         var52.put(var10001, new BigDecimal(0.0D));
 697     }
 698 

它提供支持许多的bean类8个基本类型,还有map,list,arraylist等.然后使用对象提供的set和get来进行数据绑定.而ognl在解析xml的时候,会首先进入该源代码

代码语言:javascript
复制
public class OgnlParserTokenManager implements OgnlParserConstants {
    Object literalValue;
    private char charValue;
    private char charLiteralStartQuote;
    private StringBuffer stringBuffer;
    public PrintStream debugStream;
    static final long[] jjbitVec0 = new long[]{2301339413881290750L, -16384L, 4294967295L, 432345564227567616L};
    static final long[] jjbitVec2 = new long[]{0L, 0L, 0L, -36028797027352577L};
    static final long[] jjbitVec3 = new long[]{0L, -1L, -1L, -1L};
    static final long[] jjbitVec4 = new long[]{-1L, -1L, 65535L, 0L};
    static final long[] jjbitVec5 = new long[]{-1L, -1L, 0L, 0L};
    static final long[] jjbitVec6 = new long[]{70368744177663L, 0L, 0L, 0L};
    static final long[] jjbitVec7 = new long[]{-2L, -1L, -1L, -1L};
    static final long[] jjbitVec8 = new long[]{0L, 0L, -1L, -1L};
    static final int[] jjnextStates = new int[]{15, 16, 18, 19, 22, 13, 24, 25, 7, 9, 10, 13, 17, 10, 13, 11, 12, 20, 21, 1, 2, 3};
    public static final String[] jjstrLiteralImages = new String[]{"", ",", "=", "?", ":", "||", "or", "&&", "and", "|", "bor", "^", "xor", "&", "band", "==", "eq", "!=", "neq", "<", "lt", ">", "gt", "<=", "lte", ">=", "gte", "in", "not", "<<", "shl", ">>", "shr", ">>>", "ushr", "+", "-", "*", "/", "%", "~", "!", "instanceof", ".", "(", ")", "true", "false", "null", "#this", "#root", "#", "[", "]", "{", "}", "@", "new", "$", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null};
    public static final String[] lexStateNames = new String[]{"DEFAULT", "WithinCharLiteral", "WithinBackCharLiteral", "WithinStringLiteral"};

可以看到需要#{}之类的 或者#name等才能被ognl识别,然后才能解析...,然后回到我们的这个问题

对于if语句中的 DomainID 并没有被标识符标记,因而识别不出,所以启动ognl解析的时候,会自认为他是自定义的变量,自定义它的开发者应该会编写它对应的get和set方法,所以ongl会默认的去调用该对象的set,get方法,然而

我们对Domain对象是一个java.lang.Integer对象,本身没有get,set方法。所以才会爆出开始的那些异常. 这应该就是问题所在了,然后如何解决呢?

1. 方法一:

封装一下这个元素或者使用map来封装.

代码语言:javascript
复制
//对DomainID进行封装

class myId{
   private Integer  DomainID;
   public Integer getDomainID(){
     return DomainID;
   }
  public void SetDomainID(Integer id){
     DomainID = id;
   }
}

2.采用将DomainID改为 _parameter

代码语言:javascript
复制
<where>
            <if test="_parameter != null and _parameter !='' ">
                DomainID=#{_parameter}
            </if>
 </where>

3.使用@Param注解

如果我们使用的是接口Interface方式

使用

代码语言:javascript
复制
public ABLayer GetInfos( @Param(value="DomainID") Integer DomainID);
代码语言:javascript
复制
    <select id="GetInfos" parameterType="java.lang.Integer" resultMap="ABLayer">
        select *
        from ab_layer
        <where>
            <if test="DomainID != null and DomainID !='' ">
                DomainID=#{DomainID}
            </if>
        </where>
        order by ID
    </select>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-08-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档