MybatisPlus实现分页——自写SQL

#一、引入依赖

<!--        mybatis-plus依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1</version>
        </dependency>

#二、编写SQL,返回list

/**
 * (SumTable)表数据库访问层
 *
 * @author zdh
 * @since 2024-04-12 10:49:24
 */
public interface SumTableMapper extends BaseMapper<SumTable> {

    Page<SumTable> selectAll(@Param("page") Page<SumTable> page);

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.yun.bicarbon.mapper.SumTableMapper">
  <resultMap id="BaseResultMap" type="cn.yun.bicarbon.entity.table.SumTable">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="pid" jdbcType="INTEGER" property="pid" />
    <result column="x" jdbcType="VARCHAR" property="x" />
    <result column="y" jdbcType="VARCHAR" property="y" />
    <result column="value" jdbcType="DOUBLE" property="value" />
    <result column="level" jdbcType="INTEGER" property="level" />
    <result column="unit" jdbcType="VARCHAR" property="unit" />
    <result column="year" jdbcType="INTEGER" property="year" />
    <result column="meter_header" jdbcType="VARCHAR" property="meterHeader" />
    <result column="city" jdbcType="INTEGER" property="city" />
  </resultMap>
  <sql id="Base_Column_List">
    id, pid, x, y, `value`, `level`, unit, `year`, meter_header
  </sql>

  <select id="selectAll" resultType="cn.yun.bicarbon.entity.table.SumTable">
    select
    <include refid="Base_Column_List" />
    from sum_table
  </select>


</mapper>

#三、在实现类中对list进行处理

public Page<SumTable> selectAll(Page<SumTable> page) {
      
        return sumTableMapper.selectAll(page);
    }

#四、传入page参数和条件

/**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param sumTable 查询实体
     * @return 所有数据
     */
    @GetMapping("a")
    public R selectAll(Page<SumTable> page, SumTable sumTable) {
//        return success(this.sumTableService.page(page, new QueryWrapper<>(sumTable)));
        return success(sumTableService.selectAll(page));
    }

#五、配置类

package cn.yun.bicarbon.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

### Flink 大数据处理优化技巧与最佳实践 #### 调优原则与方法概述 对于Flink SQL作业中的大状态导致的反压问题,调优的核心在于减少状态大小以及提高状态访问效率。通过合理配置参数和调整逻辑设计可以有效缓解此类瓶颈[^1]。 #### 参数设置建议 针对不同版本下的具体特性差异,在实施任何性能改进措施前应当充分理解当前使用的Flink版本特点及其局限性;同时也要考虑特定应用场景的需求特征来定制化解决方案。这包括但不限于并行度设定、内存分配策略等方面的选择[^2]。 #### 数据流模式优化 采用广播变量机制可作为一种有效的手段用于降低主数据流转过程中所需维护的状态量级。当存在一对多关系的数据集间需频繁交互时,将较小规模的一方作为广播状态保存下来供另一方查询匹配使用不失为明智之举。此方式特别适用于维表Join操作中,其中一方变动相对较少但又必须保持最新记录的情况[^3]。 ```sql -- 创建临时视图以支持后续JOIN操作 CREATE TEMPORARY VIEW dim_table AS SELECT * FROM kafka_source; -- 定义Temporal Table Function以便获取指定时间点上的历史快照 CREATE FUNCTION hist_dim_table AS 'com.example.HistoricalDimTableFunction'; -- 执行带有时态条件约束的JOIN语句 SELECT o.order_id, d.product_name FROM orders o LEFT JOIN LATERAL TABLE(hist_dim_table(o.event_time)) AS d ON o.product_id = d.id; ``` 上述代码片段展示了如何利用Flink SQL实现基于时间戳的历史维度表连接功能,从而确保每次都能准确捕捉到事件发生瞬间对应的最恰当的产品名称信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值