sqlserver库在字段中存取图片

SqlServer中数据类型是varbinary

存图

springMVC中(需要将图片字符流转为字节数组存到库中):

public void updateTYTX00(Map<String, Object> params) throws Exception {
    
    
		
		String paraTP0000 = String.valueOf(params.get("paraTP0000"));
		if (CommonUtils.isStringNull(paraTP0000)) {
    
    
			BASE64Decoder decoder = new BASE64Decoder();
			byte[] b = decoder.decodeBuffer(paraTP0000);
			params.put("paraTP0000", b);
		}
		this.reportManageDao.updateTYTX00(params);
		
	}

mybatis中写法:

 insert into SY_PE_YWSJ_TYTX00
          (LSID00, LB0000, ID0000, TP0000, CZY000)
          select #{paraLSID00},
                 #{paraLB0000},
                 #{paraID0000},
                 #{paraTP0000,jdbcType=BLOB},
                 #{paraCZY000}
        

注:jdbcType=BLOB表示,标识格式为字节数组

取图

springMVC中处理(需要将字节数组转为字符流)

for (int i = 1; i < cur_TYTX00.size(); i++) {
    
    
		Map m = (Map) cur_TYTX00.get(i);
		if (!CommonUtils.isNull(m.get("TP0000"))) {
    
    
			byte[] blob = (byte[]) m.get("TP0000");
			String content = "";
			try {
    
    
				content = Base64.encodeBase64String(blob);
				((Map)cur_TYTX00.get(i)).put("TP0000", content);
			} catch (Exception e) {
    
    
				logger.error("图片转换类型失败", e);
			}
		}
	 }

猜你喜欢

转载自blog.csdn.net/weixin_38323645/article/details/104851203
今日推荐