package com.xiaohui.cms.entity;
public class FileInfo {
private String fileName;//文件名称
private boolean isSecret;//是否是私密文件
private String absolutPath;//文件的绝对路径
private String relativePath;//文件的相对路径
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getAbsolutPath() {
return absolutPath;
}
public void setAbsolutPath(String absolutPath) {
this.absolutPath = absolutPath;
}
public String getRelativePath() {
return relativePath;
}
public void setRelativePath(String relativePath) {
this.relativePath = relativePath;
}
public boolean isSecret() {
return isSecret;
}
public void setSecret(boolean isSecret) {
this.isSecret = isSecret;
}
public FileInfo() {
}
public FileInfo(String fileName, boolean isSecret, String absolutPath, String relativePath) {
super();
this.fileName = fileName;
this.isSecret = isSecret;
this.absolutPath = absolutPath;
this.relativePath = relativePath;
}
@Override
public String toString() {
return "FileInfo [fileName=" + fileName + ", isSecret=" + isSecret + ", absolutPath=" + absolutPath
+ ", relativePath=" + relativePath + "]";
}
}
Controller类
package com.xiaohui.cms.controller;
import com.xiaohui.cms.entity.FileInfo;
import com.xiaohui.cms.utils.JesyFileUploadUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
@RequestMapping("/upload")
public class FileController {
@PostMapping("/file")
@ResponseBody
@CrossOrigin(origins = "*")
public String upload(MultipartFile file) {
String path =null;
try {
FileInfo fileInfo = JesyFileUploadUtil.uploadFile(file ,"http://localhost:8060");//上传地址
path =fileInfo.getRelativePath();
} catch (IOException e) {
e.printStackTrace();
}
return path;
}
}
HBuilder X
页面上传
添加页面
uni 界面
选择标题图(图片分辨率建议为:200px*200px)
变量
var _self ;//声明
export default {
data() {
return {
imgpPath: null,//图片变量
loading: false,//进度变量
}
}
}
函数
upload(){
_self =this;
_self.loading =true;
//选择图片 使用uin.chooseImage
uni.chooseImage({
count:1,
sizeType:['original','compressed'],//original:原图:compressed:压缩图 指定上传的图片是原图 还是压缩图
sourceType:['album'],//从相册选择
success: (res) => {
const temFilePath = res.tempFilePaths;//图片选择完成后 获取该图片的路劲
//上传图片 使用uni.upLoadFile
uni.uploadFile({
url:'http://127.0.0.1:8070/upload/file',//上传文件的Controller
filePath: temFilePath[0],//要上传的文件路径
name:'file',
success: (res) => {
console.log(res);
_self.loading =false;//进度条
_self.imgpPath =res.data;
}
});
}
})
}
页面列表
data
data() {
return {
baserUrl:'http://localhost:8060',
}
},
页面 完整代码
文章ID 文章名称 标题图片 文章简述 发布时间 设置 {{article.id}} {{article.name}} {{article.descr}} {{article.publishTime}}
添加页面
选择标题图(图片分辨率建议为:200px*200px)



