<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 3.4 SpringMVC集成 適用于Spring 6+JDK17 ```xml <dependency> <groupId>com.ibeetl</groupId> <artifactId>beetl-spring</artifactId> <version>3.14.1.RELEASE</version> </dependency> ``` 適用于Spring 5以下 ```xml <dependency> <groupId>com.ibeetl</groupId> <artifactId>beetl-spring-classic</artifactId> <version>3.14.1.RELEASE</version> </dependency> ``` ### 3.4.1 普通集成 Srping5 需要做如下配置即可包名是org.beetl.ext.spring6) ```xml <bean id="beetlConfig" class="org.beetl.ext.spring6.BeetlGroupUtilConfiguration" init-method="init"/> <bean id="viewResolver" class="org.beetl.ext.spring6.BeetlSpringViewResolver"> <property name="contentType" value="text/html;charset=UTF-8"/> </bean> ``` 或者Spring5以下(包名是org.beetl.ext.spring) ```xml <bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"/> <bean id="viewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver"> <property name="contentType" value="text/html;charset=UTF-8"/> </bean> ``` 同其他集成方式一樣,模板的配置將放在beetl.properties中。 如果想獲取GroupTemplate,可以調用如下代碼 ```java BeetlGroupUtilConfiguration config = (BeetlGroupUtilConfiguration) this.getApplicationContext().getBean("beetlConfig"); GroupTemplate group = config.getGroupTemplate(); ``` Controller代碼如下: ```java @RequestMapping(value = "/", method = RequestMethod.GET) public ModelAndView index(HttpServletRequest req) { ModelAndView view = new ModelAndView("/index"); //total 是模板的全局變量,可以直接訪問 view.addObject("total",service.getCount()); return view; } ``` [http://git.oschina.net/xiandafu/springbeetlsql](http://git.oschina.net/xiandafu/springbeetlsql)?有完整例子 通常可以把模板放到WEB-INF目錄下,除了可以配置beetl.propertis 外,還可以使用Spring配置 ```xml <bean id="beetlConfig" class="org.beetl.ext.spring." init-method="init"> <property name="root" value="/WEB-INF/templates"/> </bean> ``` ### 3.5 高級集成 spring集成還允許注冊被spring容器管理的Function,Tag等,也允許配置多個視圖解析器等功能 ```xml <bean name="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"> <property name="configFileResource" value="/WEB-INF/beetl.properties"/> <property name="functions"> <map> <entry key="testFunction" value-ref="testFunction"/> </map> </property> <property name="functionPackages"> <map> <entry key="fp" value-ref="testFunctionPackage"/> </map> </property> <property name="tagFactorys"> <map> <entry key="html.output" value-ref="testTagFactory"/> <entry key="html.output2" value-ref="testTagFactory2"/> </map> </property> </bean> <bean name="testTagFactory" class="org.beetl.ext.spring.SpringBeanTagFactory"> <property name="name" value="testTag"/> </bean> <bean name="testTagFactory2" class="org.beetl.ext.spring.SpringBeanTagFactory"> <property name="name" value="testTag2"/> </bean> <bean name="beetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver"> <property name="config" ref="beetlConfig"/> <property name="contentType" value="text/html;charset=UTF-8"/> </bean> ``` 如上圖所示,BeetlGroupUtilConfiguration有很多屬性,列舉如下 - configFileResource 屬性指定了配置文件所在路徑,如果不指定,則默認在classpath下 - functions 指定了被spring容器管理的function,key為注冊的方法名,value-ref 指定的bean的名稱 - functionPackages,指定了被spring容器管理的functionPackage,key為注冊的方法包名,value-ref 指定的bean的名稱 - tagFactorys ,注冊tag類,key是tag類的名稱,value-ref指向一個org.beetl.ext.spring.SpringBeanTagFactory實例,該子類是一個Spring管理的Bean。屬性name對應的bean就是tag類。需要注意,由于Tag是有狀態的,因此,必須申明Scope為 "prototype"。如代碼: ```java @Service @Scope("prototype") public class TestTag extends Tag { } ``` - typeFormats: 同functions,參數是 Map<Class<?>, Format>,其中key為類型Class - formats:同functions,參數是 Map<String, Format>,其中key為格式化函數名 - virtualClassAttributes 同functions,參數Map<Class<?>, VirtualClassAttribute>,其中key為類型Class - virtualAttributeEvals ,類型為List<VirtualAttributeEval> - resourceLoader,資源加載器 ,值是 實現ResourceLoader的一個Bean - errorHandler ,錯誤處理,值是實現ErrorHandler的一個Bean - sharedVars,同functions,類型是Map<String, Object>,可以在此設置共享變量 - configProperties,類型是Properties,可以覆蓋配置文件的某些屬性 如下配置,指定了三個視圖解析器,一個用于beetl頁面渲染,一個用于cms,采用了beetl技術,另外一個是一些遺留的頁面采用jsp ```xml <bean name="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"> <property name="configFileResource" value="/WEB-INF/beetl.properties"/> </bean> <bean name="cmsbeetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"> <property name="configFileResource" value="/WEB-INF/cms-beetl.properties"/> </bean> <!-- Beetl視圖解析器1 --> <bean name="beetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver"> <!-- 多視圖解析器,需要設置viewNames和order --> <property name="viewNames"> <list> <value>/template/**</value> </list> </property> <property name="suffix" value=".btl"/> <property name="contentType" value="text/html;charset=UTF-8"/> <property name="order" value="0"/> <!-- 多GroupTemplate,需要指定使用的bean --> <property name="config" ref="beetlConfig"/> </bean> <!-- Beetl視圖解析器2 --> <bean name="cmsBeetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver"> <!-- 多視圖解析器,需要設置viewNames和order --> <property name="viewNames"> <list> <value>/cmstemplate/**</value> </list> </property> <property name="contentType" value="text/html;charset=UTF-8"/> <property name="order" value="1"/> <!-- 多GroupTemplate,需要指定使用的bean --> <property name="config" ref="cmsbeetlConfig"/> </bean> <!-- JSP視圖解析器 --> <bean name="JSPViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 注意JSP的這個視圖解析器order必須在最后 --> <property name="order" value="256"/> <!-- beetl配置不支持前綴,這不同于jsp 和 freemaker --> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> <property name="contentType" value="text/html;charset=UTF-8"/> </bean> ``` Beetl視圖解析器屬性同spring自帶的視圖解析器一樣,支持contentType,order,prefix,suffix等屬性。 注意視圖解析器里的屬性viewNames,這個用于判斷controller返回的path到底應該交給哪個視圖解析器來做。 - 以/template開頭的是beetlViewResolver來渲染。 - 以/cmstemplate是交給cmsBeetlViewResolver渲染。 - 如果都沒有匹配上,則是jsp渲染 你也可以通過擴展名來幫助Spring決定采用哪種視圖解析器,比如 ~~~xml <property name="viewNames"> <list> <value>/**/*.btl</value> </list> </property> ~~~ 如果你想更改此規則,你只能增加canHandle方法指定你的邏輯了。詳情參考org.springframework.web.servlet.view.UrlBasedViewResolver.canHandle 對于僅僅需要redirect和forward的那些請求,需要加上相應的前綴 - 以"redirect:"為前綴時:表示重定向,不產生BeetlView渲染模版,而直接通過Servlet的機制返回重定向響應.redirect:前綴后面的內容為重定向地址,可以采用相對地址(相對當前url),絕對地址(完整的url),如果采用/開頭的地址,會自動的在前面接上當前Web應用的contextPath,即contextPath為test的Web應用中使用redirect:/admin/login.html 實際重定向地址為 /test/admin/login.html - 以"forward:"為前綴時:表示轉發,不產生BeetlView渲染模版。而是直接通過Servlet的機制轉發請求(關于轉發和重定向的區別,請自行查看Servlet API) forward:前綴后面的內容為轉發地址,一般都是以/開頭相對于當前Web應用的根目錄 其他集成需要注意的事項: - spring集成,請不要使用spring的 前綴配置,改用beetl的RESOURCE.ROOT 配置,否則include,layout會找不到模板 - 如果根目錄不是默認目錄,可以通過添加root屬性 ~~~xml <bean name="cmsbeetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"> <property name="root" value="/WEB-INF/views"/> </bean> ~~~
                  <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>

                              哎呀哎呀视频在线观看