引入包
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。