设为首页 加入收藏

TOP

Beego学习笔记5:MVC-VC(二)
2017-12-07 14:22:11 】 浏览:671
Tags:Beego 学习 笔记 5:MVC-VC
tals) //得到分页user的数据 userlist:=models.LimitList(3,pa) c.Data["datas"] = userlist //用户的数据 c.Data["paginator"] = res //分页的数据 c.Data["totals"] = totals //分页的数据 c.TplName="list.html" }

  

2>     在路由器文件router.go中添加路由配置,其代码如下:

package routers

import (
	"firstweb/controllers"
	"github.com/astaxie/beego"
)

func init() {
	//beego.Router("/", &controllers.MainController{})
	beego.Router("/", &controllers.HomeController{})
	beego.Router("/Home/Edit", &controllers.EditHomeController{})
	beego.Router("/Home/Update", &controllers.UpdateHomeController{})
	beego.Router("/Home/Delete", &controllers.DeleteHomeController{})
	beego.Router("/Home/List", &controllers.UserController{})
}

  

3>     在views文件夹下添加2html页面,分别为home.html,edit.html

4>     Home.html页面的代码如下:

 

<!DOCTYPE html>
 
<html>
      <head>
        <title>首页 - 用户列表页面</title>
        <link rel="shortcut icon" href="/static/img/favicon.png" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      </head>
    
    <body>
     
        <div class="row pull-right" style="margin-bottom: 20px;margin-right: 45px;text-align:right;">
          <a class="btn btn-success" href="/Home/Edit?Id=0">添加</a>
        </div>
            
        <table class="table table-striped table-hover table-bordered ">
          <thead>
           <th style="text-align: center">ID</th>
           <th style="text-align: center">名称</th>
           <th style="text-align: center">昵称</th>
           <th style="text-align: center">密码</th>
           <th style="text-align: center">Email</th>
           <th style="text-align: center">性别</th>
           <th style="text-align: center">手机号</th>
           <th style="text-align: center">操作</th>
         </thead>
        
         <tbody id="sortable">
            {{range $index, $item := .datas}}
            <tr class="sort-item"  id="module_{{$item.Id}}" value="{{$item.Id}}">
              <td style="text-align: center;width: 150px;"><span class="label label-default" >{{$item.Id}}</span></td>
              <td style="text-align: center;width: 240px;" ><strong>{{$item.Name}}</strong></td>
              <td style="text-align: center;width: 240px;" ><strong>{{$item.Nickname}}</strong></td>
              <td style="text-align: center;width: 240px;" ><strong>{{$item.Pwd}}</strong></td>
              <td style="text-align
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Beego 学习比较8:SQL语句 下一篇Beego 学习笔记7:JS分页

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目