• springboot 整合pageHelper 注解形式


    定义分页注解

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD,ElementType.TYPE})
    @Documented
    public @interface EnablePage {
        String value() default "";
    }

    定义需要分页的拦截

    @Aspect
    @Component
    public class PageAop extends BaseService {
    
        /**
         * 定义切入点,切入点为com.example.fileupload.controller下的所有函数
         */
        @Pointcut("execution(public * com.liuchao.mayikttest.mapper.*.*(..))")
        /*
         * 定义连接点
         */
        public void webLog() {
        }
    
        @Around("webLog()")
        public Object doAroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
            MethodSignature methodSignature = (MethodSignature)proceedingJoinPoint.getSignature();
            Method method = methodSignature.getMethod();
            EnablePage enablePage = method.getAnnotation(EnablePage.class);
            if(StringUtils.isEmpty(enablePage)){
                Object obj = proceedingJoinPoint.proceed();
                return obj;
            }
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String pageNo = request.getParameter("pageNo");
            String pageSize = request.getParameter("pageSize");
            PageHelper.startPage(Integer.valueOf(pageNo), Integer.valueOf(pageSize));
            Object proceed = proceedingJoinPoint.proceed();
            return proceed;
            /*BaseResponse baseResponse =(BaseResponse) proceedingJoinPoint.proceed();
            List data = (List)baseResponse.getData();
            PageInfo pageInfo = new PageInfo(data);
                return setSuccess(pageInfo);*/
        }
    }

    在需要分页的Mapper方法上加上注解 

    public interface UserMapper {
            @EnablePage
            List<UserDO> findAll();
            UserDO findById(int id);
    }

    返回分页信息带分页的信息

     

     

  • 相关阅读:
    mouseenter和mouseleave,mouseover和mouseout
    哈哈哈
    instanceof与typeof
    js事件传参
    浮动与清除问题
    简易富文本编辑
    js之prototype
    json序列化
    我对Defer and Promise的实现
    Ajax 完整教程
  • 原文地址:https://www.cnblogs.com/dkws/p/12095053.html
Copyright © 2020-2023  润新知