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.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    // @formatter:off
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    // @formatter:on
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    // @formatter:off
52    @ConstructorArgs({
53        @Arg(id = true, column = "id", javaType = ProductId.class, jdbcType = JdbcType.INTEGER),
54        @Arg(column = "name")
55      })
56    // @formatter:on
57    Product getProductByNameUsingConstructor(String name);
58  
59    @Select("select id from product where name = #{value}")
60    ProductId getProductIdByName(String name);
61  }