当前位置: 首页 > article >正文

开发中遇到的问题

开发中遇到的问题

    • 一.Mybatis
      • 1.链式SQL嵌套and,or
      • 2.xml
      • 3.分页
    • 二.SpringBoot
      • 1.定时任务
    • 三.Java
      • 1.常用的流
      • 2.时间格式转换
      • 3.JSON问题
    • 四.Windows
      • 1.杀死端口
    • 未完待续......

一.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.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位:* * * * * * * 秒、分、时、天、月、周、年

三.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)

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 <端口号>
taskkill /F /PID 39908

未完待续…


http://www.kler.cn/news/134674.html

相关文章:

  • HarmonyOS开发(四):应用程序入口UIAbility
  • 小米手环8pro重新和手机配对解决办法
  • java: 无法访问org.mybatis.spring.annotation.MapperScan
  • 智能货柜:无人零售行业的新宠
  • JDBC编程
  • 阿里云CentOS主机开启ipv6
  • Windows10下Maven3.9.5安装教程
  • 代码逻辑修复与其他爬虫ip库的应用
  • 探索SPI:深入理解原理、源码与应用场景
  • 【Matterport3D模拟器安装详细教程】适用于离散视觉语言导航任务的环境部署与安装
  • python django 小程序博客源码
  • 如何保护PayPal账户安全:防止多个PayPal账号关联?
  • 【服务器学习】hook模块
  • SIMULIA|Abaqus 2022x新功能介绍第三弹
  • 【面试经典150 | 数学】回文数
  • 计算机毕业设计选题推荐-个人博客微信小程序/安卓APP-项目实战
  • 硬盘无法格式化怎么办?
  • ModStartCMS v7.6.0 CMS备份恢复优化,主题开发文档更新
  • ESP32 Arduino实战协议篇-搭建独立的 Web 服务器
  • APP源码|智慧校园电子班牌源码 智慧校园云平台
  • Elasticsearch备份与还原:使用elasticdump
  • C#入门(5):数组、一维数组,二维数组、交错数组、数组复制
  • 数据资产入表,给企业带来的机遇和挑战
  • 02-1解析xpath
  • String的字符串拼接
  • 通付盾Web3专题 | KYT/AML:Web3合规展业的必要条件
  • 蓝桥杯 vector
  • nvm 安装后出现的各种问题解决方法
  • Redis 学习
  • linux 安装中文字体