struts+spring+mybatis项目中图片上传获取

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>




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值