1. 查询两个LocalDate类型之间的所有日(周,月)
废弃版本(实际用的时候,发现少了一周):
long distance = ChronoUnit.WEEKS.between(startDateLocal, endDateLocal);
List<LocalDate> dateList = LongStream.range(0, distance)
.mapToObj(startDateLocal::plusWeeks)//映射
.collect(Collectors.toList());//收集
最新版本:
List<LocalDate> dateList = Lists.new ArrayList<>();
long distance = ChronoUnit.WEEKS.between(startDateLocal, endDateLocal);
if (distance >= 1) {
dateList = Stream.iterate(startDateLocal, d -> d.plusWeeks(1)).limit(distance + 1).collect(Collectors.toList());
}
2. Date类型转LocalDate
LocalDate startDateLocal = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
3. 字符串(单个或多个)转List
List<String> list = Arrays.asList("aaa","bbb");
4. 用mysql查询笛卡尔积
select * from
(select a.c1,a.c2,a.c3 from a) e
CROSS JOIN
(select b.d1,b.d2,b.d3 from b) f
5. mysql使用case…when
select
case a.a1 when '0' then '就是0'
else '就是1' end
from a
6. mysql根据查询的数据insert
INSERT INTO table_a(`id`,`name`,`code`) SELECT `id`,`name`,`code` FROM table_b;
INSERT INTO table_a SELECT * FROM table_b;
7. mysql命令行
mysql -uroot -p -h127.00.0.1 -P3306;
show databases;
create database d1;
use d1;
8. mysql修改表字段名/类型/默认值/备注
ALTER TABLE table_a CHANGE name name_code varchar(30) DEFAULT NULL COMMENT '名称';