2020java框架教程之mybatis参数传递

2020java框架教程之mybatis参数传递

一、分页

方式1:使用索引

按照参数的顺序,从0开始

select*from users limit #{0},#{1}

方式2:使用注解

select*from users limit #{start},#{pageSize}

List<Users> selectUsersPage2(
@Param(value = “start”) int start,
@Param(value = “pageSize”) int pageSize);

方式3:使用Map

select*from users limit #{start},#{pageSize}

List<Users> selectUsersPage3(Map<String,Object> map);

@Test
public void test9(){
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    UsersDao mapper = sqlSession.getMapper(UsersDao.class);
    Map<String,Object> map=new HashMap<>();
    map.put("start",2);
    map.put("pageSize",2);
    List<Users> users = mapper.selectUsersPage3(map);
    sqlSession.close();
    System.out.println(users);
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *