mybatis-plus clickhouse支持分页
事情不是太复杂,mybatis-plus3.X已经支持ClickHouse数据库,只需正确配置其他用法跟用mysql一样。
废话不多说,直接上代码。
1 相关依赖:
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version></dependency><!-- alibaba的druid数据库连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.4</version></dependency><dependency><groupId>ru.yandex.clickhouse</groupId><artifactId>clickhouse-jdbc</artifactId><version>0.1.53</version></dependency>
2 相关配置:
(1)读取yml配置:
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix = "spring.datasource.click")
public class JdbcParamConfig {private String driverClassName ;private String url ;private Integer initialSize ;private Integer maxActive ;private Integer minIdle ;private Integer maxWait ;public String getDriverClassName() {return driverClassName;}public void setDriverClassName(String driverClassName) {this.driverClassName = driverClassName;}public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}public Integer getInitialSize() {return initialSize;}public void setInitialSize(Integer initialSize) {this.initialSize = initialSize;}public Integer getMaxActive() {return maxActive;}public void setMaxActive(Integer maxActive) {this.maxActive = maxActive;}public Integer getMinIdle() {return minIdle;}public void setMinIdle(Integer minIdle) {this.minIdle = minIdle;}public Integer getMaxWait() {return maxWait;}public void setMaxWait(Integer maxWait) {this.maxWait = maxWait;}}
(2)Druid连接池的配置
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.annotation.Resource;
import javax.sql.DataSource;@Configuration
public class DruidPoolConfig {@Resourceprivate JdbcParamConfig jdbcParamConfig ;@Beanpublic DataSource dataSource() {DruidDataSource datasource = new DruidDataSource();datasource.setUrl(jdbcParamConfig.getUrl());datasource.setDriverClassName(jdbcParamConfig.getDriverClassName());datasource.setInitialSize(jdbcParamConfig.getInitialSize());datasource.setMinIdle(jdbcParamConfig.getMinIdle());datasource.setMaxActive(jdbcParamConfig.getMaxActive());datasource.setMaxWait(jdbcParamConfig.getMaxWait());//datasource.setValidationQuery("select 1");datasource.setTestOnBorrow(true);datasource.setTestOnReturn(true);datasource.setTestWhileIdle(true);datasource.setTimeBetweenEvictionRunsMillis(15000);datasource.setMinEvictableIdleTimeMillis(60000);datasource.setRemoveAbandoned(true);datasource.setRemoveAbandonedTimeout(3600);datasource.setLogAbandoned(true);return datasource;}}
(3)mybatis-plus的配置:
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MybatisPlusConfig {/*** 新的分页插件*/@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.CLICK_HOUSE));return interceptor;}
}
3 代码:
(1)映射器mapper:
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xlkj.clickhouseservice.beans.SafeEventAll;public interface SafeEventAllDao extends BaseMapper<SafeEventAll> {}
(2)service接口:
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xlkj.clickhouseservice.beans.SafeEventAll;public interface SafeEventAllService extends IService<SafeEventAll> {/*** 分页查询* @param page 第几页* @param pageSize 每页条数* @return Page*/Page<SafeEventAll> list(Integer page, Integer pageSize);
}
(3)serviceImpl实现类:
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xlkj.clickhouseservice.beans.SafeEventAll;
import com.xlkj.clickhouseservice.dao.SafeEventAllDao;
import com.xlkj.clickhouseservice.service.SafeEventAllService;
import org.springframework.stereotype.Service;@Service
public class SafeEventAllServiceImpl extends ServiceImpl<SafeEventAllDao, SafeEventAll> implements SafeEventAllService {@Overridepublic Page<SafeEventAll> list(Integer page, Integer pageSize) {//TODO 将来在这里处理QueryWrapper<SafeEventAll>对象return this.page(new Page<SafeEventAll>(page,pageSize),new QueryWrapper<SafeEventAll>());}
}
(4)controller前端控制器:
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xlkj.clickhouseservice.beans.SafeEventAll;
import com.xlkj.clickhouseservice.service.SafeEventAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/safeallevent")
public class SafeEventAllController {@AutowiredSafeEventAllService safeEventAllService;/*** 分页查询* @return*/@GetMapping("/list")public Object list(@RequestParam(value = "page",defaultValue = "1") Integer page,@RequestParam(value = "page_size",defaultValue = "10") Integer pageSize) {Page<SafeEventAll> pageObj = safeEventAllService.list(page, pageSize);return pageObj;}}
(5)pojo映射对象略、映射文件xml略。
mybatis-plus clickhouse支持分页相关推荐
- mysql分页取数每一页生成xml_让MyBatis Generator产生的代码支持分页
本文提供一种方法,让MyBatis Generator产生的代码支持分页, 适用于MySQL. 分析 如果要获取分页信息,使用MySQL语句,我们需要怎么做呢? select * from t_us ...
- rowbounds分页oracle,Oracle使用MyBatis中RowBounds实现分页查询功能
Oracle中分页查询因为存在伪列rownum,sql语句写起来较为复杂,现在介绍一种通过使用MyBatis中的RowBounds进行分页查询,非常方便. 使用MyBatis中的RowBounds进行 ...
- springboot+jpa+mybatis 多数据源支持
springboot+jpa+mybatis 多数据源支持 配置dataSource import org.springframework.beans.factory.annotation.Quali ...
- Springboot集成mybatis通用Mapper与分页插件PageHelper
Springboot集成mybatis通用Mapper与分页插件PageHelper 插件介绍 通用 Mapper 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及 ...
- MyBatis使用PageHelper排序分页
文章目录 MyBatis使用PageHelper排序分页 前言 排序分页 使用PageHelper排序分页 添加PageHelper Spring Boot依赖 新增一个列表查询的方法 使用PageH ...
- 大数据druid查询不支持分页_Druid实时大数据分析查询(六)
Druid的数据查询过程以及查询语法 Druid提供了HTTP REST风格的查询接口.用户对数据的查询通过HTTP请求发送到查询节点(Broker Node),然后查询节点转发至历史节点(Histo ...
- 【Vue】ElementUI el-select 下拉分页加载数据,并支持搜索功能(此处不支持分页)
项目场景: 在公司管理后台需要有一个 根据选择客户筛选拥有的服务 的功能 问题描述: 但是有上千条用户数据,一次性查询加载会导致页面有很长时间(大概4~5s)的空白期,用户体验很不友好. 故需要进行优 ...
- spring boot整合mybatis+通用mapper+pagehelper分页插件
spring boot整合mybatis+通用mapper+pagehelper分页插件 pom依赖 <?xml version="1.0" encoding="U ...
- 【clickhouse】Clickhouse 支持毫秒 纳秒数据
文章目录 1.概述 1.概述 转载:https://vkingnew.blog.csdn.net/article/details/107294011 在clickhouse winter/Spring ...
最新文章
- spring boot读取yml配置集合,反射实战!
- solr4.5分组查询、统计功能介绍
- Android开发热门前沿知识,成功定级腾讯T3-2
- MyEclipse快捷键与插件大全
- c语言x的2取模_c语言如何取模运算
- springmvc+spring+mybatis基于soa架构进行框架整合思路分析
- SetConsoleCursorPosition光标的位置控制
- hexo部署成功但是没效果_使用 Hexo+GitHub 搭建个人免费博客教程(小白向)
- 小程序提交不能保存,后台可以正常保存
- 远哥跟你说 Spring的 classpath 通配符加载配置文件
- 高通Audio缩写(不断更新中...)
- 无缝向上滚动文字代码(Js+div),可用在公告栏
- ueditor 图片水印 php,[UEditor]上传图片自动添加水印
- 互联网2018校招时间_供参考
- c51语言主函数,51单片机的基本c51语言程序介绍
- 小明开了一家糖果店。他别出心裁:把水果糖包成4颗一包和7颗一包的两种。糖果不能拆包卖
- 原生js实现对未来dom的事件绑定
- kali linux外网渗透指定ip,kali Linux局域网渗透之win10
- HTML网页设计:五、行内元素和块元素
- No module named 'gensim'
热门文章
- 一本通1592【例 1】国王
- 《机器学习实战》学习笔记(八)
- C# picturebox在form_load和最小化后内容无法显示
- C#Winform中picturebox控件加载图片后无法释放
- 《老男孩》上映 “娱乐宝”投资电影进入回收期
- level1和level2行情的区别
- android 点击按钮来回切换图片
- linux通过无线网卡上网,在Ubuntu中使用PHS无线网卡上网
- JAVA 洗衣房管理系统 宿舍洗衣机管理系统
- SOTA 激光相机标定velo2cam_calibration(待完成)