编辑
2023-07-11
遇到的问题
00

前提

这是因为mybatis默认开启驼峰命名法,按规则数据表中的lastName字段应对应实体类中的last_name属性,而实体类中的lastName属性应对应数据表中的last_name字段。

解决方式1

在application.yml中,关闭驼峰转换,可能会出现问题,影响以前的实体查不到内容

yml
mybatis-plus.configuration.map-underscore-to-camel-case=false

解决方式2

局部解决,写个将驼峰转回下划线命名方式的接口,优点不影响全局配置

java
public String camelToUnderline(String camelCase) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < camelCase.length(); i++) { char c = camelCase.charAt(i); if (Character.isUpperCase(c)) { if (i != 0) { sb.append("_"); } sb.append(Character.toLowerCase(c)); } else { sb.append(c); } } if (sb.charAt(sb.length() - 1) == '_') { sb.deleteCharAt(sb.length() - 1); } return sb.toString().toUpperCase(); }
编辑
2023-07-09
前端
00

原因

问题描述:

报错:Error: error:0308010C

envelope routines::unsupported

报错原因:

因为 node.js V17版本中最近发布的OpenSSL3.0, 而OpenSSL3.0对允许算法和密钥大小增加了严格的限制

解决方法

  1. 卸载该nodejs,安装nodejs17以下版本
  2. idea终端输入 set NODE_OPTIONS=--openssl-legacy-provider
编辑
2023-07-08
学习记录
00

前提

由于业务需要返回一个树形结构,并且实现搜索功能,搜索子类时要显示父类信息

代码实现

请求

java
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel(value = "获取查询条件请求") public class SearchConditionRequest { @ApiModelProperty(value = "查询条件名称") private String text; }

实现

java
@ApiOperation(value = "获取查询条件树形列表") @PostMapping("getSearchConditionListTree") public Result<List<SearchConditionEntity>> getRecSearchConditionListTree(@RequestBody SearchConditionRequest request) { List<SearchConditionEntity> list = iSearchConditionService.selectSearchConditionList(request); List<SearchConditionEntity> SearchConditionEntityListTree = new ArrayList<>(); //第一步获取顶层节点 List<RecSearchConditionEntity> top = list.stream() .filter(pa -> "0".equals(pa.getParentId()) || pa.getParentId()==null).collect(Collectors.toList()); if (top != null && top.size() > 0) { top.forEach(p -> { searchConditionEntity searchConditionEntity = p; this.getChildrenList(list, searchConditionEntity); searchConditionEntityListTree.add(SearchConditionEntity); }); return Result.success(SearchConditionEntityListTree); } return Result.fail("500", "没有结果"); } private void getChildrenList(List<SearchConditionEntity> list, SearchConditionEntity parent) { List<searchConditionEntity> children = list.stream() .filter(pa -> parent.getId().equals(pa.getParentId())).collect(Collectors.toList()); if (children != null && children.size() > 0) { children.forEach(p -> { this.getChildrenList(list, p); }); parent.setChildren(children); } return; }

使用递归的方式,给树形添加上下级

编辑
2023-07-07
遇到的问题
00

前因

后端接受前端的时间是yyyy-mm-ss格式,但是使用mybatis查询这个时间的时候,会变成yyyy-MM-ss 08:00:00, 自动加上八小时,不是我想要的0时,就导致查询的时候出现了很多错误数据

解决方式

接受时间的实体,需要加上JsonFormat 注解

java
@ApiModelProperty(value="出院时间开始") @NotNull(message = "出院开始时间不能为空") @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date dischargeTimeBegin; @ApiModelProperty(value="出院时间截止") @NotNull(message = "出院截止时间不能为空") @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") private Date dischargeTimeEnd;

因为jsonformat是对json格式有效,会格式化返回值,他和@DateTimeFormat注解是相辅相成的,具体可以看我的这篇文章

编辑
2023-07-07
实用工具
00

DateUtil

java
package com.lhw.utils; import com.lhw.common.ResultCodeEnum; import com.lhw.exception.BusinessException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; public class DateUtils { /** * 字符串转换为java.util.Date<br> * 支持格式为 yyyy.MM.dd G 'at' hh:mm:ss z 如 '2017-12-12 AD at 22:10:59 PSD'<br> * yy/MM/dd HH:mm:ss 如 '2017/12/12 17:55:00'<br> * yy/MM/dd HH:mm:ss pm 如 '2017/12/12 17:55:00 pm'<br> * yy-MM-dd HH:mm:ss 如 '2017-12-12 17:55:00' <br> * yy-MM-dd HH:mm:ss am 如 '2017-12-12 17:55:00 am' <br> * @param time String 字符串<br> * @return Date 日期<br> */ public static Date stringToDate(String time){ SimpleDateFormat formatter =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { int len = time.length(); time=time.replace(":","") .replace("-","") .replace("/","") .replace(" ",""); ArrayList<String> formatterList=new ArrayList<>(); formatterList.add("yyyyMMdd"); formatterList.add("yyyyMMddHHmm"); formatterList.add("yyyyMMddHHmm"); formatterList.add("yyyyMMddHHmmss"); for (String strFormatter:formatterList ) { if(strFormatter.length()==time.length()) formatter=new SimpleDateFormat(strFormatter); } return formatter.parse(time); } catch (Exception e) { throw new BusinessException(ResultCodeEnum.ERR_0x1000.getCode(), e.getMessage()); } } public static boolean afterDate(Date d1, Date d2) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { String strFirstDate = dateFormat.format(d1); d1 = dateFormat.parse(strFirstDate); String strSecondDate = dateFormat.format(d2); d2 = dateFormat.parse(strSecondDate); } catch (Exception e) { // 日期型字符串格式错误 throw new BusinessException(ResultCodeEnum.ERR_0x1000.getCode(), "日期型字符串格式错误。"+e.getMessage()); } int betweenDays = 0; Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); if(c1.after(c2)){ return true; }else return false; } public static boolean beforeDate(Date d1, Date d2) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { String strFirstDate = dateFormat.format(d1); d1 = dateFormat.parse(strFirstDate); String strSecondDate = dateFormat.format(d2); d2 = dateFormat.parse(strSecondDate); } catch (Exception e) { // 日期型字符串格式错误 throw new BusinessException(ResultCodeEnum.ERR_0x1000.getCode(), "日期型字符串格式错误。"+e.getMessage()); } int betweenDays = 0; Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); if(c1.before(c2)){ return true; } else return false; } public static int getBetweenDays(Date d1, Date d2) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { String strFirstDate = dateFormat.format(d1); d1 = dateFormat.parse(strFirstDate); String strSecondDate = dateFormat.format(d2); d2 = dateFormat.parse(strSecondDate); } catch (Exception e) { // 日期型字符串格式错误 throw new BusinessException(ResultCodeEnum.ERR_0x1000.getCode(), "日期型字符串格式错误。"+e.getMessage()); } int betweenDays = 0; Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); // 保证第二个时间一定大于第一个时间 if(c1.after(c2)){ c1.setTime(d2); c2.setTime(d1); } int betweenYears = c2.get(Calendar.YEAR)-c1.get(Calendar.YEAR); betweenDays = c2.get(Calendar.DAY_OF_YEAR)-c1.get(Calendar.DAY_OF_YEAR); for(int i=0;i<betweenYears;i++){ int tmp=countDays(c1.get(Calendar.YEAR)); betweenDays+=countDays(c1.get(Calendar.YEAR)); c1.set(Calendar.YEAR,(c1.get(Calendar.YEAR)+1)); } return betweenDays; } public static int countDays(int year){ int n=0; for (int i = 1; i <= 12; i++) { n += countDays(i,year); } return n; } public static int countDays(int month, int year){ int count = -1; switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: count = 31; break; case 4: case 6: case 9: case 11: count = 30; break; case 2: if(year % 4 == 0) count = 29; else count = 28; if((year % 100 ==0) & (year % 400 != 0)) count = 28; } return count; } /** * * @Description: 将日期转换为字符串 * @author yehui * @version 2016年12月27日 下午1:19:15 * @param date * @param format * 转化格式,如:yyyy-MM-dd HH:mm:ss * @return * */ public static String formatDateToString(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); String str = sdf.format(date); return str; } public static Date addDays(Date date,int days){ Calendar calendar=Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_YEAR,days); return calendar.getTime(); } }