Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Created December 15, 2022 04:03
Show Gist options
  • Save A-pZ/1cbcb0cd898f08006de1b077b32b9336 to your computer and use it in GitHub Desktop.
Save A-pZ/1cbcb0cd898f08006de1b077b32b9336 to your computer and use it in GitHub Desktop.
マッパー定義例
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;
}
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);
}
<?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