blob操作,我们一般用于存视频,图片,文档 下面是一个上传图片到数据库保存下来,然后下载的例子(上传和下载的前端代码就不展示了,已有功能展示了) @RequestMapping("ibatisLiveSqlController!insertBlob.do") public String insertBlob(@RequestParam(value = "theFile") MultipartFile file) throws Exception{ Img img = new Img(); img.setImg_name(file.getOriginalFilename()); img.setImg(file.getBytes()); ibatisLiveSqlService.insertImg(img); return JSON; } @Override public void insertImg(Img img) { if(ValidateUtil.isEmpty(img)){ throw new AppException("对象为空!"); } img.setId(getSequence("SEQ_IMGS_PLANS")); dao.insert("clobblob.insertImg", img); } <insert id="insertImg" parameterClass="com.yinhai.demo.domain.Img"> insert into imgs (id, img_name, img) values (#id#, #img_name#, #img,javaType=[B,jdbcType=BLOB#) </insert> <resultMap id="imgResult" class="com.yinhai.demo.domain.Img"> <result column="ID" property="id" jdbcType="VARCHAR2" javaType="String"/> <result column="IMG_NAME" property="img_name" jdbcType="VARCHAR2" javaType="String"/> <result column="IMG" property="img" jdbcType="BLOB" javaType="[B" /> </resultMap> <select id="queryImgById" parameterClass="String" resultMap="imgResult"> select id, img_name, img FROM imgs WHERE id = #id# </select> @RequestMapping("ibatisLiveSqlController!downloadImg.do") public String downloadImg() throws Exception{ HttpServletRequest request = getRequest(); Img img = (Img)getDao().queryForObject("clobblob.queryImgById", request.getParameter("id")); HttpServletResponse response = getResponse(); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"" + img.getImg_name() + "\""); response.setContentType("application/octet-stream;charset=UTF-8"); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); outputStream.write(img.getImg()); outputStream.flush(); outputStream.close(); return JSON; }
ibatis-blob
猜你喜欢
转载自blog.csdn.net/blossomfzq/article/details/82868064
今日推荐
周排行