当前位置:网站首页>[email protected]注解使用
[email protected]注解使用
2022-07-28 02:00:00 【qq_45860901】
一,fill属性
阿里巴巴的开发规范中推荐每个表都带有一个createTime 和一个 updateTime, 但是每次自己手动添加太麻烦了,可以配置MP让其自动添加。
第1步 : 实体类对应字段添加TableField 的fill 属性
第2步 : 重写元对象handler 。
这里使用LocalDateTime的now 方法获取当前时间。注意JDBC的配置要使用东八区的时间CTT,不要使用UTC协调时,会少8个小时。
spring.datasource.url=jdbc:mysql://localhost:3306/seckill?
useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=CTT
package com.seckill.seckilldemo.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "gmtCreate", LocalDateTime.class, LocalDateTime.now());
this.strictInsertFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
// setFieldValByName("gmtCreate", LocalDateTime.now(), metaObject);
// setFieldValByName("gmtModified", LocalDateTime.now(), metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
// setFieldValByName("gmtModified", LocalDateTime.now(), metaObject);
}
}
写个测试方法,测试一下:
结果:

边栏推荐
- Arm32 for remote debugging
- Four methods of modifying MySQL password (suitable for beginners)
- Ah Han's story
- P6118 [JOI 2019 Final]珍しい都市 题解
- There is no way to predict the rise and fall of tomorrow
- Collision and rebound of objects in unity (learning)
- Trivy [1] tool scanning application
- 2022.7.8 eth price analysis
- 入职华为od一个月的感受
- [tutorial of using idea] shortcut key of idea
猜你喜欢
![[self growth website collection]](/img/42/fa17c9167697543defd3e63a97237a.png)
[self growth website collection]

Superparameter adjustment and experiment - training depth neural network | pytorch series (26)

Job 7.27 IO process

How to simply realize the function of menu dragging and sorting

Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'

On the problem that sqli labs single quotation marks do not report errors

Special network technology virtual host PHP version setting

First knowledge of C language -- operators and keywords, define, pointer

tfx airflow 使用体验

CNN训练循环重构——超参数测试 | PyTorch系列(二十八)
随机推荐
[leetcode] 13. linked list cycle · circular linked list
Hardware standard
Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
POC模拟攻击利器 —— Nuclei入门(一)
Should programmers choose outsourcing companies
First knowledge of C language -- operators and keywords, define, pointer
Collision and rebound of objects in unity (learning)
How to authenticate Youxuan database client
[wechat applet development (V)] the interface is intelligently configured according to the official version of the experience version of the development version
【OpenGL】GLES20.glClear
Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记
[brother hero's July training] day 27: picture
树的孩子兄弟表示法
RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑
【stream】并行流与顺序流
First knowledge of C language -- structure, branch and loop statements
MySQL blocking monitoring script
JS中的reduce()函数介绍
【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
Building of APP automation environment (I)