0
点赞
收藏
分享

微信扫一扫

SpringBoot中使用常量类来判断对象某属性的值是否包含在指定集合中


场景

在业务场景中需要判断某对象类的属性值是否是指定的集中。

为了使用方便,可以指定的几种放在一个公共模块下的常量类。

注:

实现

首先在common路径下constant下新建Constants常量类

/**
* 通用常量信息
*
*/
public class Constants
{

/**
* 通用成功标识
*/
public static final String SUCCESS = "0";

/**
* 通用失败标识
*/
public static final String FAIL = "1";


/**
* 正常的考勤状态
*/
public static final List<String> KQZT_ZC = new ArrayList<String>() {
{
this.add("正常上班");
this.add("加班");
this.add("补班");
}
};
}

然后在需要用到的地方

if(kqsjTian.getKqzt()!=null && Constants.KQZT_ZC.contains(kqsjTian.getKqzt()))
{
kqrs++;
}

调用Constans的实体判断是否包含着对象的属性值。

举报

相关推荐

0 条评论