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=天恒
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 刪除docker里建立容器的操作方法2. Docker 部署 Prometheus的安裝詳細(xì)教程3. Docker 容器健康檢查機(jī)制4. IntelliJ IDEA設(shè)置自動(dòng)提示功能快捷鍵的方法5. 淺談JavaScript宏任務(wù)和微任務(wù)執(zhí)行順序6. IntelliJ IDEA刪除類的方法步驟7. idea刪除項(xiàng)目的操作方法8. idea環(huán)境下Maven無法正常下載pom中配置的包問題9. IntelliJ IDEA配置Tomcat服務(wù)器的方法10. Django中如何使用Channels功能

網(wǎng)公網(wǎng)安備