应用管理-图片上传
This commit is contained in:
@@ -35,6 +35,39 @@ public class AppAction extends BaseAction<AppModel>
|
||||
private UserBusinessIService userBusinessService;
|
||||
private AppModel model = new AppModel();
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
public void uploadImg()
|
||||
{
|
||||
Log.infoFileSync("==================开始调用上传图片方法uploadImg()===================");
|
||||
File fileInfo = model.getFileInfo();
|
||||
String fileName = model.getFileInfoName(); //获取文件名
|
||||
try {
|
||||
if(fileInfo != null ){
|
||||
String path = ServletActionContext.getServletContext().getRealPath("/upload/images/deskIcon");
|
||||
InputStream is = new FileInputStream(fileInfo);
|
||||
File file = new File(path, fileName);
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
byte[] b = new byte[1024];
|
||||
int bs = 0;
|
||||
while ((bs = is.read(b)) > 0) {
|
||||
os.write(b, 0, bs);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
}
|
||||
Log.infoFileSync("==================结束调用上传图片方法uploadImg()===================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加应用
|
||||
@@ -50,35 +83,7 @@ public class AppAction extends BaseAction<AppModel>
|
||||
app.setNumber(model.getNumber());
|
||||
app.setName(model.getName());
|
||||
app.setType(model.getType());
|
||||
|
||||
try {
|
||||
if(model.getIcon()!=null)
|
||||
{
|
||||
String path = ServletActionContext.getServletContext().getRealPath("/upload/images/deskIcon");
|
||||
String iconName=model.getIcon();
|
||||
File file1 = new File(iconName); //文件
|
||||
String FileName = file1.getName(); //获取文件名
|
||||
app.setIcon(FileName); //设置图片ICON
|
||||
InputStream is = new FileInputStream(iconName);
|
||||
File file = new File(path, FileName);
|
||||
OutputStream os = new FileOutputStream(file);
|
||||
byte[] b = new byte[1024];
|
||||
int bs = 0;
|
||||
while ((bs = is.read(b)) > 0) {
|
||||
os.write(b, 0, bs);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
app.setIcon(model.getIcon()); //设置图片Icon
|
||||
app.setURL(model.getURL());
|
||||
app.setWidth(model.getWidth());
|
||||
app.setHeight(model.getHeight());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.jsh.model.vo.basic;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -28,7 +30,9 @@ public class AppModel implements Serializable
|
||||
* 图标
|
||||
*/
|
||||
private String Icon = "";
|
||||
|
||||
|
||||
private File fileInfo;
|
||||
private String fileInfoName; //图片名称
|
||||
/**
|
||||
* 链接
|
||||
*/
|
||||
@@ -139,6 +143,22 @@ public class AppModel implements Serializable
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public File getFileInfo() {
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
public void setFileInfo(File fileInfo) {
|
||||
this.fileInfo = fileInfo;
|
||||
}
|
||||
|
||||
public String getFileInfoName() {
|
||||
return fileInfoName;
|
||||
}
|
||||
|
||||
public void setFileInfoName(String fileInfoName) {
|
||||
this.fileInfoName = fileInfoName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return Type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user