マッパーインターフェイスを作成するときは、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>
どのようにuはからそれを呼び出すかにマッピングされますアクションクラス/サーブレット? SqlSessionを初期化したとき、
EntityMapperInterface emi = session.getMapper(EntityMapperInterface.class);
List eList = emi.selectEmployeeWithId(1);
私は本当にこれを知りたいです!マッパーインターフェイスを手動で追加することは適切な解決策ではありません。マッパーをXMLで構成し、手で追加せずにMapperInterfacesを一緒に使用するにはどうすればよいですか? – Chris