<select id="findAllStudents" resultMap="StudentResult"> select * from studdents </select> int offset=0;//开始位置 int limit=25;//取出的数据条数 RowBounds rowBounds=new RowBounds(offset,limit); List<Student> list=studentMapper.findAllStudent(rowBounds);
public interface ResultHandler
{
void handleResult(ResultContext context);
}
Map<Integer , String> map=new HashMap<Integer,String>();
SqlSession sqlSession=MyBatisUtil.openSession();
sqlSession.select("com.mybatis3.mappers.StudentMapper.findAllStudents",new ResultHandler(){
public void handlerResult(ResultContext context)
{
Student student=(Student)context.getResultObject();
map.put(student.getStudId(),student.getName());
}
})
public interface StudentMapper
{
@Insert("insert into student (stud_id, name, email, addr_id, phone)values(#{studId},#{name},#{email},#{address.addrId},#{phone})")
int insertStudent(Student student);
}
public interface StudentMapper
{
@Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})")
@Options(useGeneratedKeys=true,keyProperty="studId")
int insertStudent(Student student);
}
public interface StudentMapper
{
@Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})")
@SelectKey(statement="select stud_id_seq.nextval from dual",keyProperty="studId",resultType=int.calss,before=true)
int insertStudent(Student student);
}
@Update("update students set name=#{name},email=#{email}")
int updateStudent(Student student);
@Delete("delete form students where stud_id=#{studId}")
int deleteStudent(int studId)
@Select("select name,email,phone from students where stud_id=#{studId}")
Student findStudentById(Integer studId);
@Select("select name,email,phone from students where stud_id=#{studId}")
@Results({
@Result(id=true,column="stud_id",property="studId"),
@Result(column="name",property="name"),
@Result(column="email",property="email"),
@Result(column="phone",property="phone")
})
Student findStudentById(Integer studId);
<mapper namespace="com.mybatis3.mappers.StudentMapper">
<resultMap type="Student" id="StudentResult">
.......
</resultMap>
@Select("select name,email,phone from students where stud_id=#{studId}")
@ResultMap("com.mybatis3.mappers.StudentMapper.StudentResult")
Student findStudentById(Integer studId);
public class SqlProvider
{
public String findTutorById(int tutorId)
{
return "select tutorId,name,email from tutors where tutorId="+tutorId;
}
}
@SelectProvider(type=SqlProvider.class,method="findTutorById") Tutor findTutorById(int tutorId);
public class SqlProvider
{
public String findTutorById(int tutorId)
{
return new SQL(){{
SELECT("tutorid,name,email")
FROM("tutors")
WHERE("tutorid="+tutorId)
}}.toString();
}
}
public class SqlProvider
{
public String findTutorById()
{
return new SQL(){{
SELECT("tutorid,name,email")
FROM("tutors")
WHERE("tutorid=#{tutorId}")
}}.toString();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有