YelinCui | fdf4ed7 | 2025-05-26 11:49:36 +0800 | [diff] [blame] | 1 | package com.example.myproject.config; |
| 2 | |
| 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
| 4 | import org.apache.ibatis.reflection.MetaObject; |
| 5 | import org.springframework.stereotype.Component; |
| 6 | |
| 7 | import java.time.LocalDateTime; |
| 8 | |
| 9 | @Component |
| 10 | public class MyMetaObjectHandler implements MetaObjectHandler { |
| 11 | |
| 12 | |
| 13 | @Override |
| 14 | public void insertFill(MetaObject metaObject) { |
| 15 | this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); |
| 16 | this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); |
| 17 | } |
| 18 | |
| 19 | // 更新时自动填充 |
| 20 | @Override |
| 21 | public void updateFill(MetaObject metaObject) { |
| 22 | this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); |
| 23 | } |
| 24 | } |