SpringBoot 集成 ClickHouse

SpringBoot 集成 ClickHouse

1. 引入maven 依赖
<dependency>
            <groupId>com.clickhouse</groupId>
            <artifactId>clickhouse-jdbc</artifactId>
            <version>${clickhouse.jdbc.version}</version>
        </dependency>

最新版本可以 在 mvnrepository 搜索

https://mvnrepository.com/

2. 添加ck的数据源
spring:
  datasource:
      driver-class-name: com.clickhouse.jdbc.ClickHouseDriver
      url: jdbc:clickhouse://localhost:8123/default
      username: username
      password: password 
3. 持久层的编写

由于项目当中使用的是mybatis plus 所以代码就按照对应的格式编写,正常调用即可


@Mapper
public interface LocalMapper extends BaseMapper<LocalEntity> {

    

}
@Getter
@Setter
@Accessors(chain = true)
@TableName("local")
public class LocalEntity {

    /**
     * 主键ID
     */
    private String id;

    
    @TableField("status")
    private Integer status;

   
}