package com.abc.mapper;
import com.abc.domain.Teacher;
import org.springframework.stereotype.Component;
import java.util.List;
//@Component指定映射器名称为myTeacherMapper
//相关内容,可参考笔者博客:
//http://legend2011.blog.51cto.com/3018495/980150
@Component("myTeacherMapper")
publicinterface TeacherMapper {
public Teacher getById(int id);
//分页查询教师信息
public List<Teacher> findTeacherByPage(
String sort,//排序字段
String dir, //排序方向
int start, //起始记录
int limit //记录条数
);
}
<?xmlversion="1.0"encoding="utf8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--与以前一样,namespace的值是对应的映射器接口的完整名称-->
<mappernamespace="com.abc.mapper.TeacherMapper">
<!--教师实体映射-->
<resultMapid="supervisorResultMap"type="Teacher">
<idproperty="id"/>
<resultproperty="name"/>
<resultproperty="gender"/>
<resultproperty="researchArea"column="research_area"/>
<resultproperty="title"/>
<!--collection元素映射教师的指导学生集合的属性。这里采用了
“命名空间名.select语句id”的形式来引用StudentMapper.xml中的
select语句getStudents。关于这种collection元素使用嵌套的
select语句的详情,请参考笔者博客:
http://legend2011.blog.51cto.com/3018495/985907
-->
<collectionproperty="supStudents"column="id"ofType="Student"
select="com.abc.mapper.StudentMapper.getStudents"/>
</resultMap>
<!--param1、param2等是MyBatis对映射器方法参数的默认命名-->
<selectid="findTeacherByPage"resultMap="supervisorResultMap">
select * from teacher
order by ${param1} ${param2} limit #{param3},#{param4}
</select>
</mapper>