1 回答
TA贡献1801条经验 获得超8个赞
您可以指示BeanPropertyItemSqlParameterSourceProvider返回VARCHAR字段的类型,design如下所示:
@Bean
public JdbcBatchItemWriter<OphthalmicLens> writer(DataSource dataSource) throws SQLException {
return new JdbcBatchItemWriterBuilder<OphthalmicLens>()
.itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<OphthalmicLens>() {
@Override
public SqlParameterSource createSqlParameterSource(OphthalmicLens item) {
return new BeanPropertySqlParameterSource(item) {
@Override
public int getSqlType(String paramName) {
if (paramName.equalsIgnoreCase("desing")) {
return Types.VARCHAR;
}
return super.getSqlType(paramName);
}
};
}
})
.sql("INSERT INTO OphthalmicLens (`createdBy`,`createdDate`,`lastModifiedBy`,`lastModifiedDate`,`sid`,`version`,`manufacturer`,`manufacturerCode`,`name`,`sku`,`upc`,`cylinder`,`design`,`diameter`,`index`,`material`,`source`,`sphere`,`type`) VALUES (:createdBy,NOW(),:lastModifiedBy,NOW(),UUID(),:version,:manufacturer,:manufacturerCode,:name,:sku,:upc,:cylinder,:design,:diameter,:index,:material,:source,:sphere,:type)")
.dataSource(dataSource)
.build();
}
添加回答
举报