生产代码如下:
public void streamImage(final String name, final OutputStream os)
throws DataAccessException {
this.simpleJdbcTemplate.getJdbcOperations().query(
"select content from imagedb where image_name=?",
new Object[] { name },
new AbstractLobStreamingResultSetExtractor() {
@Override
protected void handleNoRowFound()
throws LobRetrievalFailureException {
throw new EmptyResultDataAccessException(
"Image with name '" + name
+ "' not found in database", 1);
}
@Override
protected void streamData(ResultSet rs)
throws SQLException, IOException,
DataAccessException {
InputStream inputStream = lobHandler
.getBlobAsBinaryStream(rs, 1);
if (inputStream != null) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int length = 0;
while ((length = inputStream.read(bytes)) > 0) {
outputStream.write(bytes, 0, length);
}
os = outputStream;
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
});
}
在代码行红色的位置,IDE提示错误,在内部类中如何才能正确为外部形参赋值?请帮忙解答,谢谢。
------解决方案--------------------
os紧紧是内部类内部使用,可以设置个内部类成员变量指向os。
- Java code
这里填代码
------解决方案--------------------
有了修饰符final修饰形态变量,在方法内部就不能给变量os重新再赋值了..
你其实没有必要再给os赋值..
重新定义一个变量让其指向os..