mybatis-plus:
global-config:
db-config:
logic-delete-value: N # 逻辑已删除值
logic-not-delete-value: Y # 逻辑未删除值
1、判断大量的数据中是否存在某个字符串时,用HashSet set 中的contains()方法
执行效率是最高的。
2、当进行对map集合进行循环遍历时,Iterator iter = map.entrySet().iterator()
while(iter.hasNext())
{
Map.entry entry = (Map.Entry)iter.next();
String key = (String) entry.getKey();
String val = (String) entry.getValue();
}
遍历map中的键
for (Integer key : map.keySet()) {
System.out.println(“Key = “ + key);
}
遍历map中的值
for (Integer value : map.values()) {
System.out.println(“Value = “ + value);
}
3、将List中的某个字段拼接成非空的字符串:String createdBys = surveyWorkBenchQueryRespList.stream().map(SurveyWorkBenchQueryResp::getCreatedBy).collect(Collectors.joining(“,”));
// 带单引号
String opinionTypes = opinionList.stream().map(OaCommonOpinionDTO::getOpinionTypeCode).map(s->”\’” + s + “\’”).collect(Collectors.joining(“,”));
4、将List某些属性值转换成Map集合:Map
5、将List中的某些属性值转换成带有Long和对象的Map集合:Map
.collect(Collectors.toMap(SuHeaderResponse::getSuHeaderId, Function.identity(), (v1, v2) -> v1));
6、将List中某些属性值加起来:Integer sumSbomQty = sboms.stream().mapToInt(o -> o.getSuQty() * o.getSbomQty()).sum();
7、将List中某些属性转换成Set:Set
8、将List中按照某个属性进行分组:Map
9、将List中的多个属性拼接进行分组
Map
10、 加法
BigDecimal result1 = num1.add(num2);
BigDecimal result12 = num12.add(num22);
11、减法
BigDecimal result2 = num1.subtract(num2);
BigDecimal result22 = num12.subtract(num22);
12、乘法
BigDecimal result3 = num1.multiply(num2);
BigDecimal result32 = num12.multiply(num22);
13、绝对值
BigDecimal result4 = num3.abs();
BigDecimal result42 = num32.abs();
14、除法
BigDecimal result5 = num2.divide(num1,20,BigDecimal.ROUND_HALF_UP);
BigDecimal result52 = num22.divide(num12,20,BigDecimal.ROUND_HALF_UP);
15、BigDecimal 比较大小
// 前提为a、b均不能为null
If (a.compareTo(b) == -1) {
System.out.println(“a小于b”);
}
If (a.compareTo(b) == 0) {
System.out.println(“a等于b”);
}
If (a.compareTo(b) == 1) {
System.out.println(“a大于b”);
}
if(a.compareTo(b) > -1){
System.out.println(“a大于等于b”);
}
if(a.compareTo(b) < 1){
System.out.println(“a小于等于b”);
}
16、多个字符串拼接
Joiner.on(“-“).skipNulls().join(this.siteAddress, this.secondLevel, this.thirdLevel, this.fourthLevel, this.fiveLevel);
17、过滤重复元素
List productConfigIdList = productConfigList.stream().map(
ConConfig :: getParentConfigId).distinct().collect(Collectors.toList());
18、从集合中过滤出来符合条件元素
List filterList = appleList.stream().filter(a -> a.getName().equals(“香蕉”)).collect(Collectors.toList());
19、注解处理日期
@JSONField(format = “yyyy-MM-dd”)
Private Date createdDate;
20、SQL处理查询一张表中某个属性值出现的次数
SELECT material.suheader_id,count() from cpqdsu_core_db.su_material material WHERE material.layer = 5 AND material.enabled_flag = ‘Y’ GROUP BY material.su_header_id HAVING COUNT() = 1;
21、+、、|、\等符号在正则表达示中有相应的不同意义,所以在使用时要进行转义处理。
String strs[]=str.split(“\“);
22、Set集合交集
result.retainAll(set2);
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = {“createdBy”, “creationDate”, “lastUpdatedBy”, “lastUpdateDate”, “enabledFlag”})
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 创建人
*/
@TableField(value = "created_by", fill = FieldFill.INSERT)
protected String createdBy;
/**
* 创建时间,创建时采用数据默认值,不进行自动填充
*/
protected Date creationDate;
/**
* 最后修改人
*/
@TableField(value = "last_updated_by", fill = FieldFill.INSERT_UPDATE)
protected String lastUpdatedBy;
/**
* 最后更新时间,创建时采用数据默认值,不进行自动填充
*/
@TableField(value = "last_update_date", fill = FieldFill.UPDATE, update = "now()")
protected Date lastUpdateDate;
/**
* 有效性(Y/N),该字段必须放最后,不然逻辑删除不起作用
*/
@TableField(value = "enabled_flag", fill = FieldFill.INSERT)
@TableLogic(value = "Y", delval = "N")
protected String enabledFlag;
}