一天上午,小明突然叫我说数据库数据很奇怪,我看了下的确好奇怪
为什么自增id字段突然变得怎么大了,后面我比对下其他的库表,有点自增id是ok,有的也出现上述的情况,我一开始就纳闷了,然后开启数据库的打印语句,发现入库语句如下:
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@21f78019] will be managed by Spring
==> Preparing: INSERT INTO user ( id, name, age, email, modify_time ) VALUES ( ?, ?, ?, ?, ? )
==> Parameters: 1263010382649716737(Long), stringbxsdf(String), 0(Integer), string(String), 2020-05-20 15:35:15.432(Timestamp)
<== Updates: 1
正如上面所示,sql居然显示指定自增id的值,我调试了测试样本代码,发现没有显示指定id的值
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@3ffe858f] will be managed by Spring
==> Preparing: INSERT INTO user ( name, age, email, modify_time ) VALUES ( ?, ?, ?, ? )
==> Parameters: stringbxsdf(String), 0(Integer), string(String), 2020-05-20 15:36:56.419(Timestamp)
<== Updates: 1
这个差别让我对比下双方的entity的定义发现了差别如下,会显示指定id的值的定义是
@Data
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Long id;
private String name;
private Integer age;
private String email;
@TableField(value = "modify_time", fill = FieldFill.INSERT_UPDATE, update = "now()", strategy = FieldStrategy.NOT_NULL)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Timestamp modifyTime