Created
December 15, 2022 04:03
-
-
Save A-pZ/1cbcb0cd898f08006de1b077b32b9336 to your computer and use it in GitHub Desktop.
マッパー定義例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.apz.sample.repository; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import java.time.LocalDateTime; | |
@NoArgsConstructor @Getter | |
public class Item { | |
private Long id; | |
private String name; | |
private LocalDateTime registerDateTime; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.apz.sample.mapper; | |
import com.github.apz.sample.repository.Item; | |
import org.apache.ibatis.annotations.Mapper; | |
import java.util.List; | |
@Mapper | |
public interface ItemMapper { | |
List<Item> selectItem(String id); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<!DOCTYPE mapper | |
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |
"https://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
<mapper namespace="com.github.apz.sample.mapper.ItemMapper"> | |
<select id="selectItem" resultMap="Item"> | |
SELECT | |
id | |
, name | |
, register_time | |
FROM | |
item | |
<where> | |
<if test="id != null"> | |
id = #{id} | |
</if> | |
</where> | |
</select> | |
<resultMap id="Item" type="com.github.apz.sample.repository.Item"> | |
<id column="id" property="id"/> | |
<id column="name" property="name"/> | |
<id column="register_time" property="registerDateTime"/> | |
</resultMap> | |
</mapper> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment