我正在尝试制作一个表格,其中几乎没有属性。我的模型是帐户具有描述属性,默认情况下应该是“此帐户没有可用的描述”
CREATE TABLE accounts
(
...
description VARCHAR DEFAULT 'No description available for this account',
...
);
在控制器描述中,仅当它不为空且不等于“时才设置 “这样
if(!description.isEmpty() && !description.equals("\n"))
{
account.setDescription(description);
}
应用程序运行后,我得到一个账户表,但属性描述仍然为空,没有默认值。有什么想法吗?
Postgres 仅在未提供值时设置默认值 + 列不允许使用 NULL 值。
在表创建脚本中
description VARCHAR DEFAULT 'No description available for this account' NOT NULL
这也会更新所有现有记录
private String description = "No description available for this account";
还要对 setter 方法进行 NULL 检查。