不明确类型,用Object接收,再用instanceof进行类型判断

11111

不明确类型,用Object接收,再用instanceof进行类型判断

package com.zhetang.model.bo.realtime;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

/**
 * Created with IntelliJ IDEA.
 * User:wq
 * Date:2021/4/21
 * Time: 17:34
 * Description: 安全监测点位、⼯艺DCS监测点位报警数据
 */
@Data
public class DcsDetectAlarmDataBO extends FirmBaseDataBO{
    @ApiModelProperty(value = "当前值",example = "当前值")
    private Object value;

    @ApiModelProperty(value = "报警类型",example = "报警类型")
    private String alarmType;

    @ApiModelProperty(value = "当前报警/消警阈值",example = "当前报警/消警阈值")
    private String threshold;

    @ApiModelProperty(value = "报警时间戳YYYYMMDDHHmmss",example = "报警时间戳YYYYMMDDHHmmss")
    private String alarmTime;

    @ApiModelProperty(value ="quotaId",example = "quotaId")
    private String quotaId;

    public void setQuotaId(String quotaId) {
        if(quotaId == null || "".equals(quotaId)){
            throw new RuntimeException("quotaId不能为空");
        }
        this.quotaId = quotaId;
    }

    public void setValue(Object value) {
        if(value == null || "".equals(value)){
            throw new RuntimeException("value不能为空");
        }
        this.value = value;
    }

    public void setvalue(Object value) {
        if(value == null || "".equals(value)){
            throw new RuntimeException("value不能为空");
        }
        Boolean aBoolean = value instanceof Boolean ? ((Boolean) value) : null;
        String s = value instanceof String ? (String) value : null;
        Double d = value instanceof Double ? (Double) value : null;
        Integer integer = value instanceof Integer ? (Integer) value : null;
        System.out.println("11111111111111111111111111");
        this.value = value;
    }

    public void setAlarmType(String alarmType) {
        if(alarmType == null || "".equals(alarmType)){
            throw new RuntimeException("alarmType不能为空");
        }
        this.alarmType = alarmType;
    }

    public void setThreshold(String threshold) {
        if(threshold == null || "".equals(threshold)){
            throw new RuntimeException("threshold不能为空");
        }
        this.threshold = threshold;
    }

    public void setAlarmTime(String alarmTime) {
        if(alarmTime == null || "".equals(alarmTime)){
            throw new RuntimeException("alarmTime不能为空");
        }
        this.alarmTime = alarmTime;
    }
}

fastJson对对象进行操作时,调用的get、set方法

fasetJson转对象时同样要调用get、set方法,但是调用的get、set方法,对象字段首字母小写  例如 getspeed()、setspeed(),(且使用fastjson转对象后,字段都是首字母小写,需要加@jsonFiled)而不是getSpeed()、setSpeed()。

https://www.cnblogs.com/wq-9/p/14140771.html

11111

posted @ 2021-04-25 11:44  wq9  阅读(321)  评论(0编辑  收藏  举报