seam 中 上传图片实现
seam中默认的seam-gen生成项目确实不会帮你处理图片的问题。需要做一定的修改才行。
以mysql数据库为例:
1.在mysql中使用longblob类型来存图像。
2.生成的实体bean对图片的字段做一定得修改
@Type(type="binary") @Column(name = "pic", nullable = false, columnDefinition="longblob") @NotNull public byte[] getPic() { return this.pic; }3.页面对于图片的上传,form标签要加上enctype="multipart/form-data"
<h:form enctype="multipart/form-data"> ...... <s:fileUpload id="pic" data="#{personHome.instance.pic}" accept="image/jpg" contentType="image/jpg" /> ...... <h:form>4.页面对于图片的显示
<s:graphicImage rendered="#{personHome.instance.pic ne null}" value="#{personHome.instance.pic}"> <s:transformImageSize width="200" maintainRatio="true"/> </s:graphicImage>