Skip to content

Commit 753da00

Browse files
committed
1.springboot2+clickhouse查询demo
1 parent f137d39 commit 753da00

15 files changed

+558
-0
lines changed

spring-boot2-clickhouse/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
clickhouse安装配置.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/

spring-boot2-clickhouse/pom.xml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.example</groupId>
6+
<artifactId>spring-boot2-clickhouse</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
9+
<name>spring-boot2-clickhouse</name>
10+
<description>Demo project for Spring Boot</description>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>2.0.4.RELEASE</version>
16+
<relativePath/> <!-- lookup parent from repository -->
17+
</parent>
18+
19+
<properties>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22+
<java.version>1.8</java.version>
23+
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
24+
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
25+
<mysql.version>5.1.46</mysql.version>
26+
<maven.test.skip>true</maven.test.skip>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
<!-- <exclusions>&lt;!&ndash; 去掉springboot默认配置 &ndash;&gt;-->
34+
<!-- <exclusion>-->
35+
<!-- <groupId>org.springframework.boot</groupId>-->
36+
<!-- <artifactId>spring-boot-starter-logging</artifactId>-->
37+
<!-- </exclusion>-->
38+
<!-- </exclusions>-->
39+
</dependency>
40+
<!-- <dependency> &lt;!&ndash; 引入log4j2依赖 &ndash;&gt;-->
41+
<!-- <groupId>org.springframework.boot</groupId>-->
42+
<!-- <artifactId>spring-boot-starter-log4j2</artifactId>-->
43+
<!-- </dependency>-->
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-actuator</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-test</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>mysql</groupId>
55+
<artifactId>mysql-connector-java</artifactId>
56+
<version>5.1.42</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.mybatis.spring.boot</groupId>
60+
<artifactId>mybatis-spring-boot-starter</artifactId>
61+
<version>1.3.2</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.alibaba</groupId>
65+
<artifactId>druid</artifactId>
66+
<version>1.1.22</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>ru.yandex.clickhouse</groupId>
70+
<artifactId>clickhouse-jdbc</artifactId>
71+
<version>0.1.53</version>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.projectlombok</groupId>
76+
<artifactId>lombok</artifactId>
77+
<scope>provided</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>commons-lang</groupId>
81+
<artifactId>commons-lang</artifactId>
82+
<version>2.6</version>
83+
</dependency>
84+
</dependencies>
85+
86+
<dependencyManagement>
87+
<dependencies>
88+
<dependency>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-dependencies</artifactId>
91+
<version>${spring-boot.version}</version>
92+
<type>pom</type>
93+
<scope>import</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.springframework.cloud</groupId>
97+
<artifactId>spring-cloud-dependencies</artifactId>
98+
<version>${spring-cloud.version}</version>
99+
<type>pom</type>
100+
<scope>import</scope>
101+
</dependency>
102+
</dependencies>
103+
</dependencyManagement>
104+
105+
<build>
106+
<finalName>${project.artifactId}</finalName>
107+
<plugins>
108+
<plugin>
109+
<groupId>org.springframework.boot</groupId>
110+
<artifactId>spring-boot-maven-plugin</artifactId>
111+
<dependencies>
112+
<dependency>
113+
<groupId>org.springframework</groupId>
114+
<artifactId>springloaded</artifactId>
115+
<version>1.2.5.RELEASE</version>
116+
</dependency>
117+
</dependencies>
118+
</plugin>
119+
<plugin>
120+
<groupId>org.apache.maven.plugins</groupId>
121+
<artifactId>maven-compiler-plugin</artifactId>
122+
<version>3.5.1</version>
123+
<configuration>
124+
<source>1.8</source>
125+
<target>1.8</target>
126+
</configuration>
127+
</plugin>
128+
<!-- <plugin>-->
129+
<!-- <groupId>org.mybatis.generator</groupId>-->
130+
<!-- <artifactId>mybatis-generator-maven-plugin</artifactId>-->
131+
<!-- <version>1.3.2</version>-->
132+
<!-- <configuration>-->
133+
<!-- <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>-->
134+
<!-- <overwrite>true</overwrite>-->
135+
<!-- <verbose>true</verbose>-->
136+
<!-- </configuration>-->
137+
<!-- <dependencies>-->
138+
<!-- <dependency>-->
139+
<!-- <groupId>mysql</groupId>-->
140+
<!-- <artifactId>mysql-connector-java</artifactId>-->
141+
<!-- <version>${mysql.version}</version>-->
142+
<!-- </dependency>-->
143+
<!-- <dependency>-->
144+
<!-- <groupId>tk.mybatis</groupId>-->
145+
<!-- <artifactId>mapper-generator</artifactId>-->
146+
<!-- <version>1.0.0</version>-->
147+
<!-- </dependency>-->
148+
<!-- </dependencies>-->
149+
<!-- </plugin>-->
150+
<plugin>
151+
<groupId>pl.project13.maven</groupId>
152+
<artifactId>git-commit-id-plugin</artifactId>
153+
</plugin>
154+
</plugins>
155+
156+
</build>
157+
158+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.demo;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
@MapperScan(basePackages = {"com.example.demo.dao.mapper"})
9+
public class DemoApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(DemoApplication.class, args);
13+
}
14+
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.example.demo.config;
2+
3+
import com.alibaba.druid.pool.DruidDataSource;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import javax.annotation.Resource;
8+
import javax.sql.DataSource;
9+
10+
/**
11+
* <p></p>
12+
* Created by @author zhezhiyong@163.com on 2020/4/28.
13+
*/
14+
@Configuration
15+
public class DruidConfig {
16+
@Resource
17+
private JdbcParamConfig jdbcParamConfig;
18+
19+
@Bean
20+
public DataSource dataSource() {
21+
DruidDataSource datasource = new DruidDataSource();
22+
datasource.setUrl(jdbcParamConfig.getUrl());
23+
datasource.setDriverClassName(jdbcParamConfig.getDriverClassName());
24+
datasource.setInitialSize(jdbcParamConfig.getInitialSize());
25+
datasource.setMinIdle(jdbcParamConfig.getMinIdle());
26+
datasource.setMaxActive(jdbcParamConfig.getMaxActive());
27+
datasource.setMaxWait(jdbcParamConfig.getMaxWait());
28+
datasource.setValidationQuery("select *");
29+
return datasource;
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.demo.config;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* <p></p>
9+
* Created by @author zhezhiyong@163.com on 2020/4/28.
10+
*/
11+
@Component
12+
@Data
13+
@ConfigurationProperties(prefix = "spring.datasource.click")
14+
public class JdbcParamConfig {
15+
private String driverClassName;
16+
private String url;
17+
private Integer initialSize;
18+
private Integer maxActive;
19+
private Integer minIdle;
20+
private Integer maxWait;
21+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.example.demo.controller;
2+
3+
import com.example.demo.entity.UserInfo;
4+
import com.example.demo.service.UserInfoService;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
import javax.annotation.Resource;
9+
import java.util.List;
10+
11+
/**
12+
* <p></p>
13+
* Created by @author zhezhiyong@163.com on 2020/4/10.
14+
*/
15+
@RestController
16+
@RequestMapping("/user")
17+
public class DemoController {
18+
@Resource
19+
private UserInfoService userInfoService;
20+
21+
@RequestMapping("/saveData")
22+
public String saveData() {
23+
UserInfo userInfo = new UserInfo();
24+
userInfo.setId(4);
25+
userInfo.setUserName("winter");
26+
userInfo.setPassWord("567");
27+
userInfo.setPhone("13977776789");
28+
userInfo.setEmail("winter");
29+
userInfo.setCreateDay("2020-02-20");
30+
userInfoService.saveData(userInfo);
31+
return "sus";
32+
}
33+
34+
@RequestMapping("/selectById")
35+
public UserInfo selectById() {
36+
return userInfoService.selectById(1);
37+
}
38+
39+
@RequestMapping("/selectList")
40+
public List<UserInfo> selectList() {
41+
return userInfoService.selectList();
42+
}
43+
44+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.example.demo.dao;
2+
3+
import com.example.demo.entity.UserInfo;
4+
import org.apache.ibatis.annotations.Mapper;
5+
import org.apache.ibatis.annotations.Param;
6+
7+
import java.util.List;
8+
9+
/**
10+
* <p></p>
11+
* Created by @author zhezhiyong@163.com on 2020/4/28.
12+
*/
13+
@Mapper
14+
public interface UserInfoMapper {
15+
// 写入数据
16+
void saveData(UserInfo userInfo);
17+
18+
// ID 查询
19+
UserInfo selectById(@Param("id") Integer id);
20+
21+
// 查询全部
22+
List<UserInfo> selectList();
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.demo.entity;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* <p></p>
7+
* Created by @author zhezhiyong@163.com on 2020/4/28.
8+
*/
9+
@Data
10+
public class UserInfo {
11+
12+
private Integer id;
13+
private String userName;
14+
private String passWord;
15+
private String phone;
16+
private String email;
17+
private String createDay;
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.demo.service;
2+
3+
import com.example.demo.entity.UserInfo;
4+
5+
import java.util.List;
6+
7+
/**
8+
* <p></p>
9+
* Created by @author zhezhiyong@163.com on 2020/4/28.
10+
*/
11+
public interface UserInfoService {
12+
// 写入数据
13+
void saveData(UserInfo userInfo);
14+
15+
// ID 查询
16+
UserInfo selectById(Integer id);
17+
18+
// 查询全部
19+
List<UserInfo> selectList();
20+
}

0 commit comments

Comments
 (0)