基于springboot+vue.js实现的前后端分离的blog

关于

其实在很早之前我就开发过一个博客系统,不过由于当时自己的技术不够成熟,所以选择的是ssm+velocity开发。前后端没有分离,编辑器选择是百度uedit,后台使用的jQuery easyui,整个界面不是很美观,而且富文本编辑器很难用。所以一直想想给blog 升级。
现在 blog v2.0 beat即将上线。
它是基于 spring + vue实现的。

技术栈

  • springboot 后台基础框架提供rest api接口

  • springsecurity 提供安全权限认证

  • jwt 提供访问token

  • spring-data-jpa 持久层访问

  • redis 提供数据缓存

  • elasticsearch 提供全文检索

  • 七牛云 图片托管至七牛云oss

  • vue.js 前台基础框架

  • iview 后台管理ui

运行截图


分隔符

主要实现代码

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);
    }
}

总结

希望大家有兴趣一起完善的可以联系我

你可能感兴趣的:(个人博客,springboot,vue.js)