jsp:
<td style="padding-left: 4em;" align="left">团队标志:
<input id="image" type="file" name="uploadFile"></td>
java:
InputStream input = null;
byte[] imageByteArray = null;
input = new FileInputStream(uploadFile);
imageByteArray = IOUtils.toByteArray(input);
struts中其它参数用struts推荐的get,set方式获取
mybatis:
<!-- 创建团队 -->
<insert id="creatTeam" parameterType="map">
insert into t_team (id,name,teamleader,logo,ci_id)
values(seq_t_team.nextval,#{teamName},#{teamleader},#{imageByteArray,jdbcType=BLOB},#{cid})
</insert>
mybatis中插入BLOB类型需要加入Type类型
————————————————————————————————————————————————
图片获取:
jsp:
<img src="进入项目中action获取">
java:
/**
* 获取团队标志
*/
public String queryTeamlogo(){
String id = request.getParameter("id");
HashMap<String, Object> map = new HashMap<String, Object>();
map = sportPiazaService.queryTeamlogo(id);/ /根据id从数据库中获取blob字段的值,通过map类型获取
Blob imageBlob = (Blob) map.get("LOGO"); //转换为blob类型
response.setContentType("image/png;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
OutputStream out = null;
try {
InputStream inputStream = imageBlob.getBinaryStream();
int size = (int) imageBlob.length();
byte[] data = new byte[size];
inputStream.read(data);
out = response.getOutputStream();
out.write(data);
out.flush();
out.close();
inputStream.close();
} catch (Exception e) {
logger.error(DateUtils.getTodayStr()+"获取团队标志\n" +e);
}
return null;
}
mybatis:
<!-- 获取团队标志 -->
<select id="queryTeamlogo" parameterType="string" resultType="map" flushCache="true">
select logo from t_team where id=#{id}
</select>