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

边栏推荐
- Share an esp32 relay
- [signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
- Selenium+pytest+allure comprehensive exercise
- Canonical Address
- Constant power wireless charging based on stm32
- 初识C语言 -- 操作符和关键字,#define,指针
- 【TA-霜狼_may-《百人计划》】图形3.7 移动端TP(D)R架构
- Four methods of modifying MySQL password (suitable for beginners)
- mysql 随笔
- LoRaWAN中的网关和chirpstack到底如何通信的?UDP?GRPC?MQTT?
猜你喜欢

2022.7.8 supplement of empty Luna

入职华为od一个月的感受

数据中台夯实数据基础
![[TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal](/img/9c/695294c673aa559462b4afe8eb5253.png)
[TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal

CNN循环训练的解释 | PyTorch系列(二十二)

【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码

Selenium+pytest+allure comprehensive exercise

Typescript (zero) -- introduction, environment construction, first instance
![Trivy [1] tool scanning application](/img/b1/c05949f9379fcde658da64f3a0157a.png)
Trivy [1] tool scanning application

tfx airflow 使用体验
随机推荐
【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码
【信号处理】基于高阶统计量特征的通信系统中微弱信号检测附matlab代码
[brother hero's July training] day 26: check the collection
GBase8s如何在有外键关系的表中删除数据
【信号去噪】基于卡尔曼滤波实现信号去噪附matlab代码
There is no way to predict the rise and fall of tomorrow
Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
Introduction to the reduce() function in JS
修改MySQL密码的四种方法(适合初学者)
2022.7.8 supplement of empty Luna
Representation of children and brothers of trees
CNN循环训练的解释 | PyTorch系列(二十二)
IO flow: node flow and processing flow are summarized in detail.
第二季度邮件安全报告:邮件攻击暴增4倍,利用知名品牌获取信任
Welcome to CSDN markdown editor Assad
特征值和特征向量
Hardware standard
Pychart shortcut key for quickly modifying all the same names on the whole page
"29 years old, general function test, how do I get five offers in a week?"