81,092
社区成员
发帖
与我相关
我的任务
分享
String tea_number = (String) request.getSession().getAttribute("tea_number");
String type = getUploadFileName().substring(getUploadFileName().lastIndexOf(".")).toLowerCase();
String realpath = request.getSession().getServletContext().getRealPath("\\images\\"+tea_number+type);
String path = "/images/"+tea_number+type;
FileInputStream fis = new FileInputStream(getUpload());
FileOutputStream fos = new FileOutputStream(realpath);
int len;
byte[] buf = new byte[1024];
while((len=fis.read(buf))!=-1){
fos.write(buf,0,len);
}
fos.close();
fis.close();
Teacher t = new Teacher();
t.setTea_number(tea_number);
t = teacherService.findSingleTeacher(t);
t.setTea_icon(path);
teacherService.updateTeacher(t);
/**
* 获取保安人员相片
* @param id
* @param response
* @throws Exception
*/
@RequestMapping("/getpicuture")
public void getPicture(@RequestParam("tableName") String tableName,
@RequestParam("keyFieldName") String keyFieldName,
@RequestParam("keyFieldValue") String keyFieldValue,
@RequestParam("imageFieldName") String imageFieldName,
@RequestParam("time") long time, HttpServletResponse response,
HttpServletRequest request) throws Exception {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
byte[] by = null;
try {
conn = beanFactoryDataSourceLookup.getDataSource("dataSource")
.getConnection();
String sql = "select " + imageFieldName + " from " + tableName
+ " t where t." + keyFieldName + " = ?";
ps = conn.prepareStatement(sql);
ps.setString(1, keyFieldValue);
rs = ps.executeQuery();
if (rs.next()) {
Blob bo = rs.getBlob(1);
by = new byte[(int) bo.length()];
InputStream in = bo.getBinaryStream();
in.read(by);
ServletOutputStream out = response.getOutputStream();
in.close();
out.write(by);
out.flush();
out.close();
in.close();
}
} catch (Exception e) {
// e.printStackTrace();
} finally {
conn.close();
}
}