欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

SpringBoot如何集成PageHelper分页功能

时间:2020-12-15 01:31:11|栏目:JAVA代码|点击:

添加MyBatis的代码并修改以下部分:

1.添加MyBatisConfig

package myshop.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.PageHelper;

@Configuration
public class MyBatisConfig {
  @Bean
  public PageHelper pageHelper()
  {
    System.out.println("Use PageHelper");
    PageHelper pageHelper = new PageHelper();
    Properties p = new Properties();
    p.setProperty("offsetAsPageNum", "true");
    p.setProperty("rowBoundsWithCount", "true");
    p.setProperty("reasonable", "true");
    pageHelper.setProperties(p);
    return pageHelper;
  }
}

2.修改MyBatisController

package myshop.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;

import myshop.bean.UserInfo;
import myshop.service.MyBatisService;

@RestController
public class MyBatisController {
   @Autowired
   private MyBatisService myBatisService;
   
   @RequestMapping("likeName")
   public List<UserInfo> likeName(String username)
   {
     PageHelper.startPage(1,2);
     return myBatisService.likeName(username);
   }
}

3.访问地址

http://localhost:8080/likeName?username=天恒

上一篇:Java数据结构与算法之选择排序(动力节点java学院整理)

栏    目:JAVA代码

下一篇:Mybatis学习笔记之动态SQL揭秘

本文标题:SpringBoot如何集成PageHelper分页功能

本文地址:http://www.codeinn.net/misctech/33021.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有