判断字符串是否为空
if (work.getSfdycdy()!=null && !"".equals(work.getSfdycdy())) {
}
截取前端传来的带,的字符串
String[] idss = work.getSfdycdy().split(",");
将字符串转换为int类型
Integer.parseInt(idss)
在java中对LIst集合的两种排序方法
Collections.sort(List);
Collections.sort(List,Commparator);
获取list中的最小值,最大值
String min\max = Collections.min\.max(list);
decimal的加减算法
BigDecimal bignum2 = new BigDecimal("5");
bignum3 = bignum1.add(bignum2);
bignum3 = bignum1.subtract(bignum2);
bignum3 = bignum1.multiply(bignum2);
bignum3 = bignum1.divide(bignum2);
BigDecimal运算
.divide(new BigDecimal(2),2,RoundingMode.HALF_UP)
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");
}
使用json格式接收前台传来的一个参数
String schoolId = jsonObject.getString("schoolId");
把map放到list中
List values = list.values().stream().collect(Collectors.toList());
mysql中时间转换为yyyy-mm-dd形式进行模糊查询
add_time LIKE concat('%', DATE_FORMAT(#{user.addTime},'%Y-%m-%d'), '%')
java得到今天是星期几
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
String displayName = calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());
System.out.println(day);
System.out.println(displayName);
}
根据日期获取对应星期几
SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
String week = sdf.format(paDuty.getCreateTime());
EEEE代表星期
获取一个集合中一个字段相同的值分别有多少个
Map<Object,List<EduPreTargetExcelDTO>> map = list.stream().collect(Collectors.groupingBy(m->m.getEetTarget()));
Map<Object,List<EduPreTargetExcelDTO>> map2 = list.stream().filter(m->m.getEetTwoTarget()!=null).collect(Collectors.groupingBy(m->m.getEetTwoTarget()));
Java8中将list转换为用逗号隔开的字符串
String result = list.stream().map(String::valueOf).collect(Collectors.joining(","));
获取指定日期的年份
Calendar cal = Calendar.getInstance();
cal.setTime(annualMonitoring.getCreateTime());
int year = cal.get(Calendar.YEAR);
mybatis中#会自动加双引号,$不会加双引号
判断奇偶数
(num%2==0)?"偶数":"奇数"
复制一个实体内容到另一个实体,自动匹配拥有的字段
BeanUtils.copyProperties(a,b,c);