forked from zhoustone/middle-ware-parent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SpringBoot2 整合 ClickHouse数据库,实现数据高性能查询分析
- Loading branch information
cicadasmile
committed
Oct 7, 2019
1 parent
0170734
commit 437fea5
Showing
15 changed files
with
424 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starters</artifactId> | ||
<version>2.1.3.RELEASE</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.click.house</groupId> | ||
<artifactId>ware-click-house</artifactId> | ||
<packaging>jar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>5.1.38</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid-spring-boot-starter</artifactId> | ||
<version>1.1.13</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>2.6</version> | ||
</dependency> | ||
<!-- clickHouse数据库 --> | ||
<dependency> | ||
<groupId>ru.yandex.clickhouse</groupId> | ||
<artifactId>clickhouse-jdbc</artifactId> | ||
<version>0.1.53</version> | ||
</dependency> | ||
</dependencies> | ||
<!-- 项目构建 --> | ||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
ware-click-house/src/main/java/com/click/house/Application7016.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.click.house; | ||
|
||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@MapperScan(basePackages = {"com.click.house.mapper"}) | ||
public class Application7016 { | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application7016.class,args) ; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
ware-click-house/src/main/java/com/click/house/config/DruidConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.click.house.config; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import javax.annotation.Resource; | ||
import javax.sql.DataSource; | ||
|
||
@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()); | ||
return datasource; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
ware-click-house/src/main/java/com/click/house/config/JdbcParamConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.click.house.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@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 ; | ||
public String getDriverClassName() { | ||
return driverClassName; | ||
} | ||
public void setDriverClassName(String driverClassName) { | ||
this.driverClassName = driverClassName; | ||
} | ||
public String getUrl() { | ||
return url; | ||
} | ||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
public Integer getInitialSize() { | ||
return initialSize; | ||
} | ||
public void setInitialSize(Integer initialSize) { | ||
this.initialSize = initialSize; | ||
} | ||
public Integer getMaxActive() { | ||
return maxActive; | ||
} | ||
public void setMaxActive(Integer maxActive) { | ||
this.maxActive = maxActive; | ||
} | ||
public Integer getMinIdle() { | ||
return minIdle; | ||
} | ||
public void setMinIdle(Integer minIdle) { | ||
this.minIdle = minIdle; | ||
} | ||
public Integer getMaxWait() { | ||
return maxWait; | ||
} | ||
public void setMaxWait(Integer maxWait) { | ||
this.maxWait = maxWait; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
ware-click-house/src/main/java/com/click/house/controller/UserInfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.click.house.controller; | ||
|
||
import com.click.house.entity.UserInfo; | ||
import com.click.house.service.UserInfoService; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
public class UserInfoController { | ||
@Resource | ||
private UserInfoService userInfoService ; | ||
@RequestMapping("/saveData") | ||
public String saveData (){ | ||
UserInfo userInfo = new UserInfo () ; | ||
userInfo.setId(4); | ||
userInfo.setUserName("winter"); | ||
userInfo.setPassWord("567"); | ||
userInfo.setPhone("13977776789"); | ||
userInfo.setEmail("winter"); | ||
userInfo.setCreateDay("2020-02-20"); | ||
userInfoService.saveData(userInfo); | ||
return "sus"; | ||
} | ||
@RequestMapping("/selectById") | ||
public UserInfo selectById () { | ||
return userInfoService.selectById(1) ; | ||
} | ||
@RequestMapping("/selectList") | ||
public List<UserInfo> selectList () { | ||
return userInfoService.selectList() ; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
ware-click-house/src/main/java/com/click/house/entity/UserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.click.house.entity; | ||
|
||
public class UserInfo { | ||
|
||
private Integer id ; | ||
private String userName ; | ||
private String passWord ; | ||
private String phone ; | ||
private String email ; | ||
private String createDay ; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUserName() { | ||
return userName; | ||
} | ||
|
||
public void setUserName(String userName) { | ||
this.userName = userName; | ||
} | ||
|
||
public String getPassWord() { | ||
return passWord; | ||
} | ||
|
||
public void setPassWord(String passWord) { | ||
this.passWord = passWord; | ||
} | ||
|
||
public String getPhone() { | ||
return phone; | ||
} | ||
|
||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getCreateDay() { | ||
return createDay; | ||
} | ||
|
||
public void setCreateDay(String createDay) { | ||
this.createDay = createDay; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ware-click-house/src/main/java/com/click/house/mapper/UserInfoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.click.house.mapper; | ||
|
||
import com.click.house.entity.UserInfo; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface UserInfoMapper { | ||
// 写入数据 | ||
void saveData (UserInfo userInfo) ; | ||
// ID 查询 | ||
UserInfo selectById (@Param("id") Integer id) ; | ||
// 查询全部 | ||
List<UserInfo> selectList () ; | ||
} |
14 changes: 14 additions & 0 deletions
14
ware-click-house/src/main/java/com/click/house/service/UserInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.click.house.service; | ||
|
||
import com.click.house.entity.UserInfo; | ||
|
||
import java.util.List; | ||
|
||
public interface UserInfoService { | ||
// 写入数据 | ||
void saveData (UserInfo userInfo) ; | ||
// ID 查询 | ||
UserInfo selectById (Integer id) ; | ||
// 查询全部 | ||
List<UserInfo> selectList () ; | ||
} |
31 changes: 31 additions & 0 deletions
31
ware-click-house/src/main/java/com/click/house/service/impl/UserInfoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.click.house.service.impl; | ||
|
||
import com.click.house.entity.UserInfo; | ||
import com.click.house.mapper.UserInfoMapper; | ||
import com.click.house.service.UserInfoService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.List; | ||
|
||
@Service | ||
public class UserInfoServiceImpl implements UserInfoService { | ||
|
||
@Resource | ||
private UserInfoMapper userInfoMapper ; | ||
|
||
@Override | ||
public void saveData(UserInfo userInfo) { | ||
userInfoMapper.saveData(userInfo); | ||
} | ||
|
||
@Override | ||
public UserInfo selectById(Integer id) { | ||
return userInfoMapper.selectById(id); | ||
} | ||
|
||
@Override | ||
public List<UserInfo> selectList() { | ||
return userInfoMapper.selectList(); | ||
} | ||
} |
Oops, something went wrong.