View Javadoc
1   /*
2    *    Copyright 2009-2021 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    *       http://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.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  }