我正在尝试使用 [spring-data-jdbc] 保留布尔列,但转换默认为“TRUE”、“FALSE”值,但数据库列是 char(1) ('T'/'F'):
2018-07-13 14:58:32.761 [main] DEBUG org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQL state '22001', error code '22001', message [Valor demasiado largo para la columna "FLAG CHAR(1) NOT NULL": "'FALSE' (5)"
Value too long for column "OCCUPATION_FLAG CHAR(1) NOT NULL": "'FALSE' (5)"; SQL statement:
INSERT INTO MY_TABLE (description, flag, code) VALUES (?, ?, ?) [22001-197]]; SQL was [INSERT INTO MY_TABLE (description, flag, code) VALUES (?, ?, ?)] for task [PreparedStatementCallback]
我正在尝试创建一些转换器,但仍然失败。
@Bean
public Converter<Boolean, Character> booleanToCharacter() {
return new Converter<Boolean, Character>() {
@Override
public Character convert(Boolean source) {
if (null==source) { return (Character)null;}
return source.toString().toUpperCase().charAt(0);
}
};
}
@Bean
public Converter<Character, Boolean> characterToBoolean() {
return new Converter<Character, Boolean>() {
@Override
public Boolean convert(Character source) {
if (null==source) { return (Boolean)null; };
return 'T'==Character.toUpperCase(source);
}
};
}
任何建议都会很有用。谢谢。