判斷一個元素是否存在:(要判斷的那個數若是包含在Status(通過或運算得出來的值)中通過與運算隻能得到自己的值)
/**
* 擷取産品
*
* @param
* @return
*/
@Override
public List<Product> getProduct(Long appUserId) {
List<Product> list = productMapper.getProduct(appUserId);
if (list != null && list.size() > 0) {
for (Product product : list) {
if (!StringUtils.isEmpty(product.getIouProductLogoUrl())) {
product.setIouProductLogoUrl(OSSUtil.imgUrl + product.getIouProductLogoUrl());
}
//拼接年化率
BigDecimal rate = product.getInterestRateAnnual().multiply(BigDecimal.valueOf(100));
product.setAnnualRate(rate.intValue() + "%");
//解析所需材料項數
Integer item = product.getMaterialItems();
String[] arrT = new String[4];
for (int i = 0; i < 4; i++) {
if ((item & 1) == 1) {
arrT[0] = "身份證";
}
if ((item & 2) == 2) {
arrT[1] = "銀行卡";
}
if ((item & 4) == 4) {
arrT[2] = "營運商";
}
if ((item & 8) == 8) {
arrT[8] = "芝麻信用";
}
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arrT.length; i++) {
if (arrT[i] == null)
continue;
sb.append(arrT[i] + " ");
}
String s = sb.toString();
product.setMaterialItemsStr(s);
}
}
logger.debug("擷取産品:{}", list);
return list;
}
關于位運算相關知識