1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }