1.在oracle数据库中以blob类型存储,写入时以byte[]形式。
2.在取出的xml中<result property="meImage" column="MEAL_IMAGE" jdbcType="BLOB" javaType="[B"/>
3.转json
// 从数据库中取出图片数据二进制数组,利用base64转成字符串
byte[] mi = tpom.getMeImage();
if(null==mi || mi.length==0){
}else{
String mealImage = new String(Base64.encode(mi));
tpol.setMealImage(mealImage);
}
4.取json返回的图片字符串,还原图片
@Test
public void picture() throws UnsupportedEncodingException{
String ss="json返回的图片字符串,一般很大";
Base64 encode = new Base64();
byte[] cc = encode.decode(ss.getBytes());
String result = new String(cc);
System.out.println(result);
try {
OutputStream os = new FileOutputStream(new File("D:\\picture\\4.png"));
os.write(cc);
os.flush();
} catch (FileNotFoundException e) {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}