View Javadoc
1   /*
2    *    Copyright 2009-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.submitted.dirty_select;
17  
18  import org.apache.ibatis.annotations.Insert;
19  import org.apache.ibatis.annotations.Options;
20  import org.apache.ibatis.annotations.Select;
21  import org.apache.ibatis.annotations.SelectProvider;
22  import org.apache.ibatis.cursor.Cursor;
23  
24  public interface Mapper {
25  
26    @Select("select * from users where id = #{id}")
27    User selectById(Integer id);
28  
29    @Select("select * from users where id = #{id}")
30    Cursor<User> selectCursorById(Integer id);
31  
32    @Select(value = "insert into users (name) values (#{name}) returning id, name", affectData = true)
33    User insertReturn(String name);
34  
35    @Select(value = "insert into users (name) values (#{name}) returning id, name", affectData = true)
36    Cursor<User> insertReturnCursor(String name);
37  
38    User insertReturnXml(String name);
39  
40    @SelectProvider(type = MyProvider.class, method = "getSql", affectData = true)
41    User insertReturnProvider(String name);
42  
43    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
44    @Insert("insert into users (name) values (#{name}) returning id, name")
45    int insert(User user);
46  
47    static class MyProvider {
48      public static String getSql() {
49        return "insert into users (name) values (#{name}) returning id, name";
50      }
51  
52      private MyProvider() {
53      }
54    }
55  }