ognl表达式中判断字符串常量的注意事项

来源:互联网 发布:linux开机挂载硬盘 编辑:程序博客网 时间:2024/03/29 15:25
                // OGNL与单个字符常量做等号判断,会被转成数值型Map<String, Object> context = new HashMap<String, Object>();context.put("id", "1");context.put("name", "z");context.put("sex", "man");System.out.println(context);// 单个字符的数字型字符串System.out.println(getValue("id == '1'", context));// falseSystem.out.println(getValue("id == '1'.toString()", context));// true// 单个字符的非数字型字符串try {System.out.println(getValue("name == 'z'", context));} catch (Exception e) {// 'z'不能被转成数值型,此处会抛出NumberFormatExceptione.printStackTrace();}System.out.println(getValue("name == \"z\"", context));// trueSystem.out.println(getValue("name == 'z'.toString()", context));// true// 不是单个字符的字符串System.out.println(getValue("sex == 'man'", context));// trueSystem.out.println(getValue("sex == \"man\"", context));// trueSystem.out.println(getValue("sex == 'man'.toString()", context));// true

0 0
原创粉丝点击