我正在尝试返回 boolean
基于一些业务。我在这里使用 jdbctemplate。
public boolean dealExistsInInterval(String partyId) {
String sql = "<Query>";
boolean result = getJdbcTemplate().queryForObject(sql, new Object[] {partyId},
new RowMapper<boolean>() { --> **Error here**
public boolean mapRow(ResultSet rs, int rowNum) throws SQLException {
Date startDate = rs.getDate("BBORIGINDATE");
logger.info("Start date :"+startDate);
Date todayDate = new Date();
long diff = todayDate.getTime() - startDate.getTime();
Properties properties = BBUtil.getProperties();
int NO_OF_DAYS = 0;
if (properties != null) {
NO_OF_DAYS = Integer.parseInt(properties.getProperty("NO_OF_DAYS"));
}
logger.info("NO_OF_DAYS:"+NO_OF_DAYS);
logger.info("Number of days between today and latest deal :"+TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) < NO_OF_DAYS ? true : false;
}
});
return result;
}
编译时错误发生在 new RowMapper<boolean>()
.
P.S:这不是基于计数的查询。获得结果集后,我必须执行一些业务逻辑。
最佳答案
您无法定义原始数据类型的通用规范。您必须使用 java.lang.Boolean
包装类:
new RowMapper<Boolean>() {
public Boolean mapRow(ResultSet rs, int rowNum) throws SQLException {
// Code goes here...
关于java - 在 Spring jdbc 中使用 jdbctemplate 返回 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46882571/