mybatis byte[] array select/insert
<<< INSERT OR UPDATE >>>
- java
byte[] sumByte;
Map<String, Object> map = new HashMap<String, Object>();
map.put("sumByte", sumByte);
- mybatis xml
<update id="setBinaryFileInfo" parameterType="hashMap">
UPDATE ICOMATCH SET BINARY_FILE_INFO = #{sumByte, typeHandler=org.apache.ibatis.type.ByteArrayTypeHandler}
</update>
<<< SELECT >>>
# xml
<resultMap id="result" type="hashMap">
<result column="BINARY_FILE_INFO" property="BINARY_FILE_INFO" jdbcType="BLOB" javaType="[B" ></result>
</resultMap>
<select id="getBinaryFileInfo" parameterType="hashmap" resultMap="result">
SELECT BINARY_FILE_INFO
FROM ICOMATCH
WHERE HOUSE_CODE = #{ses.houseCode}
AND UUID = #{UUID}
AND UUID_SEQ = #{UUID_SEQ}
</select>
# mapper
public Map<String, Object> getBinaryFileInfo(Map<String, Object> map);
# service
public Map<String, Object> getBinaryFileInfo(String uuid, String uuid_seq){
Map<String, Object> map = new HashMap<String, Object>();
map.put("UUID", uuid);
map.put("UUID_SEQ", uuid_seq);
return fileAttachMapper.getBinaryFileInfo(map);
}
# controller
ServletOutputStream op = HttpServletResponse.getOutputStream();
byte[] bbuf = new byte[4096];
DataInputStream in = null;
if("BID".equals(fileInfo.get("BIZ_TYPE"))){
Map<String, Object> returnData = fileAttachService.getBinaryFileInfo(uuid, uuid_seq);
ByteArrayInputStream bis = new ByteArrayInputStream((byte[])returnData.get("BINARY_FILE_INFO"));
in = new DataInputStream(bis);
}else{
in = new DataInputStream(new FileInputStream(file));
}
while ((length = in.read(bbuf)) != -1) {
op.write(bbuf, 0, length);
}
in.close();
op.flush();
op.close();