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

边栏推荐
- [image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
- 【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码
- 欢迎使用CSDN-markdown编辑器阿萨德
- Day 8 of DL
- Some shortest path problems solved by hierarchical graph
- vscode debug显示多列数据
- Flutter神操作学习之(满级攻略)
- [image defogging] image defogging based on dark channel and non-mean filtering with matlab code
- [brother hero's July training] day 27: picture
- 【OpenGL】GLES20.glClear
猜你喜欢

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

IO flow: node flow and processing flow are summarized in detail.

JS event object offsetx/y clientx y pagex y

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

A 64 bit 8-stage pipelined adder based on FPGA

Pycharm 快速给整页全部相同名称修改的快捷键

Job 7.27 IO process

vscode debug显示多列数据

TypeScript(零) —— 简介、环境搭建、第一个实例

Canonical Address
随机推荐
Confusion matrix in CNN | pytorch series (XXIII)
社恐适合什么工作?能做自媒体吗?
Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
Selenium+pytest+allure comprehensive exercise
Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'
【微信小程序开发(五)】接口按照根据开发版体验版正式版智能配置
JS event object offsetx/y clientx y pagex y
How do gateways and chirpstacks in lorawan communicate? UDP? GRPC? MQTT?
IO flow: node flow and processing flow are summarized in detail.
初识C语言 -- 结构体,分支和循环语句
Pychart shortcut key for quickly modifying all the same names on the whole page
为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?
Interpretation of cesium3dtilesets using customshader and examples of Omni effects
New infrastructure helps the transformation and development of intelligent road transportation
【OpenGL】GLES20.glClear
[signal denoising] signal denoising based on Kalman filter with matlab code
Redis AOF log persistence
First knowledge of C language -- operators and keywords, define, pointer
"29 years old, general function test, how do I get five offers in a week?"
Day 19 of leetcode