动态sql
foreach中list是对象时
直接: 对象.属性
<select id="selectStuForeach" resultMap="studentMap">
select * from student where stu_id in
<foreach collection="list" item="stu" open="(" close=")" separator=",">
#{stu.id}
</foreach>
</select>
PageHelper分页代替limit offset,size
pom.xml:
<!--PageHelper依赖-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
mybatis.xml:
<!--pageHelper插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
在查询之前分页说明:【startPage(int pageNum, int pageSize)】
@Test
public void selectStus() {
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
PageHelper.startPage(1,4);
List<Student> list = dao.selectStudents();
sqlSession.close();
list.forEach(System.out::println);
}
预留问题:缓存,日志,插件AV21272940