Springboot整合mybatis实现分页

1.pom文件


	4.0.0
	com.hlkj
	springboot_mybatisForPagehelper
	0.0.1-SNAPSHOT
	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.0.RELEASE
	

	
		
			org.projectlombok
			lombok
			1.16.10
		

		
			org.springframework.boot
			spring-boot-starter
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		

		
			org.mybatis.spring.boot
			mybatis-spring-boot-starter
			1.3.0
		

		
			mysql
			mysql-connector-java
		

		
			org.springframework.boot
			spring-boot-starter-web
		

		
			com.github.pagehelper
			pagehelper-spring-boot-starter
			1.2.5
		

		
			org.apache.commons
			commons-lang3
		

	

2、实体类如下:

@Data
public class Person {
	private String pid;
	private String pname;
}

3、mapper类如下

public interface PersonMapper {
 @Select("select * from person")	
 List findPersonList();
}

4、service类如下

@Service
public class PersonService {
	@Autowired
	private PersonMapper personMapper;
	public PageInfo findPersonList(int page,int pageSize){
		PageHelper.startPage(page,pageSize);//底层实现原理改写语句
		List lists=personMapper.findPersonList();
		PageInfo pageInfoUserList=new PageInfo(lists);
		return pageInfoUserList;
	}
	
	
}

5、controller类如下

@RestController
public class PersonController {
	@Autowired
	private PersonService personService;
	
	@RequestMapping("index")
	public PageInfoindex(int page,int pageSize){
		return personService.findPersonList(page, pageSize);
	}
}

7、测试类如下

@SpringBootApplication  
@MapperScan("com.hlkj.mapper")
public class PagehelperTest {
	
	public static void main(String[] args) {
	    SpringApplication.run(PagehelperTest.class, args);
	}
}

8、application.properties如下

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


logging.level.com.example.demo.dao=DEBUG
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.page-size-zero=true

 

你可能感兴趣的:(Springboot整合mybatis实现分页)