feat: 添加配置存储表及其处理类

This commit is contained in:
禾几海
2020-10-16 16:35:28 +08:00
parent 5f3cbece7b
commit 2fbe030da9
7 changed files with 207 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
package cn.celess.blog.entity;
import lombok.Data;
/**
* @author : xiaohai
* @date : 2020/10/16 15:24
* @desc :
*/
@Data
public class Config {
private Integer id;
private String name;
private String value;
}

View File

@@ -0,0 +1,55 @@
package cn.celess.blog.mapper;
import cn.celess.blog.entity.Config;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author : xiaohai
* @date : 2020/10/16 15:24
* @desc :
*/
@Mapper
@Repository
public interface ConfigMapper {
/**
* 获取单个配置
*
* @param key 配置名
* @return 配置
*/
Config getConfiguration(String key);
/**
* 更新配置
*
* @param c 配置
* @return 改变数据行数
*/
int updateConfiguration(Config c);
/**
* 获取所有配置
*
* @return 所有配置
*/
List<Config> getConfigurations();
/**
* 新增配置
*
* @param c 配置
* @return 改变行数
*/
int addConfiguration(Config c);
/**
* 删除配置
*
* @param id 主键id
* @return 改变行数
*/
int deleteConfiguration(int id);
}

View File

@@ -0,0 +1,50 @@
<?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="cn.celess.blog.mapper.ConfigMapper">
<resultMap type="cn.celess.blog.entity.Config" id="ConfigMap">
<result property="id" column="conf_id" jdbcType="INTEGER"/>
<result property="name" column="conf_name" jdbcType="VARCHAR"/>
<result property="value" column="conf_value" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="getConfiguration" resultMap="ConfigMap">
select conf_id,
conf_name,
conf_value
from config
where conf_name = #{key}
</select>
<!--查询指定行数据-->
<select id="getConfigurations" resultMap="ConfigMap">
select conf_id,
conf_name,
conf_value
from config
</select>
<!--新增所有列-->
<insert id="addConfiguration" keyProperty="id" useGeneratedKeys="true">
insert into config(conf_name, conf_value)
values (#{name}, #{value})
</insert>
<!--通过主键修改数据-->
<update id="updateConfiguration">
update config
set conf_value = #{value}
where conf_id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteConfiguration">
delete
from config
where conf_id = #{id}
</delete>
</mapper>

View File

@@ -214,3 +214,10 @@ VALUES (1, '1.新增网站更新接口api \n2.新增友链api \n3.优化了文
(16, '登陆处理过程变更登陆时长修改至5天', '2019-11-22 11:39:03', 0), (16, '登陆处理过程变更登陆时长修改至5天', '2019-11-22 11:39:03', 0),
(17, '界面改版v2.0', '2020-04-06 11:00:53', 0); (17, '界面改版v2.0', '2020-04-06 11:00:53', 0);
INSERT INTO config (conf_id, conf_name, conf_value)
VALUES (1, 'file.type', 'local'),
(2, 'file.qiniu.accessKey', ''),
(3, 'file.qiniu.secretKey', ''),
(4, 'file.qiniu.bucket', ''),
(6, 'file.local.dictoryPath', ''),
(7, 'db.type', 'h2')

View File

@@ -8,6 +8,7 @@ drop table if exists tag_category;
drop table if exists links; drop table if exists links;
drop table if exists visitor; drop table if exists visitor;
drop table if exists web_update; drop table if exists web_update;
drop table if exists config;
CREATE TABLE `user` CREATE TABLE `user`
@@ -88,7 +89,7 @@ CREATE TABLE `links`
`l_url` varchar(255) unique not null comment '首页地址', `l_url` varchar(255) unique not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址', `l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述', `l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除', `is_delete` boolean not null default false comment '该数据是否被删除',
`l_email` varchar(255) comment '网站管理员的邮箱', `l_email` varchar(255) comment '网站管理员的邮箱',
`l_notification` boolean default false comment '是否通知了' `l_notification` boolean default false comment '是否通知了'
) comment '友站表'; ) comment '友站表';
@@ -110,6 +111,13 @@ CREATE TABLE `web_update`
`is_delete` boolean not null default false comment '该数据是否被删除' `is_delete` boolean not null default false comment '该数据是否被删除'
) comment '更新内容表'; ) comment '更新内容表';
CREATE TABLE `config`
(
`conf_id` int primary key auto_increment,
`conf_name` varchar(255) unique not null comment '配置名',
`conf_value` varchar(255) not null comment '配置值'
);
CREATE VIEW articleView CREATE VIEW articleView
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount, (articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
publishDate, updateDate, isOpen, publishDate, updateDate, isOpen,

View File

@@ -8,6 +8,7 @@ drop table if exists tag_category;
drop table if exists links; drop table if exists links;
drop table if exists visitor; drop table if exists visitor;
drop table if exists web_update; drop table if exists web_update;
drop table if exists config;
-- 用户表 -- 用户表
CREATE TABLE `user` CREATE TABLE `user`
@@ -115,6 +116,13 @@ CREATE TABLE `web_update`
`is_delete` boolean not null default false comment '该数据是否被删除' `is_delete` boolean not null default false comment '该数据是否被删除'
); );
CREATE TABLE `config`
(
`conf_id` int primary key auto_increment,
`conf_name` varchar(255) unique not null comment '配置名',
`conf_value` varchar(255) not null comment '配置值'
);
CREATE VIEW articleView CREATE VIEW articleView
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount, (articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
publishDate, updateDate, isOpen, publishDate, updateDate, isOpen,

View File

@@ -0,0 +1,63 @@
package cn.celess.blog.mapper;
import cn.celess.blog.BaseTest;
import cn.celess.blog.entity.Config;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.*;
public class ConfigMapperTest extends BaseTest {
@Autowired
ConfigMapper configMapper;
@Test
public void getConfiguration() {
Config file = configMapper.getConfiguration("file.type");
assertNotNull(file);
assertNotNull(file.getId());
assertEquals("file.type", file.getName());
assertEquals("local", file.getValue());
}
@Test
public void updateConfiguration() {
Config config = generateConfig();
configMapper.addConfiguration(config);
assertNotNull(config.getId());
String s = randomStr();
config.setValue(s);
configMapper.updateConfiguration(config);
assertEquals(s, configMapper.getConfiguration(config.getName()).getValue());
}
@Test
public void getConfigurations() {
assertTrue(configMapper.getConfigurations().size() > 0);
}
@Test
public void addConfiguration() {
Config config = generateConfig();
configMapper.addConfiguration(config);
assertNotNull(config.getId());
}
@Test
public void deleteConfiguration() {
Config config = generateConfig();
configMapper.addConfiguration(config);
assertNotNull(config.getId());
assertNotEquals(0, configMapper.deleteConfiguration(config.getId()));
assertNull(configMapper.getConfiguration(config.getName()));
}
private Config generateConfig() {
Config config = new Config();
config.setName("test" + randomStr(4));
config.setValue(randomStr(4));
return config;
}
}