mybatis limit的使用

来源:互联网 发布:淘宝暗语的农夫是什么 编辑:程序博客网 时间:2024/05/21 10:55
在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() ;            }        }



原创粉丝点击