|
| 1 | +package com.baeldung.mybatis.mapper; |
| 2 | + |
| 3 | +import com.baeldung.mybatis.model.Address; |
| 4 | +import com.baeldung.mybatis.model.Person; |
| 5 | +import com.baeldung.mybatis.utils.MyBatisUtil; |
| 6 | +import org.apache.ibatis.annotations.*; |
| 7 | +import org.apache.ibatis.mapping.StatementType; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | + |
| 13 | +public interface PersonMapper { |
| 14 | + |
| 15 | + @Insert("Insert into person(name) values (#{name})") |
| 16 | + public Integer save(Person person); |
| 17 | + |
| 18 | + @Update("Update Person set name= #{name} where personId=#{personId}") |
| 19 | + public void updatePerson(Person person); |
| 20 | + |
| 21 | + @Delete("Delete from Person where personId=#{personId}") |
| 22 | + public void deletePersonById(Integer personId); |
| 23 | + |
| 24 | + @Select("SELECT person.personId, person.name FROM person WHERE person.personId = #{personId}") |
| 25 | + Person getPerson(Integer personId); |
| 26 | + |
| 27 | + @Select("Select personId,name from Person where personId=#{personId}") |
| 28 | + @Results(value ={ |
| 29 | + @Result(property = "personId", column = "personId"), |
| 30 | + @Result(property="name", column = "name"), |
| 31 | + @Result(property = "addresses",javaType = List.class,column = "personId", |
| 32 | + many=@Many(select = "getAddresses")) |
| 33 | + |
| 34 | + }) |
| 35 | + public Person getPersonById(Integer personId); |
| 36 | + |
| 37 | + @Select("select addressId,streetAddress,personId from address where personId=#{personId}") |
| 38 | + public Address getAddresses(Integer personId); |
| 39 | + |
| 40 | + @Select("select * from Person ") |
| 41 | + @MapKey("personId") |
| 42 | + Map<Integer,Person> getAllPerson(); |
| 43 | + |
| 44 | + @SelectProvider(type=MyBatisUtil.class,method="getPersonByName") |
| 45 | + public Person getPersonByName(String name); |
| 46 | + |
| 47 | + |
| 48 | + @Select(value= "{ CALL getPersonByProc( #{personId, mode=IN, jdbcType=INTEGER})}") |
| 49 | + @Options(statementType = StatementType.CALLABLE) |
| 50 | + public Person getPersonByProc(Integer personId); |
| 51 | + |
| 52 | +} |
0 commit comments