开发中遇到的问题

开发中遇到的问题

一.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

未完待续...

相关推荐
xiaoye37085 小时前
Java 自动装箱 / 拆箱 原理详解
java·开发语言
YDS8296 小时前
黑马点评 —— 分布式锁详解加源码剖析
java·spring boot·redis·分布式
武藤一雄6 小时前
从零构建C# OOP 知识体系
windows·microsoft·c#·.net·.netcore·oop
迷藏4946 小时前
**发散创新:基于 Rust的开源权限管理系统设计与实战**在现代软件架构中,**权限控制**早已不
java·开发语言·rust·开源
升鲜宝供应链及收银系统源代码服务7 小时前
《IntelliJ + Claude Code + Gemini + ChatGPT 实战配置手册升鲜宝》
java·前端·数据库·chatgpt·供应链系统·生鲜配送
daidaidaiyu7 小时前
Nacos实例一则及其源码环境搭建
java·spring
小江的记录本7 小时前
【Redis】Redis全方位知识体系(附《Redis常用命令速查表(完整版)》)
java·数据库·redis·后端·python·spring·缓存
摇滚侠7 小时前
Java 项目《谷粒商城-1》架构师级Java 项目实战,对标阿里 P6-P7,全网最强,实操版本
java·开发语言
zihao_tom8 小时前
Spring Boot(快速上手)
java·spring boot·后端
hua872228 小时前
SpringSecurity之跨域
java