1.字符串与blob相互转化
<span style="font-size:18px;"> /**
* blob转string
* @param blob
* @return
*/
public static String blobToString(Blob blob) {
String str = "";
try {
InputStream ins = blob.getBinaryStream();
byte[] c = new byte[(int) blob.length()];
ins.read(c);
str = new String(c);
ins.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
/**
* string转blob
* @param str
* @return
*/
public static Blob stringToBlob(String str) {
str = StrUtil.formatNull(str);
Blob b = null;
try {
b = new SerialBlob(str.getBytes());
} catch (SerialException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}</span>
2.http流传递数据注意事项
a.短字符串传递到头部上,多数据使用流传递
b.传递中设置编码格式
c.URLEncoder.encode(dataNum, "UTF-8")避免中文乱码
3.json字符串转化为对象(使用的json包为阿里巴巴的json包)
<span style="font-size:18px;"> String text = "{\"area\":\"深圳\",\"city\":\"zz\",\"entryName\":\"zz6\",\"province\":\"zzz\",\"street\":\"????12?\",\"userId\":\"d074fb68-fac9-4b8a-8bac-2ee08a6318e9\"}";
AddressModel passport = JSONObject.parseObject(text, AddressModel.class);
</span>