<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 495,  comments - 11,  trackbacks - 0

    OGNL是Object Graph Navigation Language的縮寫,與JSP,JSF相比,OGNL是一種功能非常強大的針對Java的表達式語言(EL),它可用來讀取和更新Java對象的屬性。

    OGNL可以用在以下方面:
    - 用做數(shù)據(jù)綁定語言用來綁定GUI元素(textfield, combobox等)到模型對象
    - 用做數(shù)據(jù)源語言用來映射數(shù)據(jù)庫表到表模型對象
    - 用做數(shù)據(jù)綁定語言用來綁定web組件到數(shù)據(jù)模型(WebOGNLTapestryWebWork等)
    - 提供類似Jakarta Commons BeanUtils所提供的功能(讀取Java對象的屬性)

    OGNL表達式語法:
    Java標準類型:
    bool類型:true,false
    int類型:10, 0xABCD等
    long類型:100L
    float類型:1.0, 0.5F等
    double類型:0.01D
    char類型:'A', '\uFFFF'等
    字符串類型:"Hello World!"
    null

    OGNL獨自類型:
    例:10.01B,相當于java.math.BigDecimal
    例:100000H,相當于java.math.BigInteger

    OGNL表達式中能使用的操作符號:
    OGNL表達式中能使用的操作符基本跟Java里的操作符一樣,除了能使用 +, -, *, /, ++, --, ==, !=, = 等操作符之外,還能使用 mod, in, not in等

    變量的引用:
    使用方法:#變量名
    例:#this, #user.name

    對靜態(tài)方法或變量的訪問:
    @mypkg.MyClass@myVar
    @mypkg.MyClass@myMethod()

    讀取變量值:
    例:user.address.countryName

    方法調(diào)用:
    例:user.getName()

    對象的創(chuàng)建:
    new java.net.URL("http://localhost/")

    List表達式例:
    {"green", "red", "blue"}


    Map表達式例:
    #{"key1" : "value1", "key2" : "value2", "key3" : "value3"}
    對map引用,例:map.key1

    等等。

    OGNL官方首頁:
    http://www.ognl.org/

    OGNL官方文檔 (2.6.9)
    OGNL Language Guide (2.6.9)

    附:
    OGNL使用例:
    1. package com.test.ognl; ??
    2. import java.util.HashMap; ??
    3. import java.util.List; ??
    4. import java.util.Map; ??
    5. ??
    6. import junit.framework.TestCase; ??
    7. import ognl.Ognl; ??
    8. import ognl.OgnlContext; ??
    9. ??
    10. public class OgnlTest extends TestCase { ??
    11. ????public void testGetValue() throws Exception { ??
    12. ???????? OgnlContext context = new OgnlContext(); ??
    13. ???????? Book book = new Book("book1"); ??
    14. ???????? context.put("book", book); ??
    15. ??
    16. ????????final String expression = "book.name"; ??
    17. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    18. ???????? assertEquals("book1", Ognl.getValue(parseExpression, context)); ??
    19. ???????? ??
    20. ???????? book.setName("book2"); ??
    21. ???????? assertEquals("book2", Ognl.getValue(parseExpression, context)); ??
    22. ???? } ??
    23. ???? ??
    24. ????public void testSetValue() throws Exception { ??
    25. ???????? OgnlContext context = new OgnlContext(); ??
    26. ???????? Book book = new Book("book1"); ??
    27. ???????? context.put("book", book); ??
    28. ??
    29. ????????final String expression = "book.name"; ??
    30. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    31. ???????? Ognl.setValue(parseExpression, context, "book2"); ??
    32. ???????? assertEquals("book2", book.getName()); ??
    33. ???? } ??
    34. ???? ??
    35. ????public void testCallStaticMethod() throws Exception { ??
    36. ???????? OgnlContext context = new OgnlContext(); ??
    37. ??
    38. ????????final String expression = "@com.test.ognl.Book@test()"; ??
    39. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    40. ???????? assertEquals("Hello World", Ognl.getValue(parseExpression, context)); ??
    41. ???? } ??
    42. ???? ??
    43. ????public void testArray() throws Exception { ??
    44. ???????? OgnlContext context = new OgnlContext(); ??
    45. ??
    46. ????????final String expression = "new int[]{1, 2, 3}"; ??
    47. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    48. ????????int[] ret = (int[]) Ognl.getValue(parseExpression, context); ??
    49. ??
    50. ???????? assertEquals(1, ret[0]); ??
    51. ???????? assertEquals(2, ret[1]); ??
    52. ???????? assertEquals(3, ret[2]); ??
    53. ???? } ??
    54. ??
    55. ????public void testList() throws Exception { ??
    56. ???????? OgnlContext context = new OgnlContext(); ??
    57. ??
    58. ????????final String expression = "{1, 2, 3}"; ??
    59. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    60. ???????? List ret = (List) Ognl.getValue(parseExpression, context); ??
    61. ??
    62. ???????? assertEquals(new Integer(1), ret.get(0)); ??
    63. ???????? assertEquals(new Integer(2), ret.get(1)); ??
    64. ???????? assertEquals(new Integer(3), ret.get(2)); ??
    65. ???? } ??
    66. ???? ??
    67. ????public void testMap() throws Exception { ??
    68. ???????? OgnlContext context = new OgnlContext(); ??
    69. ??
    70. ????????final String expression = "#{\"name\" : \"book1\", \"price\" : 10.2}"; ??
    71. ???????? Object parseExpression = Ognl.parseExpression(expression); ??
    72. ???????? Map value = (Map) Ognl.getValue(parseExpression, context); ??
    73. ???????? assertEquals("book1", value.get("name")); ??
    74. ???????? assertEquals(new Integer(10.2), value.get("price")); ??
    75. ???? } ??
    76. } ??
    77. ??
    78. class Book { ??
    79. ????private int name; ??
    80. ??
    81. ????public Book(String bookName) { ??
    82. ????????this.name = bookName; ??
    83. ???? } ??
    84. ????public int getName() { ??
    85. ????????return name; ??
    86. ???? } ??
    87. ??
    88. ????public void setName(int Name) { ??
    89. ????????this.name = name; ??
    90. ???? } ??
    91. ??
    92. ????// test static method ??
    93. ????public static String hello() { ??
    94. ????????return "Hello World"; ??
    95. ???? }??

    posted on 2009-08-12 18:19 jadmin 閱讀(109) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 999国内精品永久免费观看| 丰满妇女做a级毛片免费观看| 亚洲成人免费在线| 青青草原亚洲视频| 国产视频精品免费视频| 亚洲日韩精品一区二区三区无码 | 大片免费观看92在线视频线视频 | 亚洲国产成人资源在线软件| 性xxxx视频免费播放直播 | 亚洲αv在线精品糸列| 在线涩涩免费观看国产精品| 久久国产精品亚洲综合| 97公开免费视频| tom影院亚洲国产一区二区| 性一交一乱一视频免费看| 最新亚洲人成无码网站| 亚洲国产a级视频| 永久免费av无码网站yy| 亚洲综合无码一区二区三区| 国产精品视频免费一区二区| 亚洲AV无码专区国产乱码不卡| 免费一级毛片在线播放不收费 | 久久成人国产精品免费软件| 亚洲依依成人精品| 国产午夜无码视频免费网站| 国产在线精品一区免费香蕉| 亚洲自偷精品视频自拍| 扒开双腿猛进入爽爽免费视频| 日本精品久久久久久久久免费| 亚洲乱码中文字幕久久孕妇黑人| 18成禁人视频免费网站| 亚洲爆乳AAA无码专区| 亚洲午夜无码毛片av久久京东热| 国产精品免费看久久久无码| 四虎影视无码永久免费| 亚洲六月丁香六月婷婷色伊人| 四虎影永久在线高清免费| 久久青草免费91观看| 亚洲乱色伦图片区小说| 国产精品亚洲一区二区三区在线 | 国产亚洲国产bv网站在线|