SpringBoot中Mybatis分页插件PageHelper简单使用

 

 

 

  • 1.pom文件依赖

    
            
                com.github.pagehelper
                pagehelper-spring-boot-starter
                1.2.5
            

     

  • 2.Mapper层

    

public interface MobileMapper {

    @Select("select * from mobile_phone")
    public List getAllMobile();
}
  • 3.Service层开发

@Transactional
@Service
public class MobileServiceImpl implements MobileService {

    @Autowired
    private MobileMapper mm;

    /**
     * 查询手机分页
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo getMobilePageInfo(Integer page, Integer size) {
        //开始分页
        PageHelper.startPage(page,size);
        //查询数据
        List list = mm.getAllMobile();
        //将查到的list放入PageInfo类中
        PageInfo info = new PageInfo<>(list);
        return info;
    }
}
  • 4.Controller层

@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@RequestMapping("/mobile")
public class MobileController {


    @Autowired
   private MobileService ms;

    /**
     * 查询手机分页
     * @return
     */
    @RequestMapping("/getAllMobile/{page}")
    public PageInfo getAllMobile(@PathVariable Integer page){
        System.out.println("page="+page);
        return ms.getMobilePageInfo(page,3);
    }

}

 

你可能感兴趣的:(javaWeb框架)