一.服务安装
docker安装clickhouse数据库_docker 安装clickhouse-CSDN博客
使用idea链接clickHouse
执行创建数据库
XML
create database student;
XML
-- auto-generated definition
create table web_visits
(
date Date default toDate(datetime),
datetime DateTime default now(),
url String
)
engine = MergeTree PARTITION BY toYYYYMM(date)
ORDER BY (date, url)
SETTINGS index_granularity = 8192;
二.项目整合
1.项目引入依赖
<!-- 3版本升级 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.5</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.5.5</version>
</dependency>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.4.6</version>
</dependency>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-http-client</artifactId>
<version>0.4.6</version>
</dependency>
<dependency>
<groupId>org.lz4</groupId>
<artifactId>lz4-java</artifactId>
<version>1.8.0</version>
</dependency>
spring:
application:
name: demo
datasource:
dynamic:
primary: master
strict: true
datasource:
master:
url: jdbc:mysql://localhost:3306/flow?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
# clickhouse:
# url: jdbc:clickhouse://127.0.0.1:8123/student
# username: default
# password:
# driver-class-name: com.clickhouse.jdbc.ClickHouseDriver
XML
import com.baomidou.dynamic.datasource.annotation.DS;
import java.lang.annotation.*;
/**
* @author chenkang
* @since 2024/7/19 9:03
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@DS("clickhouse")
public @interface DsClickHouse {
}
XML
/**
* <p>
* Mapper 接口
* </p>
* @Mapper 这个注解要么加 要么全局加mapperScan
* @author baomidou
* @since 2024-05-13
*/
@Mapper
public interface WebVisitsMapper extends BaseMapper<WebVisits> {
}
XML
@DsClickHouse
public interface IWebVisitsService extends IService<WebVisits> {
}
XML
/**
* <p>
* 服务实现类
* </p>
*
* @author baomidou
* @since 2024-05-13
*/
@Service
public class WebVisitsServiceImpl extends ServiceImpl<WebVisitsMapper, WebVisits> implements IWebVisitsService {
}
然后就写代码了