? MyBatis-Plus ?,???? PageHelper
?????????????
??,??????????? MyBatis-Plus ?????????? MyBatis-Plus ????:https://mybatis.plus/guide/quick-start.html#添加依赖
??,??? DAO ?????????,??????????,??:
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.example.demo.entity.User; public interface UserMapper extends BaseMapper{ IPage selectPageAll(Page page); }
???,??? DAO ???????,?? selectPageAll
??,????? Page
??,??:
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.example.demo.entity.User; import com.example.demo.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @Repository public class UserDaoImpl implements UserDao { @Autowired private UserMapper userMapper; @Override public IPageselectPageAll(int pageNum, int pageSize) { Page page = new Page<>(pageNum, pageSize); return userMapper.selectPageAll(page); } }
??,??? Service ???? DAO ?????,??:
import com.baomidou.mybatisplus.core.metadata.IPage; import com.example.demo.entity.User; import com.example.demo.dao.UserDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class UserServiceImpl implements UserService { @Autowired private UserDao userDao; @Override public IPageselectPageAll(int pageNum, int pageSize) { return userDao.selectPageAll(pageNum, pageSize); } }
??,???? selectPageAll
???,??????????????