开发中遇到的问题

开发中遇到的问题

一.Mybatis

1.链式SQL嵌套and,or

java 复制代码
 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.xml

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

if和foreach

xml 复制代码
 	 <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.分页

中规中矩

java 复制代码
 Page<Object> iPage = PageHelper.startPage(page, size);
 return PageResult.of(iPage,list);

手动分页

java 复制代码
 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位:* * * * * * * 秒、分、时、天、月、周、年

三.Java

1.常用的流

java 复制代码
  BigDecimal totalAmount = list.stream()
        .map(e -> e.getPlanReceiveAmount())
        .reduce(BigDecimal.ZERO, BigDecimal::add);

2.时间格式转换

LocalDate->LocalDateTime

java 复制代码
param.setApplyStartTime(listParam.getStartTime().atStartOfDay());
param.setApplyEndTime(listParam.getEndTime().atTime(23,59,59));

LocalDateTime->LocalDate

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

3.JSON问题

如果为空就不返回该字段

java 复制代码
@JsonInclude(JsonInclude.Include.NON_EMPTY)

JSON的相互转换

java 复制代码
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);
java 复制代码
		
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray attributesArray = jsonObject.getJSONArray("attributes");
JSONObject attributes1 = attributesArray.getJSONObject(0);
String country = attributes1.getString("country");

四.Windows

1.杀死端口

bash 复制代码
netstat --ano | findstr <端口号>
bash 复制代码
taskkill /F /PID 39908

未完待续...

相关推荐
深栈解码12 分钟前
JMM深度解析(三) volatile实现机制详解
java·后端
编程乐趣23 分钟前
自学C#,要懂得用好对象浏览器
windows·.net
liujing1023292924 分钟前
Day04_刷题niuke20250703
java·开发语言·算法
Brookty27 分钟前
【MySQL】JDBC编程
java·数据库·后端·学习·mysql·jdbc
能工智人小辰41 分钟前
二刷 苍穹外卖day10(含bug修改)
java·开发语言
DKPT41 分钟前
Java设计模式之结构型模式(外观模式)介绍与说明
java·开发语言·笔记·学习·设计模式
缘来是庄44 分钟前
设计模式之外观模式
java·设计模式·外观模式
qq_393828221 小时前
办公文档批量打印器 Word、PPT、Excel、PDF、图片和文本,它都支持批量打印。
windows·word·powerpoint·excel·软件需求
好名字更能让你们记住我1 小时前
Linux多线程(十二)之【生产者消费者模型】
linux·运维·服务器·jvm·windows·centos
单线程的Daniel1 小时前
Dubbo RPC 序列化问题记录
windows·rpc·dubbo