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

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

这是 mybatis 源文件

  public ABLayer GetInfos(final int DomainID) {

return sqlSession.selectOne("abLayer.GetInfos",DomainID);
}
 <!---->
<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>条件之后

  <where>
<if test="DomainID != null and DomainID !='' ">
DomainID=#{DomainId}
</if>
</where>

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

 public class OgnlContext implements Map {
public static final String CONTEXT_CONTEXT_KEY = "context";
public static final String ROOT_CONTEXT_KEY = "root";
public static final String THIS_CONTEXT_KEY = "this";
public static final String TRACE_EVALUATIONS_CONTEXT_KEY = "_traceEvaluations";
public static final String LAST_EVALUATION_CONTEXT_KEY = "_lastEvaluation";
public static final String KEEP_LAST_EVALUATION_CONTEXT_KEY = "_keepLastEvaluation";
public static final String CLASS_RESOLVER_CONTEXT_KEY = "_classResolver";
public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
public static final String MEMBER_ACCESS_CONTEXT_KEY = "_memberAccess";
private static final String PROPERTY_KEY_PREFIX = "ognl";

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

   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的时候,会首先进入该源代码

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来封装.

//对DomainID进行封装

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

2.采用将DomainID改为 _parameter

<where>
<if test="_parameter != null and _parameter !='' ">
DomainID=#{_parameter}
</if>
</where>

3.使用@Param注解

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

使用

public ABLayer GetInfos( @Param(value="DomainID") Integer DomainID);
    <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>

mybatis 对于基本类型数据传值的问题的更多相关文章

  1. mybatis中为sql中传值#{}和${}的区别

    在mybatis中,配置文件中sql的值,用#{}表示,例如: <select id="getTeacher" resultType="Teacher"& ...

  2. MyBatis对数据库的增删改查操作,简单演示样例

    之前一直有用Hibernate进行开发.近期公司在使用Mybatis.依据网上的演示样例,做了一个简单的Demo,以便日后复习 使用XMl方式映射sql语句 整体结构例如以下图 watermark/2 ...

  3. Mybatis 复习

    概述 mybatis 是一个用java编写的持久层框架, 它封装了jdbc操作的很多细节,使开发者只需要关注sql语句本身,而无需关注注册驱动,创建连接等繁杂过程,它使用了ORM思想实现了结果 集的封 ...

  4. [转]Angular2-组件间数据传递的两种方式

    本文转自:https://www.cnblogs.com/longhx/p/6960288.html Angular2组件间数据传递有多种方式,其中最常用的有两种,一种是配置元数据(或者标签装饰),一 ...

  5. Angular2-组件间数据传递的两种方式

    Angular2组件间数据传递有多种方式,其中最常用的有两种,一种是配置元数据(或者标签装饰),一种是用单例模块传递:有两个元数据具有传递数据的功能:inputs和outputs. 一.元数据传递 1 ...

  6. NDK-JNI实战教程(二) JNI官方中文资料

    声明 设计概述 JNI接口函数和指针 加载和链接本地方法 解析本地方法名 本地方法的参数 引用Java对象 全局和局部引用 实现局部引用 访问Java对象 访问基本类型数组 访问域和方法 报告编程错误 ...

  7. android NDK 实用学习(二)-java端对象成员赋值和获取对象成员值

    1,关于java端类及接口定义请参考: android NDK 实用学习-获取java端类及其类变量 2,对传过来的参数进行赋值: 对bool类型成员进行赋值  env->SetBooleanF ...

  8. 【转】JNI学习积累之一 ---- 常用函数大全

    原文网址:http://blog.csdn.net/qinjuning/article/details/7595104 本文原创,转载请注明出处:http://blog.csdn.net/qinjun ...

  9. Java IO学习笔记

    Java流的分类,一般可按以下方式分: 按方向分,分为输入流,输出流. 按类型分,分为字节流和字符流. 2.1字节流是通过字节来读取数据 2.2字符流是通过字符来读取数据 按操作方式分,分为节点流和过 ...

随机推荐

  1. exp_tools

    #pwntools # github https://github.com/Gallopsled/pwntools 在线帮助文档 https://docs.pwntools.com/en/stable ...

  2. PLSQL Developer导入Excel数据

    LSQL Developer导入Excel数据 最近处理将Excel数据导入Oracle的工作比较多.之前都是采用Sqlldr命令行导入的方式处理.每次导入不同格式的Excel表数据,都需要先把Exc ...

  3. python字符串方法的简单使用

    学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...

  4. eclipse左侧不见

    我的解决办法: eclipse--->  Window --->Perspective--> Open Perspective-->Java

  5. easyui DataGrid 工具类之 WorkbookUtil class

    /** * @Title: WorkbookUtil.java * @Description: excel工具类 * @date 2014年5月29日 上午10:36:42 * @version V1 ...

  6. 《在纹线方向上进行平滑滤波,在纹线的垂直方向上进行锐化滤波》 --Gabor增强的具体实践

    <在纹线方向上进行平滑滤波,在纹线的垂直方向上进行锐化滤波>                                          --Gabor增强的具体实践     一.问 ...

  7. R语言读写中文编码方式

    最近遇到一个很头疼的事,就是 R语言读写中文编码方式.在网上找到了一篇博文,谢谢博主的精彩分享,让我很快解决了问题,在此也分享一下 R语言读写数据的方法很多,这里主要是我在使用read.csv/rea ...

  8. Ubuntu-server14.04搭建LAMP环境

    转自:http://www.cnblogs.com/myzhibie/p/4330327.html 对于很多PHP初学开发者来讲,搭建一个可用于生产的LAMP环境是一件费时费力的事情,本文以 ubun ...

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  10. [bzoj1122][POI2008]账本BBB

    1122: [POI2008]账本BBB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 402  Solved: 202[Submit][Status ...