当前位置:网站首页>[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);
}
}
写个测试方法,测试一下:
结果:

边栏推荐
- A brief analysis of the differences between functional testing and non functional testing, recommended by Shanghai haokoubei software testing company
- @Valid的作用(级联校验)以及常用约束注解的解释说明
- Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
- [self growth website collection]
- Notes for the fourth time of first knowing C language
- There is no way to predict the rise and fall of tomorrow
- Day 8 of DL
- Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
- 【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码
- 小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
猜你喜欢

使用PyTorch的TensorBoard-可视化深度学习指标 | PyTorch系列(二十五)

修改MySQL密码的四种方法(适合初学者)

Which users are suitable for applying for rapidssl certificate

JS event object offsetx/y clientx y pagex y

unordered_map的hash function及hash bucket存储方式探索

trivy【1】工具扫描运用

Docker高级篇-Docker容器内Redis集群配置

First knowledge of C language -- structure, branch and loop statements

Redis AOF log persistence

Design of edit memory path of edit box in Gui
随机推荐
trivy【1】工具扫描运用
【英雄哥七月集训】第 26天:并查集
【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
Canvas from getting started to persuading friends to give up (graphic version)
pytest最好的测试框架
POC simulation attack weapon - Introduction to nucleus (I)
What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
Flutter God operation learning (full level introduction)
Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'
Trivy [1] tool scanning application
GBase8s如何在有外键关系的表中删除数据
使用PyTorch的TensorBoard-可视化深度学习指标 | PyTorch系列(二十五)
[wechat applet development (VI)] draw the circular progress bar of the music player
JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
There is no way to predict the rise and fall of tomorrow
JS event loop synchronous task, asynchronous task (micro task, macro task) problem analysis
Commissioning experience of ROS
vscode debug显示多列数据
Redis AOF log persistence
D multi production single consumption