LocalDateTime有时接收不到
时间: 2023-12-09 13:37:01 浏览: 80
根据提供的引用[1],可以看出使用MyBatis-Plus的@TableField注释设置自动填充时间LocalDateTime类型没有生效。这可能是因为在实体类中,对应的字段没有使用注解@TableField(fill = FieldFill.INSERT)或@TableField(fill = FieldFill.INSERT_UPDATE)进行标注。这两个注解分别表示在插入和更新操作时自动填充该字段的值。如果仍然无法解决问题,可以尝试在配置文件中添加如下配置:
```yml
mybatis-plus:
global-config:
db-config:
logic-delete-value: 0
logic-not-delete-value: 1
id-type: auto
field-strategy: not_empty
db-type: mysql
table-prefix: mp_
logic-delete-field: deleted
auto-fill: true # 开启自动填充功能
```
关于引用中的问题,如果LocalDateTime有时接收不到,可能是因为时间格式不正确或者存在时区问题。可以尝试使用DateTimeFormatter对时间字符串进行格式化,或者使用atZone()方法将时间转换为指定时区的时间。例如:
```java
String timeStr = "2022-09-08 12:00:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, formatter);
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
```
阅读全文
相关推荐








