目錄
【SpringBoot2.0文章匯總目錄糯耍,java多線程教程文章匯總 長期更新系列
】
請多多支持
關于
其實在很早之前我就開發(fā)過一個博客系統(tǒng)藏斩,不過由于當時自己的技術不夠成熟据忘,所以選擇的是ssm+velocity開發(fā)蔗包。前后端沒有分離蛛壳,編輯器選擇是百度uedit寞缝,后臺使用的jQuery easyui
,整個界面不是很美觀派敷,而且富文本編輯器很難用蛹批。所以一直想想給blog 升級。
現(xiàn)在 blog v2.0 beat即將上線篮愉。
它是基于 spring + vue實現(xiàn)的腐芍。
技術棧
springboot 后臺基礎框架提供rest api接口
springsecurity 提供安全權限認證
jwt 提供訪問token
spring-data-jpa 持久層訪問
redis 提供數(shù)據(jù)緩存
elasticsearch 提供全文檢索
七牛云 圖片托管至七牛云oss
vue.js 前臺基礎框架
iview 后臺管理ui
運行截圖
?
image.png
分隔符
image.png
主要實現(xiàn)代碼
package com.blog.qiniu.service.impl;
import com.blog.qiniu.QiNiuProperties;
import com.blog.qiniu.service.QiNiuService;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.InputStream;
/**
* @author: yukong
* @date: 2018/6/21 13:50
* @description:
*/
@Service
public class QiNiuServiceImpl implements QiNiuService, InitializingBean {
@Autowired
private UploadManager uploadManager;
@Autowired
private BucketManager bucketManager;
@Autowired
private Auth auth;
@Autowired
private QiNiuProperties qiNiuProperties;
private StringMap putPolicy;
@Override
public Response uploadFile(File file) throws QiniuException {
Response response = this.uploadManager.put(file, null, getUploadToken());
int retry = 0;
while (response.needRetry() && retry < 3) {
response = this.uploadManager.put(file, null, getUploadToken());
retry++;
}
return response;
}
@Override
public Response uploadFile(InputStream inputStream) throws QiniuException {
Response response = this.uploadManager.put(inputStream, null, getUploadToken(), null, null);
int retry = 0;
while (response.needRetry() && retry < 3) {
response = this.uploadManager.put(inputStream, null, getUploadToken(), null, null);
retry++;
}
return response;
}
@Override
public Response delete(String key) throws QiniuException {
Response response = bucketManager.delete(qiNiuProperties.getBucket(), key);
int retry = 0;
while (response.needRetry() && retry++ < 3) {
response = bucketManager.delete(qiNiuProperties.getBucket(), key);
}
return response;
}
@Override
public void afterPropertiesSet() throws Exception {
this.putPolicy = new StringMap();
putPolicy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"width\":$(imageInfo.width), \"height\":${imageInfo.height}}");
}
/**
* 獲取上傳憑證
*
* @return
*/
private String getUploadToken() {
return this.auth.uploadToken(qiNiuProperties.getBucket(), null, 3600, putPolicy);
}
}
總結
希望大家有興趣一起完善的可以聯(lián)系我
最后大家關注一下我的個人公眾號把。關注我公眾號即可獲取源碼
公眾號