1. 程式人生 > >mybatis limit的使用

mybatis limit的使用

在mapper.xml的新增
<select id="selectBylimit" resultType="com.mybatis.Test">
        SELECT testid,testcontent
        FROM haodf_doctorInfo ORDER BY doctorinfoid LIMIT #{offset},#{limit}  <!--這裡修改了-->
   </select>

在mapper.java中新增

 List<Test> selectBylimit(@Param("offset") int offset, @Param("limit") int limit);

測試使用
SqlSession session = null;
        try {
            session = MybatisSessionFactory.sessionFactory().openSession(ExecutorType.BATCH,true);
            HaodfDoctorinfoMapper mapper = session.getMapper(TestMapper.class) ;
            List<Test>  lsdoc= mapper.selectByPage(0, 100);
            for(Test docinfo:lsdoc){
                System.out.println(docinfo.getTestid()+":"+docinfo.getTestcontent()) ;
            }

        }catch(PersistenceException e){
        }finally {
            if(session!=null){
                session.close() ;
            }
        }