mybatis limit的使用
阿新 • • 發佈:2019-01-04
在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() ; } }