UserMapper.java
public interface UserMapper extends BaseMapper<User> {
IPage<User> selectMyPage(IPage<User> page, @Param(Constants.WRAPPER) Wrapper<User> queryWrapper);
List<User> selectMyPage2(@Param("pageNum")int pageNum, @Param("pageSize")int PageSize);
}
UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cy.springboot.mapper.UserMapper">
<select id="selectMyPage" resultType="com.cy.springboot.entity.User">
select * from boot_user
</select>
<select id="selectMyPage2" resultType="com.cy.springboot.entity.User">
select * from boot_user limit #{pageNum},#{pageSize}
</select>
</mapper>
测试
@SpringBootTest
@RunWith(SpringRunner.class)
public class MapperTests {
@Test
public void page(){
Page<User> page = new Page<>(1,1);
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.gt("age",5);
userMapper.selectMyPage(page,userQueryWrapper);
}
@Test
public void page2(){
int pageNum=1;
int pageSize=2;
List<User> users = userMapper.selectMyPage2(pageNum, pageSize);
userMapper.selectMyPage2(pageNum,pageSize);
}
}
打印sql page() page2() 如果要对字段进行比较,方式一更合适
|