动态的页面参数数据库设计

1.简介: 当我们遇到页面的参数不确定,或者需求在不断变化的时候,这时,一个合理的数据库设计就可以帮我们省去很多麻烦,很多人采用的是横向添加的模式(横表),一个属性对应一个数据库的字段。这样属性的增加减少会对表结构产生影响,所以我们选择垂直添加模式(纵表)

下面我们有这些属性:为了节省空间 我就没有添加get,set方法

public class TradingEspParamDto {

	private String isRiskProt;    //是否启用风险策略 1 是,0否
	private String isSamePrice;   //是否启用相同价格控制  1是0否
	private String isSameCounterparty; //是否启用相同对手方控制 1是0否
	private String samePriceTime;   //相同价格时间
	private String samePriceNumber;  //相同价格次数
	private String samePriceThreshold;  //相同价格交易量
	private String sameCounterpartyTime;  //相同对手方时间
	private String sameCounterpartyNumber;  //相同对手方次数
	
	
	
}

2.下面看一下数据库,prop_name 中的一个值为一个属性,prop_value中的值为对应的属性值

 3.数据库中的表

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for trading_esp_param
-- ----------------------------
DROP TABLE IF EXISTS `trading_esp_param`;
CREATE TABLE `trading_esp_param` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `prop_name` varchar(255) DEFAULT NULL,
  `prop_value` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of trading_esp_param
-- ----------------------------
INSERT INTO `trading_esp_param` VALUES ('1', 'ESP_IS_RISK_PROT', '0');
INSERT INTO `trading_esp_param` VALUES ('2', 'ESP_IS_SAME_PRICE', '1');
INSERT INTO `trading_esp_param` VALUES ('3', 'ESP_IS_SAME_COUNTERPARTY', '1');
INSERT INTO `trading_esp_param` VALUES ('4', 'ESP_SAME_PRICE_TIME', '3');
INSERT INTO `trading_esp_param` VALUES ('5', 'ESP_SAME_PRICE_NUMBER', '4');
INSERT INTO `trading_esp_param` VALUES ('6', 'ESP_SAME_PRICE_THRESHOLD', '10');
INSERT INTO `trading_esp_param` VALUES ('7', 'ESP_SAME_COUNTERPARTY_TIME', '3');
INSERT INTO `trading_esp_param` VALUES ('8', 'ESP_SAME_COUNTERPARTY_NUMBER', '2');

4.对表进行查询显示如下

 5.sql查询语句:

      select 
            MAX(case prop_name when 'ESP_IS_RISK_PROT' then prop_value else '' end) as isRiskProt,
            MAX(case prop_name when 'ESP_IS_SAME_PRICE' then prop_value else '' end) as isSamePrice,
            MAX(case prop_name when 'ESP_IS_SAME_COUNTERPARTY' then prop_value else '' end) as isSameCounterparty,
            MAX(case prop_name when 'ESP_SAME_PRICE_TIME' then prop_value else '' end) as samePriceTime,
            MAX(case prop_name when 'ESP_SAME_PRICE_NUMBER' then prop_value else '' end) as samePriceNumber,
            MAX(case prop_name when 'ESP_SAME_PRICE_THRESHOLD' then prop_value else '' end) as samePriceThreshold,
            MAX(case prop_name when 'ESP_SAME_COUNTERPARTY_TIME' then prop_value else '' end) as sameCounterpartyTime,
            MAX(case prop_name when 'ESP_SAME_COUNTERPARTY_NUMBER' then prop_value else '' end) as sameCounterpartyNumber
          
       from trading_esp_param

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值