开发中遇到的问题

一.Mybatis

1.链式SQL嵌套and,or

 List<UserMeetDO> meets = userMeetMapper.selectList(new LambdaQueryWrapper<UserMeetDO>()
                        .eq(UserMeetDO::getMeetId, userMeetVo.getMeetId())
                        .and(wrapper -> wrapper
                                .and(w -> w.le(UserMeetDO::getStartTime, userMeetVo.getStartTime()).gt(UserMeetDO::getEndTime, userMeetVo.getStartTime()))
                                .or(w -> w.lt(UserMeetDO::getStartTime, userMeetVo.getEndTime()).ge(UserMeetDO::getEndTime, userMeetVo.getEndTime()))
                                .or(w -> w.ge(UserMeetDO::getStartTime,  userMeetVo.getStartTime()).le(UserMeetDO::getEndTime, userMeetVo.getEndTime()))
                        )
                );

2.updateById()

问题:原本不为null的字段更新为null导致更新失败

warnFieldService.update(po, new UpdateWrapper<WarnField>().lambda()
//                .set(StringUtils.isEmpty(po.getName()), WarnField::getName, null)
                .set(!StringUtils.isEmpty(po.getName()), WarnField::getName, po.getName())
                .set(!StringUtils.isEmpty(po.getField()), WarnField::getField,po.getField()) // Assuming there's another field to update
//                .set(StringUtils.isEmpty(po.getField()), WarnField::getField,null) // Assuming there's another field to update
                .eq(WarnField::getId, po.getId()));

3.xml

在xml中mybatis里认为0就是空字符串

if和foreach

 	 <if test="deptIds != null">
            and (
            sl.dept_id in
            <foreach collection="deptIds" open="(" close=")" separator="," item="id">
                #{id}
            </foreach>
            or sl.owner_id in
            <foreach collection="deptIds" open="(" close=")" separator="," item="id">
                #{id}
            </foreach>
            )
        </if>

3.分页

中规中矩

 Page<Object> iPage = PageHelper.startPage(page, size);
 return PageResult.of(iPage,list);

手动分页

 public List<PlanReceiveBo> getPage(List<PlanReceiveBo> list, int pageNum, int pageSize) {
        List<PlanReceiveBo> result = new ArrayList<>();
        if (list == null || list.isEmpty()) {
            return result;
        }
        int totalSize = list.size();
        int totalPage = (totalSize + pageSize - 1) / pageSize;
        if (pageNum < 1 || pageNum > totalPage) {
            return result;
        }
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, totalSize);
        for (int i = startIndex; i < endIndex; i++) {
            result.add(list.get(i));
        }
        return result;
    }

二.SpringBoot

1.定时任务

@Scheduled(cron = “0 0 2 * * ?”)
5位:* * * * * 分、时、天、月、周
6位:* * * * * * 秒、分、时、天、月、周
7位:* * * * * * * 秒、分、时、天、月、周、年

2.注解

@Value(“${sms.open}”)

三.Java

1.常用的流

  BigDecimal totalAmount = list.stream()
        .map(e -> e.getPlanReceiveAmount())
        .reduce(BigDecimal.ZERO, BigDecimal::add);

2.时间格式转换

LocalDate->LocalDateTime

param.setApplyStartTime(listParam.getStartTime().atStartOfDay());
param.setApplyEndTime(listParam.getEndTime().atTime(23,59,59));

LocalDateTime->LocalDate

LocalDateTime dateTime = LocalDateTime.of(2023, 11, 17, 10, 30);
LocalDate date = dateTime.toLocalDate();
System.out.println(date); // 输出 2023-11-17

3.JSON问题

如果为空就不返回该字段

@JsonInclude(JsonInclude.Include.NON_EMPTY)

返回日期格式化

 @JsonFormat(pattern = "yyyy-MM-dd")		  controller -> 前端		
    private Date sampleDate;

字符太短接收不到问题

	 @JsonProperty("sId")
    private String sId;

JSON的相互转换

String jsonString = "{\"name\":\"name\", \"age\":20}";
SomeObject someObject = JSON.parseObject(jsonString, SomeObject.class);
SomeObject someObject = new SomeObject("name", 20);
String jsonString = JSON.toJSONString(someObject, SerializerFeature.PrettyFormat);
		
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray attributesArray = jsonObject.getJSONArray("attributes");
JSONObject attributes1 = attributesArray.getJSONObject(0);
String country = attributes1.getString("country");

四.Windows

1.杀死端口

netstat -ano | findstr 8080
taskkill /F /PID 39908

五.Linux

1.常用命令

文件大小前10的

find /home/sdb/directory -type f -exec du -h {} + | sort -rh | head -n 10

挂起

 nohup java -jar wx-auto-article-0.0.1-SNAPSHOT.jar > output.log 2>&1&

2.快捷键

/ 查找时

查找下一个匹配项:按下 n,vim 会跳转到下一个匹配项。
查找上一个匹配项:按下 N,vim 会跳转到上一个匹配项。

未完待续…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值