MySQL创建自动更新列
项目中很多时候需要自动更新的列表项,例如创建时间(createTime)和修改时间(updateTime),所以的在建表的时候需要特殊处理一下:
create table `account` ( `id` int primary key auto_increment, `title` varchar(32) not null comment ‘标题‘, `price` decimal(6,2) default 0.01 comment ‘价格‘, `username` varchar(16) not null comment ‘账号‘, `password` varchar(16) not null comment ‘密码‘, `create_time` timestamp default current_timestamp comment ‘创建时间‘, `update_time` timestamp default current_timestamp on update current_timestamp comment ‘修改时间‘ ) comment ‘账号表‘;
然后修改对应的实体类,添加@DynamicInsert和@DynamicUpdate注解
@Data @Entity @DynamicInsert @DynamicUpdate public class Account { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String title; private BigDecimal price; private String username; private String password; private Date createTime; private Date updateTime; }
相关推荐
九天银河技术 2020-11-11
adsadadaddadasda 2020-09-08
行万里 2020-10-26
此处省略三千字 2020-10-22
nongfusanquan0 2020-09-23
夜影风个人空间 2020-09-22
85251846 2020-09-14
jbossrobbie 2020-08-16
幸福ITman汪文威 2020-08-15
MySQL源氏boy 2020-08-15
MySQLqueen 2020-08-15
solarspot 2020-07-28
Greatemperor 2020-07-19
manongxiaomei 2020-07-05
javamagicsun 2020-07-04
june0 2020-07-04
yogoma 2020-06-25
shawsun 2020-06-21