一、服务器安装clickhouse服务

参阅 :https://www.cnblogs.com/liuyangfirst/p/13379064.html

二.连接数据库

成功

三、新建库

 CREATE/ATTACH DATABASE zabbix ENGINE = Ordinary;

ATTACH 也可以建库,但是metadata目录下不会生成.sql文件,一般用于metadata元数据sql文件被删除后,恢复库表结构使用。

这里采用

 CREATE DATABASE mrliu ENGINE = Ordinary;

四、创建表

 CREATE TABLE mrliu.userinformation (
`id` UInt16,
`user_name` String,
`user_age` String,
`user_sex` String,
`user_id_card` String,
`user_phone` String,
`user_from` String,
`user_minzu` String,
`user_address` String,
`user_zhiye` String,
`user_educate` String,
`iddeleted` Int8,
`update_date` Date,
`create_date` Date ) ENGINE = MergeTree(create_date,
id,
8192)

五、添加数据

 INSERT INTO mrliu.userinformation (id,user_name,user_age,user_sex,user_id_card,user_phone,user_from,user_minzu,user_address,user_zhiye,user_educate,iddeleted,update_date,create_date) VALUES (
1,'赵大','','男','','','中国浙江','汉族','西湖区果哥子大街2020号','销售','本科',0,'2020-05-07','2020-07-25');

六、创建springboot项目

1.引入pom依赖

 <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mrliu</groupId>
<artifactId>undertow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>undertow</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.2.1</spring-boot-admin.version>
</properties> <dependencies> <!--引入knife4j以来-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>1.9.6</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency> <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>test</scope>
</dependency> <!-- tomcat支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency> <!-- 用于编译jsp-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- jsp标签库 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.13</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</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>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency> <!--转化工具-->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.26</version>
</dependency>
</dependencies> <build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

2.实体类建立

 package com.mrliu.undertow.pojo;

 import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; /**
* 用户信息
*
* @author liuyangos8888
*/
@ApiModel("用户信息")
public class UserInfo { @ApiModelProperty(required = true, notes = "用户ID", example = "001")
private Integer id; @ApiModelProperty(required = true, notes = "用户姓名", example = "龙五")
private String userName; @ApiModelProperty(required = true, notes = "用户年龄", example = "28")
private String userAge; @ApiModelProperty(required = true, notes = "用户性别", example = "男")
private String userSex; @ApiModelProperty(required = true, notes = "用户身份证", example = "24511000012234512")
private String userIdCard; @ApiModelProperty(required = true, notes = "用户号码", example = "13745124512")
private String userPhone; @ApiModelProperty(required = true, notes = "用户产地", example = "安徽")
private String userFrom; @ApiModelProperty(required = true, notes = "用户民族", example = "汉族")
private String userMinZu; @ApiModelProperty(required = true, notes = "用户住址", example = "某某大街110号")
private String userAddress; @ApiModelProperty(required = true, notes = "用户职业", example = "大佬")
private String userZhiYe; @ApiModelProperty(required = true, notes = "用户学历", example = "小学")
private String userEducate; @ApiModelProperty(required = true, notes = "用户是否存在", example = "否")
private Integer idDeleted; @ApiModelProperty(required = true, notes = "用户信息更新时间", example = "2020-07-18 22:22:22")
private String updateDate; @ApiModelProperty(required = true, notes = "用户创建", example = "2020-07-18 22:22:22")
private String createDate; 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 getUserAge() {
return userAge;
} public void setUserAge(String userAge) {
this.userAge = userAge;
} public String getUserSex() {
return userSex;
} public void setUserSex(String userSex) {
this.userSex = userSex;
} public String getUserIdCard() {
return userIdCard;
} public void setUserIdCard(String userIdCard) {
this.userIdCard = userIdCard;
} public String getUserPhone() {
return userPhone;
} public void setUserPhone(String userPhone) {
this.userPhone = userPhone;
} public String getUserFrom() {
return userFrom;
} public void setUserFrom(String userFrom) {
this.userFrom = userFrom;
} public String getUserMinZu() {
return userMinZu;
} public void setUserMinZu(String userMinZu) {
this.userMinZu = userMinZu;
} public String getUserAddress() {
return userAddress;
} public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
} public String getUserZhiYe() {
return userZhiYe;
} public void setUserZhiYe(String userZhiYe) {
this.userZhiYe = userZhiYe;
} public String getUserEducate() {
return userEducate;
} public void setUserEducate(String userEducate) {
this.userEducate = userEducate;
} public Integer getIdDeleted() {
return idDeleted;
} public void setIdDeleted(Integer idDeleted) {
this.idDeleted = idDeleted;
} public String getUpdateDate() {
return updateDate;
} public void setUpdateDate(String updateDate) {
this.updateDate = updateDate;
} public String getCreateDate() {
return createDate;
} public void setCreateDate(String createDate) {
this.createDate = createDate;
}
}

3.dao建立

 package com.mrliu.undertow.mapper;

 import com.mrliu.undertow.pojo.UserInfo;
import org.apache.ibatis.annotations.Mapper; import java.util.List; /**
* @author Administrator
*/ @Mapper
public interface UserInfoMapper { /**
* 查询全部
*
* @return
*/
List<UserInfo> selectList(); }

4.配置文件xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.click.house.mapper.UserInfoMapper">
<resultMap id="BaseResultMap" type="com.click.house.entity.UserInfo">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="user_name" jdbcType="VARCHAR" property="user_name" />
<result column="user_age" jdbcType="VARCHAR" property="user_age" />
<result column="user_sex" jdbcType="VARCHAR" property="user_sex" />
<result column="user_id_card" jdbcType="VARCHAR" property="user_id_card" />
<result column="user_phone" jdbcType="VARCHAR" property="user_phone" />
<result column="user_from" jdbcType="VARCHAR" property="user_from" />
<result column="user_minzu" jdbcType="VARCHAR" property="user_minzu" />
<result column="user_address" jdbcType="VARCHAR" property="user_address" />
<result column="user_zhiye" jdbcType="VARCHAR" property="user_zhiye" />
<result column="user_educate" jdbcType="VARCHAR" property="user_educate" />
<result column="iddeleted" jdbcType="INTEGER" property="iddeleted" />
<result column="update_date" jdbcType="VARCHAR" property="update_date" />
<result column="create_date" jdbcType="VARCHAR" property="create_date" />
</resultMap> <sql id="Base_Column_List">
id, user_name, user_age, user_sex, user_id_card, user_phone, user_from, user_minzu, user_address, user_zhiye, user_educate, iddeleted, update_date, create_date
</sql> <insert id="saveData" parameterType="com.click.house.entity.UserInfo" >
INSERT INTO cs_user_info
(id,user_name,pass_word,phone,email,create_day)
VALUES
(#{id,jdbcType=INTEGER},#{userName,jdbcType=VARCHAR},#{passWord,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},#{createDay,jdbcType=VARCHAR})
</insert> <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from cs_user_info
where id = #{id,jdbcType=INTEGER}
</select> <select id="selectList" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from userinformation
</select>
</mapper>

5.service层建立

service

 package com.mrliu.undertow.service;

 import com.mrliu.undertow.pojo.UserInfo;

 import java.util.List;

 public interface UserInfoService {

     /**
* 查询全部
*
* @return
*/
List<UserInfo> selectList();
}

serviceImpl

 package com.mrliu.undertow.service.impl;

 import com.mrliu.undertow.mapper.UserInfoMapper;
import com.mrliu.undertow.pojo.UserInfo;
import com.mrliu.undertow.service.UserInfoService;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.List; /**
* @author Administrator
*/
@Service
public class UserInfoServiceImpl implements UserInfoService { @Resource
private UserInfoMapper userInfoMapper; @Override
public List<UserInfo> selectList() {
return userInfoMapper.selectList();
}
}

6.controller层建立

 package com.mrliu.undertow.controller;

 import com.mrliu.undertow.pojo.UserInfo;
import com.mrliu.undertow.service.UserInfoService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; /**
* @author liuyangos8888
*/
@Api(tags = "用户操作功能接口")
@RestController
@RequestMapping("/user")
public class UserInfoController { private static Logger log = LoggerFactory.getLogger(UserInfoController.class); @Resource
private UserInfoService userInfoService; /**
* 查询所有数据
*
* @return 所有数据
*/
@ApiResponses(value = {
@ApiResponse(code = 200, message = "接口返回成功状态"),
@ApiResponse(code = 500, message = "接口返回未知错误,请联系开发人员调试")
})
@ApiOperation(value = "用户全查接口", notes = "访问此接口,返回hello语句,测试接口")
@GetMapping("/selectList")
public List<UserInfo> selectList() {
return userInfoService.selectList();
} @ApiResponses(value = {
@ApiResponse(code = 200, message = "接口返回成功状态"),
@ApiResponse(code = 500, message = "接口返回未知错误,请联系开发人员调试")
})
@ApiOperation(value = "JSP全查接口", notes = "访问此接口,返回hello语句,测试接口")
@RequestMapping(value = "/selectList2", produces = "application/json;charset=UTF-8", method = {RequestMethod.GET})
public void selectList2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<UserInfo> list = userInfoService.selectList(); List<Map<String, Object>> mapList = getMapsResult(list); log.info("进入了selectList2方法!"); ModelAndView mav = new ModelAndView("jspIndex.jsp");
mav.addObject("list", mapList);
request.setAttribute("list", mapList);
request.getRequestDispatcher("/WEB-INF/jsp/jspIndex.jsp").forward(request, response);
} @ApiResponses(value = {
@ApiResponse(code = 200, message = "接口返回成功状态"),
@ApiResponse(code = 500, message = "接口返回未知错误,请联系开发人员调试")
})
@ApiOperation(value = "自定义JSP全查接口", notes = "访问此接口,返回hello语句,测试接口")
@RequestMapping(value = "/selectList3", produces = "application/json;charset=UTF-8", method = {RequestMethod.GET})
public void selectList3(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<UserInfo> list = new ArrayList<>(); UserInfo userInfo = new UserInfo();
userInfo.setId(2);
userInfo.setUserName("李四");
userInfo.setUserAge("112");
userInfo.setUserSex("男");
userInfo.setUserIdCard("10001199104131278");
userInfo.setUserPhone("1371452312");
userInfo.setUserFrom("浙江");
userInfo.setUserMinZu("汉族");
userInfo.setUserAddress("某某大陆某某大街2220号");
userInfo.setUserZhiYe("教师");
userInfo.setUserEducate("博士"); userInfo.setCreateDate("2020-05-17 22:22:22");
userInfo.setUpdateDate("2020-05-17 22:22:22");
userInfo.setIdDeleted(0);
list.add(userInfo); log.info("进入了selectList3方法!"); ModelAndView mav = new ModelAndView("jspIndex.jsp");
mav.addObject("list", list);
request.setAttribute("list", list);
request.getRequestDispatcher("/WEB-INF/jsp/jspIndex.jsp").forward(request, response);
} private List<Map<String, Object>> getMapsResult(List<UserInfo> list) {
List<Map<String, Object>> mapList = new ArrayList<>(); for (UserInfo userInfo : list) { Map<String, Object> map = new LinkedHashMap<>(); map.put("id", userInfo.getId());
map.put("userName", userInfo.getUserName());
map.put("userAge", userInfo.getUserAge());
map.put("userSex", userInfo.getUserSex());
map.put("userIdCard", userInfo.getUserIdCard());
map.put("userPhone", userInfo.getUserPhone());
map.put("userFrom", userInfo.getUserFrom());
map.put("userMinZu", userInfo.getUserMinZu());
map.put("userAddress", userInfo.getUserAddress());
map.put("userEducate", userInfo.getUserEducate());
map.put("userZhiYe", userInfo.getUserZhiYe());
map.put("updateDate", userInfo.getUpdateDate());
map.put("createDate", userInfo.getCreateDate());
map.put("idDeleted", userInfo.getIdDeleted());
mapList.add(map);
}
return mapList;
} }

7.yml配置

 server:
port: 7788
tomcat:
uri-encoding: UTF-8
servlet:
encoding:
charset: UTF-8
force: true
enabled: true
context-path: / #springmvc
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
datasource:
type: com.alibaba.druid.pool.DruidDataSource
click:
driverClassName: ru.yandex.clickhouse.ClickHouseDriver
url: jdbc:clickhouse://127.0.0.1:8123/mrliu
initialSize: 10
maxActive: 100
minIdle: 10
maxWait: 6000 # mybatis 配置
mybatis:
type-aliases-package: com.mrliu.undertow.pojo
mapper-locations: classpath:/mapper/*.xml

8.启动测试

访问:

http://localhost:7016/user//selectList

参考:

1. clickhouse 安装 
查看 https://www.cnblogs.com/liuyangfirst/p/13379064.html
2. Knife4J 使用
查看 https://www.cnblogs.com/liuyangfirst/p/12900597.html
3. IDEA使用
查看 https://www.cnblogs.com/liuyangfirst/tag/IntelliJ%20IDEA%E4%BD%BF%E7%94%A8/

参考

Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(一)的更多相关文章

  1. Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(三)(添加增删改查)

    一.添加增加接口 @ApiResponses(value = { @ApiResponse(code = 200, message = "接口返回成功状态"), @ApiRespo ...

  2. SpringBoot+Mybatis多模块(module)项目搭建教程

    一.前言 最近公司项目准备开始重构,框架选定为SpringBoot+Mybatis,本篇主要记录了在IDEA中搭建SpringBoot多模块项目的过程. 1.开发工具及系统环境 IDE:Intelli ...

  3. Springboot+MyBatis+mysql+jsp页面跳转详细示例

           SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...

  4. JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识

    JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...

  5. Spring-boot+Mybatis+Maven+MySql搭建实例

    转自:https://www.jianshu.com/p/95fb7be049ae 最近读了spring-boot开发手册,spring-boot相比于spring-mvc封装了很多常用的依赖,并且内 ...

  6. springboot+mybatis+mysql创建简单web后台项目

    第一步:搭建框架 新建进入这个页面 新建名字,第一次可以默认,然后下一步 第三步:选择依赖 第四步:新建项目名和存放项目路径(你可以新建一个文件夹存放) 点击finish,首次创建Springboot ...

  7. Spring+SpringMvc+Mybatis框架集成搭建教程一(项目创建)

    一.框架搭建环境 Spring 4.2.6.RELEASE SpringMvc 4.2.6.RELEASE Mybatis 3.2.8 Maven 3.3.9 Jdk 1.7 Idea 15.04 二 ...

  8. Spring+SpringMvc+Mybatis框架集成搭建教程四(项目部署及测试)

    在IDEA中将项目部署到本地Tomcat下进行运行并验证整合结果 (1).点击如下图所示的下拉按钮,弹出Edit Configurations...后点击该项. (2).跳出如下界面后,点击红框内的& ...

  9. 1.SpringBoot之Helloword 快速搭建一个web项目

    背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...

随机推荐

  1. gulp之demo

    1.安装gulp cnpm install -g gulp; 2.然后还需要在当前目录安装gulp,具体不详,只知道安装了之后会在当前目录下的node_modules下多一个gulp文件夹 cnpm ...

  2. MySQL 索引结构 hash 有序数组

    MySQL 索引结构 hash 有序数组 除了最常见的树形索引结构,Hash索引也有它的独到之处.   Hash算法 Hash本身是一种函数,又被称为散列函数. 它的思路很简单:将key放在数组里,用 ...

  3. Codeforces 1292C Xenon's Attack on the Gangs 题解

    题目 On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a ...

  4. sql-exists、not exists的用法

    exists : 强调的是是否返回结果集,不要求知道返回什么, 比如:select name from student where sex = 'm' and mark exists(select 1 ...

  5. 【Blazor】在ASP.NET Core中使用Blazor组件 - 创建一个音乐播放器

    前言 Blazor正式版的发布已经有一段时间了,.NET社区的各路高手也创建了一个又一个的Blazor组件库,其中就包括了我和其他小伙伴一起参与的AntDesign组件库,于上周终于发布了第一个版本0 ...

  6. VSCode下,项识别为 cmdlet、函数、脚本文件或可运行程序的名称。

    vscode下webpack错误:无法将“webpack”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. 解决方法: 1.因为 ...

  7. 2.5万字长文简单总结SpringMVC请求参数接收

    这是公众号<Throwable文摘>发布的第22篇原创文章,暂时收录于专辑<架构与实战>.暂定下一篇发布的长文是<图文分析JUC同步器框架>,下一篇发布的短文是&l ...

  8. row_number() over()排序功能说明

    1.row_number() over()排序功能: (1) row_number() over()分组排序功能: 在使用 row_number() over()函数时候,over()里头的分组以及排 ...

  9. CocosCreator之分层管理的ListView

    前言 进入公众号回复listview即可获得demo的git地址. 之前写的一篇文章<Creator之ScrollView那些事>中提到了官方Demo中提供的ListViewCtl,只是实 ...

  10. C#中的char和string的使用简介

    char 字符 char代表一个Unicode字符,它是System.Char的别名 char someChar = 'a';//定义了一个字符 char newLine= '\n';//这是一个换行 ...