4 回答
TA贡献1801条经验 获得超16个赞
之前 做过同样的案例,发给你 你look 一下.
表结构:
create table CONTACTS (
id number(19,0) not null,
name varchar2(24 char),
address varchar2(24 char),
gender varchar2(2 char),
birthday timestamp,
email varchar2(24 char),
mobile varchar2(24 char),
photo blob,
primary key (id)
);
Contact 实体类中 photo 变量 数据类型 定义为byte[]
创建 联系人 相关代码:
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
MultipartFile multFile = multiRequest.getFile("photo");
.......
[b]contact.setPhoto(multFile.getBytes());[/b] contactsService.save(contact);
@RequestMapping("/img")
[code="java"]public void getImg(@RequestParam("id")Integer id,HttpServletResponse response)throws IOException{
Contact contact = contactsService.getById(id);
OutputStream out=response.getOutputStream();
out.write(contact.getPhoto());
out.flush();
out.close();
}
添加回答
举报