一、快速开始
1、添加依赖
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.1-patch</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency>
2、添加配置类
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
click:
driverClassName: ru.yandex.clickhouse.ClickHouseDriver
url: jdbc:clickhouse://127.0.0.1:8123/dbname
username: username
password: 123456
initialSize: 10
maxActive: 100
minIdle: 10
maxWait: 6000
3、添加配置类
@Data
@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 ;
private String username;
private String password;
}
@Configuration
public class DruidConfig {
@Resource
private JdbcParamConfig jdbcParamConfig ;
@Bean
public 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.setUsername(jdbcParamConfig.getUsername());
datasource.setPassword(jdbcParamConfig.getPassword());
return datasource;
}
}
实体类和业务实现
@Data
public class UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String userName;
private String passWord;
private String phone;
private String email;
private String createDay;
}
@Repository
public interface UserInfoMapper extends BaseMapper<UserInfo> {
// 写入数据
void saveData (UserInfo userInfo) ;
// ID 查询
UserInfo selectById (@Param("id") Integer id) ;
// 查询全部
List<UserInfo> selectList () ;
}
文章来源地址https://www.toymoban.com/news/detail-689902.html
文章来源:https://www.toymoban.com/news/detail-689902.html
到了这里,关于Springboot整合ClickHouse的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!