當你創建映射器接口與具有精確方法簽名的抽象方法作爲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>
您是如何從叫它Action類/ Servlet? 當你對SqlSession進行初始化時,
EntityMapperInterface emi = session.getMapper(EntityMapperInterface.class);
List eList = emi.selectEmployeeWithId(1);
我真的很想知道這個!手動添加映射器接口不是一個合適的解決方案。我們如何配置XML映射器和使用MapperInterfaces而無需手動添加它們? – Chris 2011-05-04 11:47:14