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

边栏推荐
- Which users are suitable for applying for rapidssl certificate
- “29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”
- Redis AOF log persistence
- Some shortest path problems solved by hierarchical graph
- Hardware standard
- trivy【1】工具扫描运用
- Usage of delegate
- MySQL blocking monitoring script
- 智能工业设计软件公司天洑C轮数亿元融资
- Gbase8s how to delete data in a table with a foreign key relationship
猜你喜欢

Canonical Address

Some shortest path problems solved by hierarchical graph

@Valid的作用(级联校验)以及常用约束注解的解释说明

ROS的调试经验

How to simply realize the function of menu dragging and sorting

为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?

@The function of valid (cascade verification) and the explanation of common constraint annotations

Usage of delegate

树的孩子兄弟表示法
![[wechat applet development (VI)] draw the circular progress bar of the music player](/img/eb/9ce5d196970a6d6a887bf3e1d742ee.png)
[wechat applet development (VI)] draw the circular progress bar of the music player
随机推荐
IO flow: node flow and processing flow are summarized in detail.
没法预测明天的涨跌
【英雄哥七月集训】第 27天:图
How do you use the jar package sent by others (how to use the jar package sent by others)
First knowledge of C language -- structure, branch and loop statements
Consolidate the data foundation in the data center
【TA-霜狼_may-《百人计划》】图形3.7 移动端TP(D)R架构
初识C语言 -- 操作符和关键字,#define,指针
"29 years old, general function test, how do I get five offers in a week?"
JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
注意,这些地区不能参加7月NPDP考试
社恐适合什么工作?能做自媒体吗?
Flutter God operation learning (full level introduction)
[TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal
【信号去噪】基于卡尔曼滤波实现信号去噪附matlab代码
[signal denoising] signal denoising based on Kalman filter with matlab code
为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?
超参数调整和实验-训练深度神经网络 | PyTorch系列(二十六)
【TA-霜狼_may-《百人计划》】图形3.5 Early-z 和 Z-prepass