Skip to content

Commit

Permalink
* 转换判空避免前端传递空串导致NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorrt-2021 authored and Air-Cooled committed Mar 27, 2023
1 parent c7b7aa8 commit 04c0425
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.diboot.core.converter;

import com.diboot.core.util.D;
import com.diboot.core.util.V;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
Expand All @@ -31,6 +32,9 @@ public class String2LocalDateConverter implements Converter<String, LocalDate> {

@Override
public LocalDate convert(String dateString) {
if(V.isEmpty(dateString)){
return null;
}
dateString = D.formatDateString(dateString);
return LocalDate.parse(dateString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.diboot.core.converter;

import com.diboot.core.util.D;
import com.diboot.core.util.V;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
Expand All @@ -33,6 +34,9 @@ public class String2LocalDateTimeConverter implements Converter<String, LocalDat

@Override
public LocalDateTime convert(String dateString) {
if(V.isEmpty(dateString)){
return null;
}
dateString = D.formatDateString(dateString);
if(dateString.length() <= D.FORMAT_DATE_Y4MD.length()) {
return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(D.FORMAT_DATE_Y4MD)).atStartOfDay();
Expand Down

0 comments on commit 04c0425

Please sign in to comment.