SpringBoot 12 mybatis分页插件

1:原理

底层修改SQL语句。

2:修改pom.xml文件,添加依赖

<!-- 整合mybatis分页插件  -->
		<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

3:用法

package com.zhaoy.datasourceipp1.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.zhaoy.entity.Comment;

public interface CommentMapper1 {
	@Insert("INSERT INTO COMMENT(ID,PRODUCT_ID,COMMENT_TIME,IS_DELETED) VALUE "
			+ "(#{id}, #{productId}, #{commentTime}, #{isDeleted})")
	int insertComment(@Param("id") String id, @Param("productId") String productId, 
			@Param("commentTime") String commentTime, @Param("isDeleted") Boolean isDeleted);
	
	@Results({@Result(property = "id", column = "ID", id = true),
		@Result(property = "productId", column = "product_id"),
		@Result(property = "CommentTime", column = "comment_time"),
		@Result(property = "isDeleted", column = "is_deleted")})
	@Select("SELECT * FROM COMMENT")
	List<Comment> selCommentList();
}
package com.zhaoy.datasourceipp1.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaoy.datasourceipp1.mapper.CommentMapper1;
import com.zhaoy.datasourceipp2.mapper.CommentMapper2;
import com.zhaoy.entity.Comment;


@Service
public class CommentService1 {
	
	@Autowired
	private CommentMapper1 commentMapper1;
	
	public PageInfo<Comment> selCommentList(int pageNum, int pageSize){
		System.out.println("pageNum: " + pageNum + " pageSize: " + pageSize);
		PageHelper.startPage(pageNum, pageSize);
		List<Comment> selCommentList = commentMapper1.selCommentList();
		PageInfo<Comment> list = new PageInfo<Comment>(selCommentList);
		return list;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值