一、服务器安装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. 一个很酷炫也挺实用的JS库leader-line

    简单粗暴,直入主题,看看效果再说. 是不是这效果挺棒?这样的效果在做系统时,可以有很多的应用,可以让枯燥的页面生动起来. 具体效果,大家可以上这个搜索网站Mag[i]上面看,切身体会一下. 这是一个开 ...

  2. 大厂前端工程师教你如何使用css3绘制任意角度扇形+动画

    这里只是做下原理解释,原理:使用两个半圆做角度拼接.比如想绘制一个缺口朝右,缺口弧度30度角的扇形 资源网站搜索大全https://55wd.com 那么将由一个旋转65度角的半圆A+一个旋转-65度 ...

  3. POJ1852 Ants 题解

    题目 An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. W ...

  4. Python爬虫教程(16行代码爬百度)

    最近在学习python,不过有一个正则表达式一直搞不懂,自己直接使用最笨的方法写出了一个百度爬虫,只有短短16行代码.首先安装必背包: pip3 install bs4 pip3 install re ...

  5. Pandas基础知识图谱

    所有内容整理自<利用Python进行数据分析>,使用MindMaster Pro 7.3制作,emmx格式,源文件已经上传Github,需要的同学转左上角自行下载或者右击保存图片.该图谱只 ...

  6. JavaScript location对象、Navigator对象、Screen对象简介

    Location对象 location用于获取或设置窗体的URL,并且可以用于解析URL. 语法: location.[属性|方法] Location对象属性 Location对象方法: Naviga ...

  7. python 并发专题(七):Twisted相关函数以及实现

    一.基础原理 二.基本函数 三.爬虫实现 四.web服务器与客户端实现

  8. 1.对Java平台的理解。“Java是解释执行”对吗

    Java本身是一种面向对象的语言,最显著的特性有两个方面,一是所谓的“书写一次,到处运行”,能够非常容易地获得跨平台能力: 另外就是垃圾收集(GC),Java通过垃圾收集器(Garbage Colle ...

  9. Python切图脚本

    背景: 时值疫情,作业需要在网上提交.最近老师改变了交作业方式,之前是提交完整的作业图片即可,现在需要将完整的作业图片切分成一题一题的提交,如果手动切分较麻烦,故本人写了个python脚本实现自动切分 ...

  10. Mysql UDF提权方法

    0x01 UDF UDF(user defined function)用户自定义函数,是mysql的一个拓展接口.用户可以通过自定义函数实现在mysql中无法方便实现的功能,其添加的新函数都可以在sq ...