spring boot integrated pagehelper (two ways)

When mybatis spring boot when you need integrated paging, we first add maven support

<dependency>
 <groupId>com.github.pagehelper</groupId>
 <artifactId>pagehelper</artifactId>
 <version>5.1.2</version>
</dependency>
<dependency>
 <groupId>com.github.pagehelper</groupId>
 <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
 <version>1.2.3</version>
</dependency>
<dependency>
 <groupId>com.github.pagehelper</groupId>
 <artifactId>pagehelper-spring-boot-starter</artifactId>
 <version>1.2.3</version>
</dependency>

One way: We join in application.yml (yml spring to be read) in

pagehelper:
 helperDialect: mysql
 reasonable: true
 supportMethodsArguments: true
 params: count=countSql

Then you can restart.

Profile will eventually be read java, eventually injected into the spring bean, we second method is to configure the bean class, of course, easy to modify a simpler embodiment the heat load,

Second way: in the annotation package covers the following new PageHeleperConfig

import com.github.pagehelper.PageHelper;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
/ ** 
 * @author zhuxiaomeng
 * @date 2018/1/2.
 * @email [email protected]
 */
@Configuration
public class PageHelperConfig {
 
 
 @Bean
 public PageHelper getPageHelper(){
 PageHelper pageHelper=new PageHelper();
 Properties properties=new Properties();
 properties.setProperty("helperDialect","mysql");
 properties.setProperty("reasonable","true");
 properties.setProperty("supportMethodsArguments","true");
 properties.setProperty("params","count=countSql");
 pageHelper.setProperties(properties);
 return pageHelper;
 }
 
}

pageHelper basics are:

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

 

Guess you like

Origin www.cnblogs.com/deityjian/p/11099467.html