golang基础-beego_web开发、模板使用(待续)
2017-11-26 17:34
495 查看
beego开发
beego模板使用
1、规划好ur
2、添加路由
3、开发controller,继承beego.Controller
看看本例的结构图
main\main.go
初始化beego,引入router模块
router\router.go
Router方法意思就是将url后缀index,交给IndexController下的Index处理
IndexController/index.go
p.TplName意思就是加载路径下的html页面文件
views/index/index.html
接下来进行测试:
由于p.TplName = “index/index.html”我们在beego_example进行编译
然后历览器输入:
http://localhost:9091/index/
beego模板使用
beego开发
Beego web开发1、规划好ur
2、添加路由
3、开发controller,继承beego.Controller
看看本例的结构图
main\main.go
初始化beego,引入router模块
package main import ( _ "beego_example/router" "github.com/astaxie/beego" ) func main() { beego.Run() }
router\router.go
package router import ( "beego_example/controller/IndexController" "github.com/astaxie/beego" ) func init() { beego.Router("/index", &IndexController.IndexController{}, "*:Index") }
Router方法意思就是将url后缀index,交给IndexController下的Index处理
IndexController/index.go
package IndexController import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" ) //继承beego的Controller type IndexController struct { beego.Controller } func (p *IndexController) Index() { logs.Debug("enter index controller") p.TplName = "index/index.html" }
p.TplName意思就是加载路径下的html页面文件
views/index/index.html
<html> <body> <p> Hello World</p> </body></html>
接下来进行测试:
由于p.TplName = “index/index.html”我们在beego_example进行编译
PS E:\golang\go_pro\src\beego_example> go build beego_example/main PS E:\golang\go_pro\src\beego_example> main.exe 2017/11/26 17:21:21 [I] [asm_amd64.s:2197] http server Running on http://127.0.0.1:9091 2017/11/26 17:21:38 [D] [asm_amd64.s:514] enter index controller [beego] 2017/11/26 - 17:21:38 | 127.0.0.1| 200 | 1.5012ms| match| GET /index/ r:/index [beego] 2017/11/26 - 17:21:38 | 127.0.0.1| 200 | 1.5012ms| match| GET /index/ r:/ind [beego] 2017/11/26 - 17:21:38 | 127.0.0.1| 200 | 1.5012ms| match| GET /index/ r:/index [beego] 2017/11/26 - 17:21:38 | 127.0.0.1| 404 | 500.2µs| nomatch| GET /favicon.ico
然后历览器输入:
http://localhost:9091/index/
beego模板使用
待续。。。相关文章推荐
- 使用Java进行FreeMarker的web模板开发的基础教程
- 使用Java进行FreeMarker的web模板开发的基础教程
- 使用Java进行FreeMarker的web模板开发的基础教程
- Golang web 开发实战之 session 缓存:如何使用 redigo 将一个结构体数据保存到 redis?
- golang的 Web 开发,提示找不到模板文件
- Web开发基础以及Tomcat基本使用(特别讲解mac如何启动tomcat)
- Golang框架beego和bee的开发使用
- PHP-Web应用程序开发:使用模板(入门)
- golang(5)使用beego 开发 api server 和前端同学拆分开发,使用swagger
- web基础----->模板引擎Velocity的使用(二)
- Android开发笔记—WebView、ProgressDialog的基础使用
- 30分钟学会使用Spring Web Services基础开发
- 学习使用J2EE Web应用的事件功能-Java基础-Java-编程开发
- 使用Java进行FreeMarker的web模板开发
- Spring Web ,使用annotation和form标签库开发web应用(一)基础配置
- (微信API接口开发) 使用HttpWebRequest进行请求时发生错误:基础连接已关闭,发送时发生错误处理
- sqlalchemy在pythonweb中开发的使用(基于tornado的基础上)
- Java Web开发——FreeMarker模板使用方法讲解
- golang(4)使用beego + ace admin 开发后台系统 CRUD
- Golang 使用 Beego 与 Mgo 开发的示例程序