SpringBoot如何集成PageHelper分頁功能
添加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;@Configurationpublic 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;@RestControllerpublic 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=天恒
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. Android 7.0 運行時權限彈窗問題的解決2. java實現(xiàn)圖形化界面計算器3. IntelliJ IDEA設置條件斷點的方法步驟4. IDEA的Mybatis Generator駝峰配置問題5. ASP.NET MVC解決上傳圖片臟數(shù)據(jù)的方法6. Python使用oslo.vmware管理ESXI虛擬機的示例參考7. Thinkphp3.2.3反序列化漏洞實例分析8. python 批量將PPT導出成圖片集的案例9. 原生js XMLhttprequest請求onreadystatechange執(zhí)行兩次的解決10. python編寫函數(shù)注意事項總結
