我用一个小时完全重写了蘑菇博客的后台

1,963 阅读3分钟

蘑菇博客是一个非常出色的博客开源博客平台,地址为: gitee.com/moxi159753/…

我是erupt的作者,出于宣传的原因,我重写了蘑菇博客的后台部分,时间仅用了一小时!

使用技术为:Spring Boot 、Erupt、JPA

首先初始化项目,步骤详见:www.yuque.com/yuepeng/eru…

现在开始Coding ~

博客类别

@Erupt(
        name = "博客类别",
        desc = "sort"
)
@Table(name = "blog_category")
@Entity
public class BlogCategory extends BaseModel {

    @EruptField(
            views = @View(title = "名称"),
            edit = @Edit(title = "名称", notNull = true, search = @Search(vague = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "顺序"),
            edit = @Edit(title = "顺序", notNull = true)
    )
    private Integer sort;

    @EruptField(
            views = @View(title = "是否显示"),
            edit = @Edit(title = "是否显示", notNull = true)
    )
    private Boolean isShow;

    @EruptField(
            views = @View(title = "分类介绍"),
            edit = @Edit(title = "分类介绍", type = EditType.TEXTAREA)
    )
    private String remark;

}

效果图

标签管理

@Erupt(
        name = "博客标签",
        desc = "sort"
)
@Table(name = "blog_tag")
@Entity
public class BlogTag extends BaseModel {


    @EruptField(
            views = @View(title = "标签名称"),
            edit = @Edit(title = "标签名称", notNull = true, search = @Search(vague = true), inputType = @InputType(fullSpan = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "排序"),
            edit = @Edit(title = "排序", notNull = true)
    )
    private Integer sort;

}

效果展示

博客管理

@Erupt(
        name = "博客管理",
        linkTree = @LinkTree(field = "blogCategory")
)
@Table(name = "blog_article")
@Entity
public class Blog extends HyperModel {

    @EruptField(
            views = {
                    @View(title = "标题图", type = ViewType.IMAGE)
            },
            edit = @Edit(title = "标题图", notNull = true, type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE))
    )
    private String image;

    @EruptField(
            views = @View(title = "标题"),
            edit = @Edit(title = "标题", notNull = true, search = @Search(vague = true), inputType = @InputType(fullSpan = true))
    )
    private String name;

    @EruptField(
            views = @View(title = "简介", type = ViewType.HTML),
            edit = @Edit(title = "简介", notNull = true, search = @Search(vague = true), inputType = @InputType(fullSpan = true))
    )
    private String intro;

    @EruptField(
            views = @View(title = "是否原创"),
            edit = @Edit(title = "是否原创", notNull = true)
    )
    private Boolean original;

    @EruptField(
            views = @View(title = "是否发布"),
            edit = @Edit(title = "是否发布", notNull = true)
    )
    private Boolean publish;

    @EruptField(
            views = @View(title = "推荐等级"),
            edit = @Edit(title = "推荐等级", notNull = true, type = EditType.CHOICE,
                    choiceType = @ChoiceType(vl = {
                            @VL(value = "0", label = "正常"),
                            @VL(value = "10", label = "一级推荐"),
                            @VL(value = "20", label = "二级推荐"),
                            @VL(value = "30", label = "三级推荐")
                    }))
    )
    private Integer recommendedLevel;

    @ManyToOne
    @EruptField(
            views = @View(title = "分类", column = "name"),
            edit = @Edit(title = "分类", notNull = true, type = EditType.REFERENCE_TREE)
    )
    private BlogCategory blogCategory;

    @EruptField(
            views = @View(title = "标签", template = "value&&value.replace(/\\|/g,'<span class=\"text-red\"> | </span>')"),
            edit = @Edit(title = "标签", notNull = true, type = EditType.TAGS,
                    tagsType = @TagsType(fetchHandler = BlogTagHandler.class)
            )
    )
    private String tag;

    @Lob //文章内容较多定义为大文本类型
    @EruptField(
            views = @View(title = "内容", type = ViewType.HTML),
            edit = @Edit(title = "内容", notNull = true, type = EditType.HTML_EDITOR)
    )
    private String content;

    @EruptField(
            views = @View(title = "备注"),
            edit = @Edit(title = "备注", type = EditType.TEXTAREA)
    )
    private String remark;

    @EruptField(
            views = @View(title = "点击数")
    )
    private Integer clickNum = 0; //需要通过前端接口向数据库写入!

}
@Component
public class BlogTagHandler implements TagsFetchHandler {

    @Autowired
    private EruptDao eruptDao;

    @Override
    public List<String> fetchTags(String[] params) {
        List<String> result = new ArrayList<>();
        List<Map<String, Object>> map = eruptDao.queryMapList(BlogTag.class, null, null, "name");
        for (Map<String, Object> objectMap : map) {
            result.add(objectMap.get("name").toString());
        }
        return result;
    }
}

友情链接

@Erupt(
        name = "友情链接",
        orderBy = "sort"
)
@Table(name = "blog_link")
@Entity
public class FriendlyLink extends BaseModel {

    @EruptField(
            views = @View(title = "友链名"),
            edit = @Edit(title = "友链名", notNull = true)
    )
    private String name;

    @EruptField(
            views = @View(title = "友链简介"),
            edit = @Edit(title = "友链简介", notNull = true)
    )
    private String remark;

    @EruptField(
            views = @View(title = "友链URL", type = ViewType.LINK_DIALOG),
            edit = @Edit(title = "友链URL", notNull = true)
    )
    private String url;

    @EruptField(
            views = @View(title = "站长邮箱"),
            edit = @Edit(title = "站长邮箱")
    )
    private String email;

    @EruptField(
            views = @View(title = "排序"),
            edit = @Edit(title = "排序")
    )
    private Integer sort;

}

开发完成,粘贴这些代码或许你可以在五分钟之内重写蘑菇博客的后台!

接下来再展示下蘑菇博客的后台功能:

文章管理 分类管理 标签管理 友情链接

不得不承认配色上是不如蘑菇博客的,但是在效率上很有优势,如果要修改博客字段,仅需简单的修改配置就可完成!!!

蘑菇博客演示后端地址:demoadmin.moguit.cn/

重写后蘑菇博客后端地址:www.erupt.xyz/demo/#/buil…

Erupt框架地址www.erupt.xyz