Skip to content

Commit 1d68154

Browse files
authored
Merge pull request #2971 from DevDengChao/docs/add-dynamic-sql-example-to-select
docs: add dynamic sql example to @select
2 parents 01225f5 + 9b99f44 commit 1d68154

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/main/java/org/apache/ibatis/annotations/Select.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,34 @@
2626
* The annotation that specify an SQL for retrieving record(s).
2727
* <p>
2828
* <b>How to use:</b>
29-
*
30-
* <pre>
31-
* public interface UserMapper {
32-
* &#064;Select("SELECT id, name FROM users WHERE id = #{id}")
33-
* User selectById(int id);
34-
* }
35-
* </pre>
29+
* <br/>
30+
* <ul>
31+
* <li>
32+
* Simple:
33+
* <pre>
34+
* public interface UserMapper {
35+
* &#064;Select("SELECT id, name FROM users WHERE id = #{id}")
36+
* User selectById(int id);
37+
* }
38+
* </pre>
39+
* </li>
40+
* <li>
41+
* Dynamic SQL:
42+
* <pre>
43+
* public interface UserMapper {
44+
* &#064;Select({"&lt;script>",
45+
* "select * from users",
46+
* "where name = #{name}",
47+
* "&lt;if test=\"age != null\"> age = #{age} &lt;/if>",
48+
* "&lt;/script>"})
49+
* User select(@NotNull String name, @Nullable Intger age);
50+
* }
51+
* </pre>
52+
* </li>
53+
* </ul>
3654
*
3755
* @author Clinton Begin
56+
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html">How to use Dynamic SQL</a>
3857
*/
3958
@Documented
4059
@Retention(RetentionPolicy.RUNTIME)
@@ -50,7 +69,6 @@
5069

5170
/**
5271
* @return A database id that correspond this statement
53-
*
5472
* @since 3.5.5
5573
*/
5674
String databaseId() default "";
@@ -60,7 +78,6 @@
6078
* e.g. RETURNING of PostgreSQL or OUTPUT of MS SQL Server.
6179
*
6280
* @return {@code true} if this select affects DB data; {@code false} if otherwise
63-
*
6481
* @since 3.5.12
6582
*/
6683
boolean affectData() default false;
@@ -69,7 +86,6 @@
6986
* The container annotation for {@link Select}.
7087
*
7188
* @author Kazuki Shimizu
72-
*
7389
* @since 3.5.5
7490
*/
7591
@Documented

0 commit comments

Comments
 (0)