您好,登錄后才能下訂單哦!
引入包
https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter/1.2.10
<!--分頁-->
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import java.util.Properties;
/**
*配置文件
* @author liwen406
* @date 2019-04-20 12:14 2019-04-20 13:20
*/
@org.springframework.context.annotation.Configuration
public class MyBatisConfig {
/**
* 目的防止駝峰命名規則
* @return
*/
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer(){
@Override
public void customize(Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
/**
* 分頁插件
* @return
*/
@Bean
public PageHelper pageHelper() {
System.out.println("MyBatisConfiguration.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;
}
}
@Select("SELECT * from tbl_emp")
List<Employee> selectByExample(Employee example);
@Override
public List<Employee> selectByExample() {
return projectInfodao.selectByExample(null);
}
@GetMapping("/page/{start}/{end}")
@ResponseBody
public List<Employee> likeName(@PathVariable int start, @PathVariable int end) throws Exception {
/*
* 第一個參數:第幾頁;
* 第二個參數:每頁獲取的條數.
*/
PageHelper.startPage(start, end);
return projectInfService.selectByExample();
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。