java类
?
public class UserRankDTO extends UserRank {
??? /**
??? ?*
??? ?*/
??? private static final long serialVersionUID = -1126882582460825752L;
??? @Transient
??? private MultipartFile rankImages;
??? public MultipartFile getRankImages() {
??? ??? return rankImages;
??? }
??? public void setRankImages(MultipartFile rankImages) {
??? ??? this.rankImages = rankImages;
??? }
}
?
控制层
?
?
String comparisonPath = "";
??? ??? // 允许的文件格式
??? ??? String allowtypes = "gif,jpg,png";
??? ??? String allowtype = "gif,jpg,png,GIF,JPG,PNG";
??? ??? MultipartFile filemark = ur.getRankImages(); // 上传文件
??? ??? String basePath = WebUtil.getBasePath();
??? ??? String fileSaveDir = basePath
??? ??? ??? ??? + SystemGlobals.getPreference("upload.rank");
??? ??? // 制作相关文件夹
??? ??? File fileSavePath = new File(fileSaveDir);
??? ??? if (fileSavePath.exists() == false) {
??? ??? ??? FileUtil.mkDirectory(fileSaveDir);
??? ??? }
??? ??? boolean isvalid = true;
??? ??? String fname="";
??? ??? // 上传文件
??? ??? if (filemark != null && filemark.isEmpty() == false) {
??? ??? ??? fname = FileUtil.getSysRandomName(filemark
??? ??? ??? ??? ??? .getOriginalFilename(), fileSaveDir);
??? ??? ??? File f_save = new File(fname);
??? ??? ??? String[] allowTypes = allowtype.split(",");
??? ??? ??? String filename = filemark.getOriginalFilename();
??? ??? ??? String ftype = FileUtil.getFileType(filename);
??? ??? ??? isvalid = FileUtil.isValid(ftype, allowTypes);
??? ??? ??? comparisonPath = fname.replace(basePath, "");
??? ??? ??? FileCopyUtils.copy(filemark.getBytes(), f_save);
??? ??? ??? ur.setRankImage(comparisonPath);
??? ??? }