Int 值在数据库中存储为空字符串,尝试将新值设置为旧值会产生 "cannot convert string to int" 问题
Int value stored as empty string in database, trying to set new value to old value creates a "cannot convert string to int" problem
我有一个表单,它允许用户不输入 customer_no 的值,它是一个 int 值。我认为它作为空字符串存储在数据库中?
这是专栏customer_no INT(11) NULL,
为什么要这样存储?我正在尝试为值为 null 或 '' 时创建触发器以使用存储的旧值。但是它有不能将字符串转换为整数的错误。有什么帮助吗?这是触发器主体
IF NEW.customer_no IS NULL OR NEW.customer_no= ''
THEN SET NEW.customer_no= OLD.customer_no;
END IF;
[Field error in object 'form' on field 'customer_no ': rejected value []; codes
[typeMismatch.form.customer_no ,typeMismatch.customer_no ,typeMismatch.int,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[form.customer_no ,customer_no ]; arguments []; default message [customer_no ]]; default message [Failed to
convert property value of type 'java.lang.String' to required type 'int' for
property 'customer_no '; nested exception is java.lang.NumberFormatException: For input
string: ""]]
`
我正在使用 springboot 和 jdbc 查询从表单中获取信息并更新数据库,但是当值为空(而不是整数值)时它显示此错误。我希望用户可以选择不为此字段输入值,如果他们想更新其他字段,并且仍然保留之前为该特定字段输入的旧值。
例如,如果先前在数据库中输入的 customer_no 是 5,并且用户更新了数据库中的另一列并且没有为此字段输入值,则触发器应该使用存储的旧值 5 而不是空但它说 "cannot convert string to int"
希望有点道理
谢谢
将class接收表单的字段从int更改为Integer。然后它应该得到一个空值,我认为这就是你所追求的。
我有一个表单,它允许用户不输入 customer_no 的值,它是一个 int 值。我认为它作为空字符串存储在数据库中?
这是专栏customer_no INT(11) NULL,
为什么要这样存储?我正在尝试为值为 null 或 '' 时创建触发器以使用存储的旧值。但是它有不能将字符串转换为整数的错误。有什么帮助吗?这是触发器主体
IF NEW.customer_no IS NULL OR NEW.customer_no= ''
THEN SET NEW.customer_no= OLD.customer_no;
END IF;
[Field error in object 'form' on field 'customer_no ': rejected value []; codes [typeMismatch.form.customer_no ,typeMismatch.customer_no ,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [form.customer_no ,customer_no ]; arguments []; default message [customer_no ]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'customer_no '; nested exception is java.lang.NumberFormatException: For input string: ""]] `
我正在使用 springboot 和 jdbc 查询从表单中获取信息并更新数据库,但是当值为空(而不是整数值)时它显示此错误。我希望用户可以选择不为此字段输入值,如果他们想更新其他字段,并且仍然保留之前为该特定字段输入的旧值。
例如,如果先前在数据库中输入的 customer_no 是 5,并且用户更新了数据库中的另一列并且没有为此字段输入值,则触发器应该使用存储的旧值 5 而不是空但它说 "cannot convert string to int"
希望有点道理
谢谢
将class接收表单的字段从int更改为Integer。然后它应该得到一个空值,我认为这就是你所追求的。