summaryrefslogtreecommitdiffstats
path: root/java/MyMyBatis/src/ModelMapper.java
blob: 901af2c7d758c224e2e9906a2d65a7c0aa3b8a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ch.asynk;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;

public interface ModelMapper extends AbstractMapper<Integer, Model>
{
    final static String attrs = " id, name ";
    final static String from = " from models ";
    final static String where = " where id=#{id} ";

    final static String INSERT = "insert into models(name) values (#{name})";
    @Insert(INSERT)
    int insert(Model obj);

    final static String UPDATE = "update models set name=#{name}" + where;
    @Update(UPDATE)
    int update(Model obj);

    final static String DELETE = "delete" + from + where;
    @Delete(DELETE)
    int delete(Model obj);

    final static String COUNT = "select count(*)" + from;
    @Select(COUNT)
    int count();

    final static String SELECT = "select" + attrs + from;
    @Select(SELECT)
    List<Model> select();

    final static String SELECT_ONE = SELECT + where;
    @Select(SELECT_ONE)
    Model selectOne(Integer id);

    final static String SELECT_SELF = SELECT + where;
    @Select(SELECT_SELF)
    Model selectSelf(Model obj);
}