1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.typehandler;
17
18 import org.apache.ibatis.annotations.Arg;
19 import org.apache.ibatis.annotations.ConstructorArgs;
20 import org.apache.ibatis.annotations.Insert;
21 import org.apache.ibatis.annotations.Options;
22 import org.apache.ibatis.annotations.Result;
23 import org.apache.ibatis.annotations.Results;
24 import org.apache.ibatis.annotations.Select;
25 import org.apache.ibatis.submitted.typehandler.Product.ProductId;
26 import org.apache.ibatis.type.JdbcType;
27
28 public interface Mapper {
29
30 @Select("select * from users where id = #{value}")
31
32 @Results({
33 @Result(column = "id", property = "id"),
34 @Result(column = "name", property = "name"),
35 @Result(column = "city", property = "city", jdbcType = JdbcType.CHAR),
36 @Result(column = "state", property = "state", jdbcType = JdbcType.VARCHAR)
37 })
38
39 User getUser(Integer id);
40
41 @Insert({ "insert into product (name) values (#{name})" })
42 @Options(useGeneratedKeys = true, keyProperty = "id")
43 int insertProduct(Product product);
44
45 @Select("select id, name from product where name = #{value}")
46 Product getProductByName(String name);
47
48 Product getProductByNameXml(String name);
49
50 @Select("select id, name from product where name = #{value}")
51
52 @ConstructorArgs({
53 @Arg(id = true, column = "id", javaType = ProductId.class, jdbcType = JdbcType.INTEGER),
54 @Arg(column = "name")
55 })
56
57 Product getProductByNameUsingConstructor(String name);
58
59 @Select("select id from product where name = #{value}")
60 ProductId getProductIdByName(String name);
61 }