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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## XML支持 beetlsql提供一個子模塊支持`sql-xml` XML,語法上借鑒了mybatis,這是beetlsql的擴展包,因此需要額外引入 ```xml <dependency> <groupId>com.ibeetl</groupId> <artifactId>sql-xml</artifactId> <version>3.23.11-RELEASE</version> </dependency> ``` 如下是一個xml文件定義 ```xml <?xml version="1.0" encoding="UTF-8" ?> <beetlsql> <sql id="select"> <!-- 測試sql --> select * from sys_user <where> <if test="has(user) and user.name=='a'"> and name='3' </if> <bind value="1+99" export="newValue"/> <isNotEmpty value="'1'"> and name='5' </isNotEmpty> and name = #{newValue} and name in <foreach items="[1,2,3]" var="id,status" open="(" close=")" separator=","> #{id+status.index} </foreach> <include refid="commonWhere"/> </where> </sql> <resultMap id="simpleMap"> <result property="id" column="id"/> <result property="myName" column="user_name"/> </resultMap> <resultMap id="complexMap"> <result property="id" column="id"/> <association property="info" > <result property="name" column="name"/> <result property="age" column="age"/> </association> </resultMap> <resultMap id="complexListMap"> <result property="id" column="id"/> <collection property="listInfo" > <result property="name" column="name"/> <result property="age" column="age"/> </collection> </resultMap> </beetlsql> ``` > 參考源碼sql-test下的代碼QuickXMLTestBeetlSQL,以及對應的xml文件user.xml 因為xml支持并非xml核心功能,因此需要一定步奏引入和配置 1) sqlLoader使用XMLClasspathLoader,可以通過配置或者api設定 ```java ConnectionSource source = .... SQLManagerBuilder builder = new SQLManagerBuilder(source); builder.setNc(new UnderlinedNameConversion()); builder.setDbStyle(new H2Style()); builder.setInters(new Interceptor[]{new DebugInterceptor()}); builder.setSqlLoader(new XMLClasspathLoader("sql")); sqlManager = builder.build(); ``` 2. 同創建md文件那樣,創建xml文件,格式可以參考如上例子 3. 如果提供的xml tag不夠用,可以完全自定義tag,以if標簽實現為例子,用beetl的標簽實現,參考http://www.hmoore.net/xiandafu/beetl3_guide/2138969 了解如何定義標簽 ```java public class IfTag extends Tag{ @Override public void render() { if (!containHtmlAttribute("test")) { throw new IllegalArgumentException("缺少 test屬性"); } Object value = this.getHtmlAttribute("test"); if (!(value instanceof Boolean)) { throw new IllegalArgumentException("期望test表達式運算結果是boolean類型"); } if ((Boolean) value) { this.doBodyRender(); } } } ``` 4. 調用XMLBeetlSQL,初始化xml支持,如果你定義了xml標簽,調用 ```java XMLBeetlSQL.config(sqlManager); //可選,自定義tag XMLBeetlSQL.regisregisterTagter(sqlManager,"yourTag",YourTag.clas); ``` 初始化XML支持后,就可以像使用md文件那樣使用XML文件 5. 如果有自定義映射,可以在xml文件定義resultMap,并通過@ResultProvider(XMLConfigMapper.class) 和@XMLMapper(resource=sqlId) 來指定對象的映射文件 ```java @Test public void testForeach(){ Map map = new HashMap(); map.put("ids", Arrays.asList(1,2)); //訪問的是user.xml文件下的 testFoeach 標簽 List<User> list = sqlManager.select(SqlId.of("user.testForeach"),User.class,map); Assert.assertTrue(list.size()==2); } @Test public void testComplexXMLMapping(){ String sql = "select id,name,age from sys_user"; List<MyXMLComplexUser> list = sqlManager.execute(new SQLReady(sql),MyXMLComplexUser.class); Assert.assertTrue(list.get(0) instanceof MyXMLComplexUser ); } @ResultProvider(XMLConfigMapper.class) @XMLMapper(resource="user.complexMap") @Data public static class MyXMLComplexUser { private Long id; private MyXMLComplexUserInfo info; } @Data public static class MyXMLComplexUserInfo { private String name; private Integer age; } ``` user.complexMap對應了user.xml的映射配置 ```xml <resultMap id="complexMap"> <result property="id" column="id"/> <association property="info" > <result property="name" column="name"/> <result property="age" column="age"/> </association> </resultMap> ```
                  <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>

                              哎呀哎呀视频在线观看