在spring MVC中对数据库中图片流的操作需要使用到spring的LobHandler类,先在applicationContext.xml加入defaultLobHandler配置,简单配置如下:

<!-- 配置defaultLobHandler -->
    <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"
        lazy-init="true" />


在代码块加入如下操作主要代码:

LobHandler lobHandler = (LobHandler) WebApplicationContextUtils
                    .getWebApplicationContext(getServletContext()).getBean(
                            "defaultLobHandler");

InputStream is = lobHandler.getBlobAsBinaryStream(rs, 3);//获取图片输入流


更多推荐

spring MVC获取数据库的图片二进制流的方法