Skip to content

Commit a7869b2

Browse files
committed
Update documentation for gh-1279
1 parent c8d3b1e commit a7869b2

File tree

5 files changed

+145
-5
lines changed

5 files changed

+145
-5
lines changed

src/site/es/xdoc/java-api.xml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,13 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
464464
</td>
465465
<td>Estas anotaciones SQL alternativas te permiten especificar un nombre de clases y un método que devolverán la SQL que debe ejecutarse (Since 3.4.6, you can specify the <code>CharSequence</code> instead of <code>String</code> as a method return type).
466466
Cuando se ejecute el método MyBatis instanciará la clase y ejecutará el método especificados en el provider. You can pass objects that passed to arguments of a mapper method, "Mapper interface type" and "Mapper method"
467-
via the <code>ProviderContext</code>(available since MyBatis 3.4.5 or later) as method argument.(In MyBatis 3.4 or later, it's allow multiple parameters) Atributos: type, method. El atributo type es el nombre completamente cualificado de una clase. El method es el nombre un método de dicha clase. Nota: A continuación hay una sección sobre la clase, que puede ayudar a construir SQL dinámico de una forma más clara y sencilla de leer.</td>
467+
via the <code>ProviderContext</code>(available since MyBatis 3.4.5 or later) as method argument.(In MyBatis 3.4 or later, it's allow multiple parameters)
468+
Atributos: type, method. El atributo type es el nombre completamente cualificado de una clase.
469+
El method es el nombre un método de dicha clase
470+
(Since 3.5.1, you can omit <code>method</code> attribute, the MyBatis will resolve a target method via the
471+
<code>ProviderMethodResolver</code> interface.
472+
If not resolve by it, the MyBatis use the reserved fallback method that named <code>provideSql</code>).
473+
Nota: A continuación hay una sección sobre la clase, que puede ayudar a construir SQL dinámico de una forma más clara y sencilla de leer.</td>
468474
</tr>
469475
<tr>
470476
<td><code>@Param</code></td>
@@ -583,6 +589,44 @@ class UserSqlBuilder {
583589
}
584590
}]]></source>
585591

592+
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
593+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
594+
List<User> getUsersByName(String name);
595+
596+
// Implements the ProviderMethodResolver on your provider class
597+
class UserSqlProvider implements ProviderMethodResolver {
598+
// In default implementation, it will resolve a method that method name is matched with mapper method
599+
public static String getUsersByName(final String name) {
600+
return new SQL(){{
601+
SELECT("*");
602+
FROM("users");
603+
if (name != null) {
604+
WHERE("name like #{value} || '%'");
605+
}
606+
ORDER_BY("id");
607+
}}.toString();
608+
}
609+
}]]></source>
610+
611+
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
612+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
613+
List<User> getUsersByName(String name);
614+
615+
// Implements the ProviderMethodResolver on your provider class
616+
class UserSqlProvider implements ProviderMethodResolver {
617+
// In default implementation, it will resolve a method that method name is matched with mapper method
618+
public static String getUsersByName(final String name) {
619+
return new SQL(){{
620+
SELECT("*");
621+
FROM("users");
622+
if (name != null) {
623+
WHERE("name like #{value} || '%'");
624+
}
625+
ORDER_BY("id");
626+
}}.toString();
627+
}
628+
}]]></source>
629+
586630
</subsection>
587631

588632
</section>

src/site/ja/xdoc/java-api.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
477477
<td>これらのアノテーションは動的 SQL を生成するためのものです。実行時に指定されたメソッドが呼び出され、メソッドから返された SQL ステートメントが実行されます (MyBatis 3.4.6以降では、メソッドの返り値として <code>String</code> ではなく <code>CharSequence</code> を指定することができます)。
478478
マップドステートメントを実行する際、プロバイダーによって指定したクラスのインスタンスが作成され、指定されたメソッドが実行されます。
479479
なお、メソッド引数にはMapperメソッドの引数に渡したオブジェクトに加え、<code>ProviderContext</code>(MyBatis 3.4.5以降で利用可能)を介して「Mapperインタフェースの型」と「Mapperメソッド」を渡すことができます。(MyBatis 3.4以降では、複数の引数を渡すことができます)
480-
キー: <code>type</code>, <code>method</code>. <code>type</code> にはクラスオブジェクト、<code>method</code> にはメソッド名を指定します。 <span class="label important">NOTE</span> 次の章で、クリーンで可読性の高いコードで動的 SQL を構築するためのクラスについて説明します。
480+
キー: <code>type</code>, <code>method</code>. <code>type</code> にはクラスオブジェクト、<code>method</code> にはメソッド名を指定します
481+
(MyBatis 3.5.1以降では、<code>method</code> 属性を省略することができます。その際MyBatisは、<code>ProviderMethodResolver</code> インタフェースを介して対象メソッドの解決を試み、
482+
対象メソッドが解決できない場合は、<code>provideSql</code>という名前のメソッドを代替メソッドとして利用します)。
483+
<span class="label important">NOTE</span> 次の章で、クリーンで可読性の高いコードで動的 SQL を構築するためのクラスについて説明します。
481484
</td>
482485
</tr>
483486
<tr>
@@ -591,6 +594,27 @@ class UserSqlBuilder {
591594
ORDER_BY(orderByColumn);
592595
}}.toString();
593596
}
597+
}]]></source>
598+
599+
<p>次のコードは、<code>ProviderMethodResolver</code>(MyBatis 3.5.1以降で利用可能)のデフォルト実装の利用例です。</p>
600+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
601+
List<User> getUsersByName(String name);
602+
603+
// SQLプロバイダクラスにProviderMethodResolverを実装する
604+
class UserSqlProvider implements ProviderMethodResolver {
605+
606+
// デフォルト実装では、マッパーメソッドと同名のメソッドが対象メソッドとして扱われます。
607+
public static String getUsersByName(final String name) {
608+
return new SQL(){{
609+
SELECT("*");
610+
FROM("users");
611+
if (name != null) {
612+
WHERE("name like #{value} || '%'");
613+
}
614+
ORDER_BY("id");
615+
}}.toString();
616+
}
617+
594618
}]]></source>
595619

596620
</subsection>

src/site/ko/xdoc/java-api.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
601601
Mapper 메서드의 인수인 "Mapper interface type" 과 <code>ProviderContext</code>(Mybatis 3.4.5 부터) 를 이용한 "Mapper method" 로 전달 된 객체를 메서드 매개변수로 전달할 수 있다.(마이바티스 3.4이상에서는 복수 파라미터를 허용한다.)
602602
사용가능한 속성들 : type, method.
603603
type 속성은 클래스.
604-
method 속성은 메소드명이다.
604+
method 속성은 메소드명이다
605+
(Since 3.5.1, you can omit <code>method</code> attribute, the MyBatis will resolve a target method via the
606+
<code>ProviderMethodResolver</code> interface.
607+
If not resolve by it, the MyBatis use the reserved fallback method that named <code>provideSql</code>).
605608
Note: 이 섹션은 클래스에 대한 설명으로 동적 SQL 을 좀더 깔끔하고 읽기 쉽게 만드는데 도움이 될 수 있다.</td>
606609
</tr>
607610
<tr>
@@ -734,6 +737,25 @@ class UserSqlBuilder {
734737
}
735738
}]]></source>
736739

740+
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
741+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
742+
List<User> getUsersByName(String name);
743+
744+
// Implements the ProviderMethodResolver on your provider class
745+
class UserSqlProvider implements ProviderMethodResolver {
746+
// In default implementation, it will resolve a method that method name is matched with mapper method
747+
public static String getUsersByName(final String name) {
748+
return new SQL(){{
749+
SELECT("*");
750+
FROM("users");
751+
if (name != null) {
752+
WHERE("name like #{value} || '%'");
753+
}
754+
ORDER_BY("id");
755+
}}.toString();
756+
}
757+
}]]></source>
758+
737759
</subsection>
738760

739761
</section>

src/site/xdoc/java-api.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
515515
via the <code>ProviderContext</code>(available since MyBatis 3.4.5 or later) as method argument.
516516
(In MyBatis 3.4 or later, it's allow multiple parameters)
517517
Attributes: <code>type</code>, <code>method</code>. The <code>type</code> attribute is a class.
518-
The <code>method</code> is the name of the method on that class. <span class="label important">NOTE</span>
518+
The <code>method</code> is the name of the method on that class
519+
(Since 3.5.1, you can omit <code>method</code> attribute, the MyBatis will resolve a target method via the
520+
<code>ProviderMethodResolver</code> interface.
521+
If not resolve by it, the MyBatis use the reserved fallback method that named <code>provideSql</code>).
522+
<span class="label important">NOTE</span>
519523
Following this section is a discussion about the class, which can help build dynamic SQL in a cleaner, easier to read way.</td>
520524
</tr>
521525
<tr>
@@ -648,6 +652,26 @@ class UserSqlBuilder {
648652
}}.toString();
649653
}
650654
}]]></source>
655+
656+
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
657+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
658+
List<User> getUsersByName(String name);
659+
660+
// Implements the ProviderMethodResolver on your provider class
661+
class UserSqlProvider implements ProviderMethodResolver {
662+
// In default implementation, it will resolve a method that method name is matched with mapper method
663+
public static String getUsersByName(final String name) {
664+
return new SQL(){{
665+
SELECT("*");
666+
FROM("users");
667+
if (name != null) {
668+
WHERE("name like #{value} || '%'");
669+
}
670+
ORDER_BY("id");
671+
}}.toString();
672+
}
673+
}]]></source>
674+
651675
</subsection>
652676

653677
</section>

src/site/zh/xdoc/java-api.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,14 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
465465
<li><code>&lt;select&gt;</code></li>
466466
</ul>
467467
</td>
468-
       <td>允许构建动态 SQL。这些备选的 SQL 注解允许你指定类名和返回在运行时执行的 SQL 语句的方法。(自从MyBatis 3.4.6开始,你可以用 <code>CharSequence</code> 代替 <code>String</code> 来返回类型返回值了。)当执行映射语句的时候,MyBatis 会实例化类并执行方法,类和方法就是填入了注解的值。你可以把已经传递给映射方法了的对象作为参数,"Mapper interface type" 和 "Mapper method" 会经过 <code>ProviderContext</code> (仅在MyBatis 3.4.5及以上支持)作为参数值。(MyBatis 3.4及以上的版本,支持多参数传入)属性有: <code>type</code>, <code>method</code>。<code>type</code> 属性需填入类。<code>method</code> 需填入该类定义了的方法名。<span class="label important">注意</span> 接下来的小节将会讨论类,能帮助你更轻松地构建动态 SQL。</td>
468+
       <td>允许构建动态 SQL。这些备选的 SQL 注解允许你指定类名和返回在运行时执行的 SQL 语句的方法。(自从MyBatis 3.4.6开始,你可以用 <code>CharSequence</code> 代替 <code>String</code> 来返回类型返回值了。)当执行映射语句的时候,MyBatis 会实例化类并执行方法,类和方法就是填入了注解的值。你可以把已经传递给映射方法了的对象作为参数,"Mapper interface type" 和 "Mapper method" 会经过 <code>ProviderContext</code> (仅在MyBatis 3.4.5及以上支持)作为参数值。(MyBatis 3.4及以上的版本,支持多参数传入)
469+
属性有: <code>type</code>, <code>method</code>。
470+
<code>type</code> 属性需填入类。
471+
<code>method</code> 需填入该类定义了的方法名
472+
(Since 3.5.1, you can omit <code>method</code> attribute, the MyBatis will resolve a target method via the
473+
<code>ProviderMethodResolver</code> interface.
474+
If not resolve by it, the MyBatis use the reserved fallback method that named <code>provideSql</code>)。
475+
<span class="label important">注意</span> 接下来的小节将会讨论类,能帮助你更轻松地构建动态 SQL。</td>
469476
</tr>
470477
<tr>
471478
<td><code>@Param</code></td>
@@ -578,6 +585,25 @@ class UserSqlBuilder {
578585
}
579586
}]]></source>
580587

588+
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
589+
<source><![CDATA[@SelectProvider(type = UserSqlProvider.class)
590+
List<User> getUsersByName(String name);
591+
592+
// Implements the ProviderMethodResolver on your provider class
593+
class UserSqlProvider implements ProviderMethodResolver {
594+
// In default implementation, it will resolve a method that method name is matched with mapper method
595+
public static String getUsersByName(final String name) {
596+
return new SQL(){{
597+
SELECT("*");
598+
FROM("users");
599+
if (name != null) {
600+
WHERE("name like #{value} || '%'");
601+
}
602+
ORDER_BY("id");
603+
}}.toString();
604+
}
605+
}]]></source>
606+
581607
</subsection>
582608

583609
</section>

0 commit comments

Comments
 (0)