修改密码
alter user 'root'@'%' identified with mysql_native_password by '你的密码';
flush privileges;
bigDecimal运算保留小数
BigDecimal.valueOf(complate).divide(BigDecimal.valueOf(all),4,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))
时间格式互转
1、Date -> LocalDateTime
public static LocalDateTime dateToLocalDateTime(Date date) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
2、Date -> LocalDate
public static LocalDate dateToLocalDate(Date date) {
LocalDateTime localDateTime = dateToLocalDateTime(date);
return localDateTime.toLocalDate();
}
3、Date -> LocalTime
public static LocalTime dateToLocalTime(Date date) {
LocalDateTime localDateTime = dateToLocalDateTime(date);
return localDateTime.toLocalTime();
}
4、LocalDateTime -> Date
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
5、LocalDate -> Date
public static Date localDateToDate(LocalDate localDate) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);
}
6、LocalTime -> Date
public static Date localTimeToDate(LocalTime localTime) {
LocalDate localDate = LocalDate.now();
ZoneId zone = ZoneId.systemDefault();
Instant instant = LocalDateTime.of(localDate, localTime).atZone(zone).toInstant();
return Date.from(instant);
}
动态SQl
涉及内容:
子查询,分表查询,集合查询 in ( 集合)
<select id="selectAgeCount" resultType="com.wewin.modules2.sys.vo.UnitStatisticsVo">
select
sum(allot.material_ship_num) as materialShipNum
from (
SELECT
sum(material_ship_num) as material_ship_num
FROM
temporary_detail
where create_time between #{start} and #{end}
<if test="ids != null and ids.size() > 0 ">
and temporary_site_id in
<foreach
collection="ids"
item="id"
open="("
separator=","
close=")">
#{id}
</foreach>
</if>
<if test="historyTableName!=null and historyTableName.size!=0 ">
<foreach collection="historyTableName" item="name">
UNION
SELECT
sum(material_ship_num) as material_ship_num
FROM
${name}
where create_time between #{start} and #{end}
<if test="ids != null and ids.size() > 0 ">
and temporary_site_id in
<foreach
collection="ids"
item="id"
open="("
separator=","
close=")">
#{id}
</foreach>
</if>
</foreach>
</if>
) allot
</select>
行行比较:同时比较两个字段满足条件的情况
<if test="users != null and users.size() > 0 ">
and (consignee,contact_tel_no) in (
<foreach
collection="users"
item="user"
separator=",">
(#{user.name},#{user.mobile})
</foreach>
)
</if>
mybatis 高级写法
sysOutboundNoticeDetailService.update(new LambdaUpdateWrapper<SysOutboundNoticeDetailEntity>()
.eq(SysOutboundNoticeDetailEntity::getOutboundId,outboundId)
.set(SysOutboundNoticeDetailEntity::getCheckTime,null)
.set(SysOutboundNoticeDetailEntity::getCheckUser,null)
.setSql("picked_quantity = onl_notice_qty")
);
Java Stream 分组求和
Map<String, BigDecimal> map = list.stream().collect(
Collectors.groupingBy(e -> e.getMisMatCode() + "#" + e.getMisMatName() + "#" + e.getProjectCode() + "#" + e.getOnlTargetProjectName()
,Collectors.reducing(BigDecimal.ZERO,InvoiceDetailsVo::getMaterialShipNum,BigDecimal::add))
);