常用工具代码

修改密码
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))

时间格式互转
1Date -> LocalDateTime
		public static LocalDateTime dateToLocalDateTime(Date date) {
				Instant instant = date.toInstant();
				ZoneId zone = ZoneId.systemDefault();
		return LocalDateTime.ofInstant(instant, zone);
		}

2Date -> LocalDate
	public static LocalDate dateToLocalDate(Date date) {
		LocalDateTime localDateTime = dateToLocalDateTime(date);
		return localDateTime.toLocalDate();
	}

3Date -> LocalTime
	public static LocalTime dateToLocalTime(Date date) {
		LocalDateTime localDateTime = dateToLocalDateTime(date);
		return localDateTime.toLocalTime();
	}

4LocalDateTime -> Date
	public static Date localDateTimeToDate(LocalDateTime localDateTime) {
		ZoneId zone = ZoneId.systemDefault();
		Instant instant = localDateTime.atZone(zone).toInstant();
		return Date.from(instant);
	}

5LocalDate -> Date
	public static Date localDateToDate(LocalDate localDate) {
		ZoneId zone = ZoneId.systemDefault();
		Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
		return Date.from(instant);
	}

6LocalTime -> 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))
        );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值