List与字符串转换

时间:2020-12-20 15:29:18
1.将list元素用单引号引起来:
List<TransferFocusxfSummaryTop3> topList = getTransferFocusxfSummaryTop3(userId);
List<String> otherSidelist=new ArrayList<String>(); for(int i=0;i<topList.size();i++){
otherSidelist.add("'"+topList.get(i).getOtherSide()+"'");
} 2.将list转化为mysql中集合查询条件in ():
("+String.join(",",otherSidelist)+")

3.mysql最近三个月数据:
t.tradetime>=DATE_SUB(now(), INTERVAL 3 MONTH)

4.BigDecimal数据类型除法并转换为百分比:
getFormatNum(amountTop3.divide(totalAmount, RoundingMode.HALF_UP).toPlainString()
百分比:
private String getFormatNum(String n) {
NumberFormat num = NumberFormat.getPercentInstance();
num.setMaximumFractionDigits(0);
return num.format(new BigDecimal(n));
}