当前位置:网站首页>[email protected] Annotation usage
[email protected] Annotation usage
2022-07-28 03:00:00 【qq_ forty-five million eight hundred and sixty thousand nine hu】
One ,fill attribute
Alibaba's development specification recommends that each table be accompanied by a createTime And a updateTime, But it's too troublesome to add it manually every time , You can configure the MP Let it automatically add .
The first 1 Step : Add TableField Of fill attribute 
The first 2 Step : Override meta object handler .
Use here LocalDateTime Of now Method to get the current time . Be careful JDBC The configuration of should use the time of Dongba District CTT, Do not use UTC When coordinating , There will be less 8 Hours .
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);
}
}
Write a test method , Test it :
result :

边栏推荐
- New infrastructure helps the transformation and development of intelligent road transportation
- Interpretation of cesium3dtilesets using customshader and examples of Omni effects
- mysql 随笔
- P6118 [JOI 2019 Final]珍しい都市 题解
- ORACLE BASICFILE LOB字段空间回收SHRINK SPACE的疑惑
- Data center construction (III): introduction to data center architecture
- @The function of valid (cascade verification) and the explanation of common constraint annotations
- Docker advanced -redis cluster configuration in docker container
- 分布式事务——Senta(一)
- @Valid的作用(级联校验)以及常用约束注解的解释说明
猜你喜欢

Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记

tfx airflow 使用体验

POC simulation attack weapon - Introduction to nucleus (I)

超参数调整和实验-训练深度神经网络 | PyTorch系列(二十六)

Canvas from getting started to persuading friends to give up (graphic version)

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

Which users are suitable for applying for rapidssl certificate

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

Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)

【stream】并行流与顺序流
随机推荐
JS中的reduce()函数介绍
pytest最好的测试框架
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
入职华为od一个月的感受
Day 8 of DL
Flutter神操作学习之(满级攻略)
数据中台夯实数据基础
初识C语言 -- 结构体,分支和循环语句
Which users are suitable for applying for rapidssl certificate
TypeScript(零) —— 简介、环境搭建、第一个实例
数据湖:数据库数据迁移工具Sqoop
Data center construction (III): introduction to data center architecture
Is it safe to buy funds on Alipay? I want to make a fixed investment in the fund
JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑
牛客-TOP101-BM340
clientY vs pageY
Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
【stream】stream流基础知识