如何在Java代码中根据表中某个字段的查询返回该字段的数据和对应的表头

今天接了一个需求,前端代码传一个入参,java后端返回该入参和该入参对应的表头的一部分,比如前段传入一个入参为$2GSiteId,我们返回$2GSiteId对应的数据和2G:
①定义一个So类,定义入参变量

private String $2GSiteId;

public String get$2GSiteId() {
    return $2GSiteId;
}

public void set$2GSiteId(String $2GSiteId) {
    this.$2GSiteId = $2GSiteId;
}

②在业务层代码中新建map集合,使用jdk8新特性返回所需的数据

Map<String, Object> map = new HashMap<String, Object>();
    List<String> enbCode = new ArrayList<>();
    if (!StringUtils.isEmpty(so.get$2GSiteId())) {
        List<String> finalEnbCode = enbCode;
        Arrays.stream(so.get$2GSiteId().split(",")).forEach(key -> {
            map.put(key,"2G");
            finalEnbCode.add(key);
        });
    }

    if (!StringUtils.isEmpty(so.get$4GSiteId())) 
        List<String> finalEnbCode = enbCode;
        Arrays.stream(so.get$4GSiteId().split(",")).forEach(key -> {
            map.put(key,"4G");
            finalEnbCode.add(key);
        });
    }

    if (!StringUtils.isEmpty(so.get$5GSiteId())) {
        List<String> finalEnbCode = enbCode;
        Arrays.stream(so.get$5GSiteId().split(",")).forEach(key -> {
            map.put(key,"5G");
            finalEnbCode.add(key);
        });
    }

    String unit = StringUtils.strip(enbCode.toString(), "[]");
    String strEnbCode = unit.replace(",","','").replace(" ", "");

③ 在返回实体类中新建一个返回对应2G数据的变量type

private String type;

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

④ 在业务层调用该变量type

TestDto testDto = new TestDto();
testDto.setType(map.get(alarmCorrelationDto.getSiteId()).toString());
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值