我有一个包含字符串,int和布尔字段的类。我有为他们宣布的获得者和接受者。Spring Bean BeanPropertyRowMapper是否('Y','N')为布尔bean属性
public class SomeClass {
private int id;
private String description;
private boolean active;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
我是BeanPropertyRowMapper从Oracle DB获取所有对象。
@Override
public List<Destination> getAll() {
List<SomeClass> objs = jdbcTemplate.query(
myQuery, new BeanPropertyRowMapper<SomeClass>(SomeClass.class));
return objs;
}
如果调试已打开我看到:
[3/14/13 10:02:09:202 EDT] 00000018 SystemOut O DEBUG BeanPropertyRowMapper - Mapping column 'ID' to property 'id' of type int
[3/14/13 10:02:09:202 EDT] 00000018 SystemOut O DEBUG BeanPropertyRowMapper - Mapping column 'DESCRIPTION' to property 'description' of type class java.lang.String
然后它没有试图映射活跃。 Active被定义为DB中1个字节的CHAR,其值为'Y'或'N'。使用BeanPropertyRowMapper并成功将诸如“Y”和“N”之类的值转换为布尔值的最佳方式是什么?
你最好不要写自己的自定义的RowMapper不是试图找出为什么春天不能将boolean Y转换为布尔值true。或者改变你的数据库映射。 – 2013-03-14 14:56:21
感谢您的信息。如何更改数据库映射来解决此问题,因为oracle没有布尔类型?我认为使用beanpropertyrowmapper有一定的价值,因为它有助于节省大量的样板代码,特别是如果你有很多域对象。它比数据访问花费更多的时间并专注于业务逻辑。 – MickJ 2013-03-14 15:13:32
是的,我只注意到Oracle没有布尔类型。我一直在阅读'BeanPropertyRowMapper',显然这应该是(而且是?)在[Spring 2.5.2](https://jira.springsource.org/browse/SPR-4355)中修复的。尽管你可能不得不使用BeanPropertyRowMapper方法。 – 2013-03-14 15:17:41