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 @Results({
32 @Result(column="id", property="id"),
33 @Result(column="name", property="name"),
34 @Result(column="city", property="city", jdbcType=JdbcType.CHAR),
35 @Result(column="state", property="state", jdbcType=JdbcType.VARCHAR)
36 })
37 User getUser(Integer id);
38
39 @Insert({
40 "insert into product (name) values (#{name})"
41 })
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 @ConstructorArgs({
52 @Arg(id = true, column="id", javaType = ProductId.class, jdbcType=JdbcType.INTEGER),
53 @Arg(column="name")
54 })
55 Product getProductByNameUsingConstructor(String name);
56
57 @Select("select id from product where name = #{value}")
58 ProductId getProductIdByName(String name);
59 }