一、时间修改
simpledateformat:时间格式
二、文件上传:
commons-fileupload
commons-fileupload
1.3.1
com.sun.jersey
jersey-client
1.19
com.sun.jersey
jersey-core
1.19
工具类:
JesyFileUploadUtil.java
package com.rz.cms.server.main.utils;
import java.io.IOException;
import java.util.Date;
import java.util.Random;
import javax.net.ssl.SSLContext;
import org.springframework.web.multipart.MultipartFile;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
public class JesyFileUploadUtil {
public static FileInfo uploadFile(MultipartFile file, String serverUrl) throws IOException {
//把request请求转换成多媒体的请求对象
// MultipartHttpServletRequest mh = (MultipartHttpServletRequest) request;
//根据文件名获取文件对象
// MultipartFile cm = mh.getFile(fileName);
//获取文件的上传流
byte[] fbytes = file.getBytes();
//重新设置文件名
String newFileName = "";
newFileName += new Date().getTime()+""; //将当前时间获得的毫秒数拼接到新的文件名上
//随机生成一个3位的随机数
Random r = new Random();
for(int i=0; i<3; i++) {
newFileName += r.nextInt(10); //生成一个0-10之间的随机整数
}
//获取文件的扩展名
String orginalFilename = file.getOriginalFilename();
String suffix = orginalFilename.substring(orginalFilename.indexOf("."));
//创建jesy服务器,进行跨服务器上传
// Client client = Client.create(getClientConfig());
Client client = Client.create();
//把文件关联到远程服务器
//http://127.0.0.1:8080/ssm_image_server/upload/123131312321.jpg
WebResource resource = client.resource(serverUrl+"/upload/"+newFileName+suffix);
//上传
resource.put(String.class, fbytes);
//图片上传成功后要做的事儿
//1、ajax回调函数做图片回显(需要图片的完整路径)
//2、将图片的路径保存到数据库(需要图片的相对路径)
String fullPath = serverUrl+"/upload/"+newFileName+suffix; //全路径
String relativePath = "/upload/"+newFileName+suffix; //相对路径
// //生成一个json响应给客户端
// String resultJson = "{"fullPath":""+fullPath+"", "relativePath":""+relativePath+""}";
// return resultJson;
return new FileInfo(newFileName+suffix, false, fullPath, relativePath);
}
}
FileInfo.java:
package com.rz.cms.server.main.utils;
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.rz.cms.server.main.controller.news;
import com.rz.cms.server.main.utils.FileInfo;
import com.rz.cms.server.main.utils.HttpResult;
import com.rz.cms.server.main.utils.JesyFileUploadUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
@RequestMapping("/file")
public class FileController {
@PostMapping("/upload")
@ResponseBody
@CrossOrigin(origins = "*")
public String upload(MultipartFile file){
String result = null;
try {
FileInfo fileInfo = JesyFileUploadUtil.uploadFile(file, "http://localhost:8060");
result = fileInfo.getRelativePath();
} catch (Exception e) {
e.printStackTrace();
result = null;
}
return result;
}
}
@GetMapping("/regedit/{id}/{title}/{descn}/{imgurl}")
@ResponseBody
@CrossOrigin(origins = "*")
public HttpResult regedit(@PathVariable int id,@PathVariable String title,@PathVariable String descn,@PathVariable String imgurl){
return articleService.regedit(id,title,descn,imgurl);
}
或
前端页面
文章标题 文章描述 选择标题图(图片分辨率建议为:200px * 200px)
主要片段
upload(){
_self=this,
this.btnState = true,
uni.chooseImage({
count:1,
sizeType:['original','compressed'],
sourceType:['album'],
success:function(res){
const tempFilePaths = res.tempFilePaths;
const uploadTask = uni.uploadFile({
url:'http://localhost:8070/file/upload',
filePath: tempFilePaths[0],
name:'file',
success:function(uploadFileRes){
_self.relativePath=uploadFileRes.data;//获得文件路径
}
});
uploadTask.onProgressUpdate(function(res){
_self.percent = res.progress;//获得文件上传进度
});
}
});
},
//需要传递路径时进行转换,回显时再转换
var path=this.relativePath.replace(///g,'@')
其他方法:
三、页面布局:行和左右漂移
.uni-flex {
display: flex;
flex-direction: row;
}
.uni-row {
flex-direction: row;
}
回显:
{{title}} {{content.value}}



