一、快速开始
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.DruidDataSourceclick : driverClassName : ru.yandex.clickhouse.ClickHouseDriverurl : jdbc: clickhouse: //127.0.0.1: 8123/dbnameusername : usernamepassword : 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) ; UserInfo selectById ( @Param ( "id" ) Integer id) ; List < UserInfo > selectList ( ) ;
}