- 1. 数据库Scheme
1.数据库Scheme
- DROP TABLE IF EXISTS `user_graphic_t`;
- /*!40101 SET @saved_cs_client = @@character_set_client */;
- /*!40101 SET character_set_client = utf8 */;
- CREATE TABLE `user_graphic_t` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `graphic_data` blob,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=360 DEFAULT CHARSET=utf8;
2.Mapper配置文件
- <resultMap id="userGraphicMap" type="userGraphicVo">
- <id column="id" property="id" jdbcType="DECIMAL" />
- <span style="color: #ff0000;"><result column="graphic_data" property="graphicData" jdbcType="BLOB" /></span>
- </resultMap>
- <sql id="resultColumn">
- id,graphic_data
- </sql>
- <insert id="insertUserGraphic" parameterType="userGraphicVo">
- INSERT INTO user_graphic_t (
- <include refid="resultColumn" />
- )
- values (
- #{id},,#{graphicData}
- )
- </insert>
- <select id="selectUserGraphic" parameterType="java.lang.Long" resultMap="userGraphicMap">
- SELECT
- <include refid="resultColumn" />
- from user_graphic_t WHERE
- id=#{id}
- order by id desc
- </select>
3.Java bean
- public class UserGraphicVo {
- private Long id;
- private byte[] graphicData;
- //get/set方法
- }
4.Action 处理
- public void showReportImage() {
- response.setContentType("image/jpeg");
- if (!"".equals(id)) {
- List<UserGraphicVo> list = userGraphicService.findUserGraphicVoById(id);
- if(null != list && !list.isEmpty()){
- OutputStream os = null;
- try {
- os = response.getOutputStream();
- os.write(list.get(0).getGraphicData());
- os.flush();
- } catch (IOException e) {
- Log.info("读取文件出错!" + e.getMessage());
- } finally {
- if(null != os){
- try {
- os.close();
- } catch (IOException e) {
- Log.info("关闭文件输出流出错!" + e.getMessage());
- }
- }
- }
- }
- }
- }
时间: 2024-11-05 13:37:00