Custom deserialization class converts LocalDate time format to LocalDateTime

Deserialize data received from the front end into classes. If the time format is inconsistent, deserialization may fail public class StorageDTO implements Serializable {<!– –> private static final long serialVersionUID = 1L; … //The format in the entity class is @JsonFormat(pattern = “yyyy-MM-dd”) @JsonDeserialize(using = CustomLocalDateTimeDeserializer.class) @ApiModelProperty(“Generation time”) private LocalDateTime generateTime; } //Customized deserialization class […]

Gson FastJson Jackson comes out Date LocalDate LocalDateTime date type JSON format string

Gson FastJson Jackson processes Date LocalDate LocalDateTime date type JSON format string Gson processes Date LocalDate LocalDateTime date type JSON format string When using the Gson library to serialize and deserialize objects whose properties are Date, LocalDate and LocalDateTime, You can use annotations to specify how dates are formatted. The Gson library supports the @SerializedName […]

Use Date and LocalDateTime to process dates in project development

Article directory Use Date and LocalDateTime to process dates in project development Date type validation Database table design (year, month and day) Entity class description Mapping file xml Response to presentation Precautions LocalDateTime validation Database Design Entity date type Dynamic SQL Date Type Response to presentation Summarize Use Date and LocalDateTime to process dates in […]

Mybatis-Plus reports errors when using java8 new date and time types such as LocalDateTime

Database JDBC version: GBase 8s JDBC V8.8 3.3.0_3 Mybatis-Plus version: 3.4.3.2 JDK version: jdk1.8.0_201 When the object type uses LocalDataTime, an error is reported: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=’et.updatetime’, mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId=’null’, jdbcTypeName=’null’, expression=’null’}. Cause: org.apache.ibatis.type.TypeException : Error setting non null for parameter #1 with […]

LocalDateTime tool class for obtaining various times

package com.xmcbs.jjcommon.util; import java.time.*; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; import java.util.Date; /** *@author:wangjp * @date: 2022/3/2 9:33 */ public class LocalDateTimeUtils {<!– –> /** * LocalDateTime to String * @param localDateTime * @param format * @return */ public static String format(LocalDateTime localDateTime,String format){<!– –> DateTimeFormatter df = DateTimeFormatter.ofPattern(format); return df.format(localDateTime); } /** * String […]

jdk8 localDateTime and localDate tool classes

1. Get the date a few months ago or a few months later public static LocalDate getMonthPast(LocalDate startDate, int month) {<!– –> LocalDate localDate = startDate.minusMonths(month); return LocalDate.from(localDate); } public static LocalDate getMonthDate(LocalDate startDate, int month) {<!– –> LocalDate localDate = startDate.plusMonths(month); return LocalDate.from(localDate); } 2. Calculate age /** * Calculate age in years * […]

Math class, BigInteger, BigDecimal, Date, Calendar, SimpleDateFormat, LocalDate, Period, Duration, System and Arrays class

Math class 1. Overview: ? Math tools 2.Features: ? a. Construct private ? b. Methods are all static 3.Use: ? Math. Directly call the class name 4.Math class method static int abs(int a) -> Find the absolute value of the parameter static double ceil(double a) -> round up static double floor(double a) -> round down […]

Java uses LocalDate to get the previous year, next year, last month, next month, previous day, today, this week, last week, this quarter, last quarter, etc. of the current time (time formatting)

Start time public static String min = ” 00:00:00″; End Time public static String max = ” 23:59:59″; public static void main(String[] args) throws Exception { //custom time System.out.println(“The beginning of the current day” + getStartOrEndDayOfDay(“2023-01-01”,0,true)); System.out.println(“The end of the current day” + getStartOrEndDayOfDay(“2023-01-01”,0,false)); System.out.println(“The start of the day before the current day” + getStartOrEndDayOfDay(“2023-01-01”,-1,true)); […]

Time class (5) [LocalDateTime]

5. LocalDateTime class java.time.LocalDateTime is an immutable datetime object that represents a datetime. public final class LocalDateTime implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable {<!– –> 1.Field Two instance fields are declared in the java.time.LocalDateTime class to store date and time: /** * The date part. */ private final LocalDate date; /** * The time part. */ […]

Spring Boot uses LocalDateTime and LocalDate as input parameters

0x0 background The LocalDateTime series is used in the project as the time type in dto, but spring always reports an error after receiving the parameters. In order to configure time type conversion globally, the following three methods were tried. Note: This article is based on the Springboot2.0 test. If it fails to take effect, […]