在使用beego时遇到 need a primary key field

1 确保结构中的 字段首字母大写
2 beego默认主键是id 如果主键定义的是其他字段比如userid 那么加上orm pk type User struct {
Id int `orm:"pk;column(Userid);"`
Name string
}

 beego 上传文件

package main

import (
"github.com/astaxie/beego"
) type UploadController struct {
beego.Controller
}
func (this *UploadController) Post() {
this.SaveToFile("uploadfile", "./static/files/",true)
this.Ctx.Redirect(, "/upload") }
/*
* fromfile input type=file name=fromfile
* tofilepath the path where the file going to save
* newfilename boolen is create new name or use original name
*/
func (c *UploadController) SaveToFile(fromfile, tofilepath string, newfilename bool) error {
file, h, err := c.Ctx.Request.FormFile(fromfile)
if err != nil {
return err
}
defer file.Close()
newname := h.Filename
if newfilename {
newname = fmt.Sprintf("%v%s", time.Now().Unix(), path.Ext(h.Filename))
}
tofilepath = path.Join(tofilepath, newname)
f, err := os.OpenFile(tofilepath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, )
if err != nil {
return err
}
defer f.Close()
io.Copy(f, file)
return nil
}
func main() {
  beego.Router("/upload", &UploadController{}) beego.Run()
}
<head>
<title>上传文件</title>
</head>
<body> <form enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="uploadfile" />
<input type="submit" value="upload" />
</form> </body>
</html>

beego 点滴的更多相关文章

  1. 【原】Go语言及Web框架Beego环境无脑搭建

    本文涉及软件均以截至到2013年10月12日的最新版本为准 1. 相关软件准备: 1) go1.2rc1.windows-386.msi,对应32位windows系统安装使用 下载地址: https: ...

  2. go中安装Beego不成功笔记

    在go.Git等等之类的相关软件安装好了之后,便可以安装Beego. 1.开始的时候是由于网络限制,不能访问Github,这个还好说找VPNFQ... 2.之后的问题,在git Bash中输入go g ...

  3. beego上传文件

    html代码: <form id="fform" method="POST" enctype="multipart/form-data" ...

  4. golang开发环境配置及Beego框架安装

    配置环境:Windows7推荐IDE:LiteIDEGO下载地址:http://www.golangtc.com/downloadBeego开发文档地址:http://beego.me/docs/in ...

  5. beego 框架入门

    根据官网向导安装配置好环境和工具https://beego.me 就可以开始了,先来入门下. 1.新建项目  在项目目录下 bee new quickstart成功后就可以运行了 http serve ...

  6. 新篇章,Golang 和 beego 初识

    beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado.sinatra ...

  7. iPhone应用开发 UITableView学习点滴详解

    iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...

  8. Pathoto项目:AWS+golang+beego搭建

    帮兄弟写了一个网站,由于要在国外使用,选择了AWS作为服务器. 不知道后面的价格如何,12个月免费的确吸引了我. 花费3天时间,从注册到服务器搭建访问,终于搞定了.下面记录一下其中容易出错的命令. 1 ...

  9. Beego框架使用

    go get github.com/astaxie/beego vim hello.go package main import "github.com/astaxie/beego" ...

随机推荐

  1. 编码 Unicode utf-8

    编码的发展史: 一开始计算机只在美国使用.8位的字节可以组合出256种不同的状态.他们将0到32种状态规定为”控制码“,后来又用其中32号以后的状态表示空格.标点符号.数字和大小写字母.这样一直编到了 ...

  2. 2017 计蒜之道 初赛 第一场 A、B题

    A题 阿里的新游戏 题目概述: 阿里九游开放平台近日上架了一款新的益智类游戏——成三棋.成三棋是我国非常古老的一个双人棋类游戏,其棋盘如下图所示: 成三棋的棋盘上有很多条线段,只能在线段交叉点上放入棋 ...

  3. empty() isset() isnull() 比较

    有关 PHP 的 empty(),isset() 还有 is_null() 这三个函数的用法讨论得已经很多了,而且很多资料也未必能说得很清楚.这里再重复一次,但不是从概念去说,直接用程序例子来说话,应 ...

  4. ajax 三级联动商品分类(转载)

    转载  自  jines     http://www.cnblogs.com/lijinblogs/p/5759399.html 思路分析:效果:当页面加载时,利用ajax异步向后台请求数据,加载一 ...

  5. .ne 基础(2)

    类是一种抽象 抽象的概念,具体的实例. 现实是先有对象,再抽象成类,再用类来创建实例 构造方法 (1)如果写好了类,不写构造方法,系统会默认一个无参的构造方法 (2) 如果手动添加了一个 构造方法,就 ...

  6. 锐捷交换机实验案例:vlan间互访的配置与验证

    组网需求: 1.如下图所示,某用户内网被划分为VLAN 10.VLAN 20.VLAN 30,以实现相互间的2 层隔离: 2.3 个VLAN 对应的IP 子网分别为192.168.10.0/24 .1 ...

  7. 创建oracle数据库表空间并分配用户

    我们在本地的oracle上或者virtualbox的oracle上 创建新的数据库表空间操作:通过system账号来创建并授权/*--创建表空间create tablespace YUJKDATAda ...

  8. angularjs ng-app="angular_app" ng-controller="angular_controller" ng-init="findAll()"

    ng-app="angular_app" 范围 ng-controller="angular_controller" 控制器 ng-init="fin ...

  9. JS-类型相关

    typeof检测类型typeof 返回的数据类型种类:number(js不分整形,浮点等等 所有的数字都是number类型).string.boolean.undefined.object.funct ...

  10. LAMP+Varnish的实现

    基于Keepalived+Varnish+Nginx实现的高可用LAMP架构 注意:各节点的时间需要同步(ntpdate ntp1.aliyun.com),关闭firewalld(systemctl ...