【发布时间】:2026-01-21 21:10:01
【问题描述】:
我正在尝试在春季设置模型中列的默认值。
我知道我可以将它们设置为private boolean company=true;
设置列默认值的另一种方法包括@Column注解中的columnDefinition。
我试过这样做
@Column(nullable=false, columnDefinition="boolean default true")
private boolean company;
但在我的表中,company 的值被设置为0每当我运行此代码时。我正在使用 mysql 工作台。
我做错了吗?或者还有其他方法可以做到这一点吗?
编辑:我知道在我的表中没有存储布尔值。只会存储 0 或 1。但是当我将 columnDefinition 更改为@Column(nullable=false, columnDefinition="tinyint(1) default '1'") 那么存储到表中的值也是 0。
【问题讨论】:
标签: java mysql spring spring-mvc spring-annotations