xml の sql として正確なメソッド シグネチャを持つ抽象メソッドを使用してマッパー インターフェイスを作成する場合。
たとえば。これは、実際のクエリを含む dao.xml の名前空間でした。
<mapper namespace=" com.mybatis.dao.EntityMapperInterface">
<select id="selectEmployeeWithId" parameterType="Long"
resultType="com.mybatis.domain.Employee">
select id,name from employee where 1=1
<if test="_parameter != null">
AND id=#{id}
</if>
order by id
</select>
インターフェイス com.mybatis.dao.EntityMapperInterfaceにマップされます
public interface EntityMapperInterface {
public List<Employee> selectEmployeeWithId(Long id);
Mybatis-config ファイル
<mappers>
<mapper resource="com/mybatis/mappers/EntityMapper.xml" />
</mappers>
アクションクラス/サーブレットからどのように呼び出すのですか? SqlSession を初期化したら、
EntityMapperInterface emi = session.getMapper(EntityMapperInterface.class);
List eList = emi.selectEmployeeWithId(1);