<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] # 簡介 OGNL:對象視圖導航語言. `${user.addr.name}` 這種寫法就叫對象視圖導航. OGNL不僅僅可以視圖導航.支持比EL表達式更加豐富的功能. 它是一種功能強大的表達式語言,通過它簡單一致的表達式語法,可以存取對象的任意屬性,調用對象的方法,遍歷整個對象的結構圖,實現字段類型轉化等功能。它使用相同的表達式去存取對象的屬性 Strtsu2框架內置了OGNL OGNL本身也是一個項目,它是可以單獨使用。 OGNL作用: 支持對象的操作,調用對象的方法 支持靜態成員訪問 支持賦值操作與表達串聯 訪問OGNL上下文,訪問ActionContext 操作集合對象 搭建環境:單獨使用OGNL來完成示例 ![](https://box.kancloud.cn/498000ae8106df060c68c13c2a091f84_704x800.png) OGNL三要素: 表達式 OgnlContext 上下文 Root 根 ![](https://box.kancloud.cn/96dc7ef56579bfed7055a7bb8c22bc58_822x752.png) # 作用 ![](https://box.kancloud.cn/655a68ad59134421cd542b584aa80989_1230x384.png) # 基本演示 準備測試類,User類 ~~~ package bean; public class User { private String name; private Integer age; public User() { super(); } public User(String name, Integer age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "User [name=" + name + ", age=" + age + "]"; } } ~~~ ## 取出root中的屬性值 ~~~ @Test public void fun1() throws OgnlException { // 準備ONGLContext // 準備Root User rootUser = new User("tom", 18); // 準備Context Map<String, User> context = new HashMap<String, User>(); context.put("user1", new User("jack", 18)); context.put("user2", new User("rose", 22)); // 它就是個java.util.map OgnlContext oc = new OgnlContext(); // 將rootUser作為root部分 oc.setRoot(rootUser); // 將context這個Map作為Context部分 oc.setValues(context); // 書寫OGNL String name = (String) Ognl.getValue("name", oc, oc.getRoot()); Integer age = (Integer) Ognl.getValue("age", oc, oc.getRoot()); System.out.println(name); System.out.println(age); } ~~~ ## 為屬性賦值 ~~~ // 準備ONGLContext // 準備Root User rootUser = new User("tom", 18); // 準備Context Map<String, User> context = new HashMap<String, User>(); context.put("user1", new User("jack", 18)); context.put("user2", new User("rose", 22)); // 它就是個java.util.map OgnlContext oc = new OgnlContext(); // 將rootUser作為root部分 oc.setRoot(rootUser); // 將context這個Map作為Context部分 oc.setValues(context); // 將root中的user對象的name屬性賦值 Ognl.getValue("name='jerry'", oc, oc.getRoot()); String name = (String) Ognl.getValue("name", oc, oc.getRoot()); String name1 = (String) Ognl.getValue("#user1.name='jdxia',#user1.name", oc, oc.getRoot()); System.out.println(name); System.out.println(name1); ~~~ ## 調用方法 ~~~ // 準備ONGLContext // 準備Root User rootUser = new User("tom", 18); // 準備Context Map<String, User> context = new HashMap<String, User>(); context.put("user1", new User("jack", 18)); context.put("user2", new User("rose", 22)); // 它就是個java.util.map OgnlContext oc = new OgnlContext(); // 將rootUser作為root部分 oc.setRoot(rootUser); // 將context這個Map作為Context部分 oc.setValues(context); // 調用root中user對象的setName方法 Ognl.getValue("setName('lilei')", oc, oc.getRoot()); String name = (String) Ognl.getValue("getName()", oc, oc.getRoot()); String name2 = (String) Ognl.getValue("#user1.setName('lucy'),#user1.getName()", oc, oc.getRoot()); System.out.println(name); System.out.println(name2); ~~~ ![](https://box.kancloud.cn/794d6cdd3ee8b79d3c10e16e7286c3ba_1630x442.png) ## 調用靜態方法 準備測試類HahaUtils ~~~ package bean; public class HahaUtils { // 回音方法 public static Object echo(Object o) { return o; } } ~~~ ~~~ // 準備ONGLContext // 準備Root User rootUser = new User("tom", 18); // 準備Context Map<String, User> context = new HashMap<String, User>(); context.put("user1", new User("jack", 18)); context.put("user2", new User("rose", 22)); // 它就是個java.util.map OgnlContext oc = new OgnlContext(); // 將rootUser作為root部分 oc.setRoot(rootUser); // 將context這個Map作為Context部分 oc.setValues(context); String name = (String) Ognl.getValue("@bean.HahaUtils@echo('hello')", oc, oc.getRoot()); //Double pi = (Double) Ognl.getValue("@java.lang.Math@PI", oc, oc.getRoot()); //內置 Double pi = (Double) Ognl.getValue("@@PI", oc, oc.getRoot()); System.out.println(name); System.out.println(pi); ~~~ ## 創建對象(List,Map) ~~~ // 準備ONGLContext // 準備Root User rootUser = new User("tom", 18); // 準備Context Map<String, User> context = new HashMap<String, User>(); context.put("user1", new User("jack", 18)); context.put("user2", new User("rose", 22)); // 它就是個java.util.map OgnlContext oc = new OgnlContext(); // 將rootUser作為root部分 oc.setRoot(rootUser); // 將context這個Map作為Context部分 oc.setValues(context); // 創建list對象 Integer size = (Integer) Ognl.getValue("{'tom','jerry','jack','rose'}.size()", oc, oc.getRoot()); String name = (String) Ognl.getValue("{'tom','jerry','jack','rose'}[0]", oc, oc.getRoot()); String name2 = (String) Ognl.getValue("{'tom','jerry','jack','rose'}.get(1)", oc, oc.getRoot()); System.out.println(size); System.out.println(name); System.out.println(name2); // 創建map對象 Integer size2 = (Integer) Ognl.getValue("#{'name':'tom','age':18}.size()", oc, oc.getRoot()); String name3 = (String) Ognl.getValue("#{'name':'tom','age':18}['name']", oc, oc.getRoot()); Integer age = (Integer) Ognl.getValue("#{'name':'tom','age':18}.get('age')", oc, oc.getRoot()); System.out.println(size2); System.out.println(name3); System.out.println(age); ~~~ ![](https://box.kancloud.cn/27ea9bd3b076eaa10eaafa49de41421b_1896x1066.png) ## 訪問Ognl上下文 ![](https://box.kancloud.cn/813365a3cc1a9dc92dc0c6912a1a3f4a_1714x1388.png) # struts2和Ognl結合 ## 結合原理 ![](https://box.kancloud.cn/b5b309ac88dc71a2b51c7f61fbcacc09_1488x754.png) ![](https://box.kancloud.cn/e2daff58d6833f298c27e6c6d900db5b_1494x448.png) ![](https://box.kancloud.cn/31ed8140137b59fde03951efa60f062a_1054x330.png) ![](https://box.kancloud.cn/4ab3fa8de314923b6609997885dac6d7_1238x134.png) ![](https://box.kancloud.cn/24a2b7e8b45894f25d439303f18698f3_968x574.png) ![](https://box.kancloud.cn/80621376ad8e1dde285237cdf1638e52_916x308.png) ## Strtus2框架中如何使用ognl表達式 在struts2框架中我們使用ognl表達式的作用是從valueStack中獲取數據。 我們在struts2框架中可以使用ognl+valueStack達到在頁面(jsp)上來獲取相關的數據。 要想在jsp頁面上使用ognl表達式,就需要結合struts2框架的標簽 `<s:property value=”表達式”>`來使用 ![](https://box.kancloud.cn/e3e9953b94abbd6529453e11c5df9bea_1894x1096.png) 默認情況下,棧中放置當前訪問的Action對象 ![](https://box.kancloud.cn/8bb9e16d4068d909e342ae89862298f2_1248x414.png) ![](https://box.kancloud.cn/b194eb3539ca70c84637c4629fab87f0_1410x498.png) ![](https://box.kancloud.cn/c745c1aae03f22a277d6b11949f03752_694x592.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看