Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(一)
一、服务器安装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 搭建单体应用项目(一)的更多相关文章
- Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(三)(添加增删改查)
一.添加增加接口 @ApiResponses(value = { @ApiResponse(code = 200, message = "接口返回成功状态"), @ApiRespo ...
- SpringBoot+Mybatis多模块(module)项目搭建教程
一.前言 最近公司项目准备开始重构,框架选定为SpringBoot+Mybatis,本篇主要记录了在IDEA中搭建SpringBoot多模块项目的过程. 1.开发工具及系统环境 IDE:Intelli ...
- Springboot+MyBatis+mysql+jsp页面跳转详细示例
SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...
- JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...
- Spring-boot+Mybatis+Maven+MySql搭建实例
转自:https://www.jianshu.com/p/95fb7be049ae 最近读了spring-boot开发手册,spring-boot相比于spring-mvc封装了很多常用的依赖,并且内 ...
- springboot+mybatis+mysql创建简单web后台项目
第一步:搭建框架 新建进入这个页面 新建名字,第一次可以默认,然后下一步 第三步:选择依赖 第四步:新建项目名和存放项目路径(你可以新建一个文件夹存放) 点击finish,首次创建Springboot ...
- 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 二 ...
- Spring+SpringMvc+Mybatis框架集成搭建教程四(项目部署及测试)
在IDEA中将项目部署到本地Tomcat下进行运行并验证整合结果 (1).点击如下图所示的下拉按钮,弹出Edit Configurations...后点击该项. (2).跳出如下界面后,点击红框内的& ...
- 1.SpringBoot之Helloword 快速搭建一个web项目
背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...
随机推荐
- C# 自定义常用代码段快捷键
不断更新中... 分享地址:http://pan.baidu.com/s/15oE0X
- 读取模式下cbc latch的事件模拟(热块竞争和热链竞争)-P62
文章目录 1. 背景 2. 过程 2.1 热块竞争 2.1.1 版本11.2.0.1.0 2.1.1.1 session 1(sid:34) 2.1.1.2 session 2(sid:35) 2.1 ...
- 【学习随手记】kubeadm 查看创建集群需要的镜像版本,附拉取镜像脚本
查看创建集群需要的镜像版本 kubeadm config images list [--kubernetes-version <version>] 国内拉取镜像脚本 一般而言,直接使用ku ...
- 好看css搜索框样式_分享8款纯CSS搜索框
最简单实用的CSS3搜索框样式,纯CSS效果无需任何javascript,其中部分搜索框在点击的时候有动画特效,搜索框的应用也是比较普通的,效果如下: 设计网站大全https://www.wode00 ...
- (四)ansible 通过堡垒机访问内网服务器
场景: 在ansible的使用过程中,存在这样的场景,ansible所在的管理节点与被管理的机器需要 通过一个跳板机才能连接,无法直接连接.要解决这个问题,并不需要在 ansible里做什么处 ...
- JVM 专题六:运行时数据区(一)概述
1. 运行时数据区架构图 2. 内存 内存是非常重要的系统资源,是硬盘和cpu的中间仓库及桥梁,承载着操作系统和应用程序的实时运行.JVM内存布局规定了JAVA在运行过程中内存申请.分配.管理的策略, ...
- 数据可视化之powerBI入门(七)数据清洗中最常使用的十三招
https://mp.weixin.qq.com/s?__biz=MzA4MzQwMjY4MA==&mid=2484067158&idx=1&sn=4ad955112df2f4 ...
- Python之爬虫(二十四) 爬虫与反爬虫大战
爬虫与发爬虫的厮杀,一方为了拿到数据,一方为了防止爬虫拿到数据,谁是最后的赢家? 重新理解爬虫中的一些概念 爬虫:自动获取网站数据的程序反爬虫:使用技术手段防止爬虫程序爬取数据误伤:反爬虫技术将普通用 ...
- Newbe.Claptrap 框架中为什么用 Claptrap 和 Minion 两个词?
Newbe.Claptrap 框架中为什么用 Claptrap 和 Minion 两个词?最近整理了一下项目的术语表.今天就谈谈为什么起了 Claptrap 和 Minion 两个名字. Claptr ...
- POJ 1050 To the Max 最详细的解题报告
题目来源:To the Max 题目大意:给定一个N*N的矩阵,求该矩阵中的某一个矩形,该矩形内各元素之和最大,即最大子矩阵问题. 解题方法:最大子序列之和的扩展 解题步骤: 1.定义一个N*N的矩阵 ...