码农笔录博客源码
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

46 lignes
1.0 KiB

package controllers
import (
"beeblog/models"
"beeblog/service"
il y a 6 ans
"github.com/astaxie/beego"
"strconv"
)
type BlogController struct {
beego.Controller
}
func (this *BlogController) Save() {
il y a 6 ans
title := this.GetString("title")
blogHtml := this.GetString("blogHtml")
catory := this.GetString("catory")
catoryId, _ := strconv.ParseInt(catory, 10, 64)
labels := this.GetStrings("labels[]")
il y a 6 ans
blog := &models.Blog{Title: title, BlogHtml: blogHtml, CategoryId: catoryId, UserId: 1}
err := service.SaveBlog(blog, labels)
il y a 6 ans
if err == nil {
this.Data["json"] = blog
} else {
this.Data["json"] = models.ReurnError(500,"保存失败")
}
this.ServeJSON()
}
func (this *BlogController) Get() {
idStr := this.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 10, 64)
blog, err := service.GetBlog(id)
il y a 6 ans
if err == nil {
this.Data["Blog"] = blog
}
this.TplName = "blog.html"
}
il y a 6 ans
func (this *BlogController) New() {
this.TplName = "newblog.html"
il y a 6 ans
}
il y a 6 ans
func (this *BlogController) Blog1() {
this.TplName = "blog1.html"
}