码农笔录博客源码
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

54 рядки
1.2 KiB

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