方法一:

main.go里:

beego.SetStaticPath("tests_url", "tests") //第一个是访问的路径,第二个是根下目录

方法二:

package main

import (
	_ "./routers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context" //注意:是这个context
	"log"
	"net/http"
	"strings"
)



func ignoreStaticPath() {
	//过滤器
	beego.InsertFilter("/", beego.BeforeRouter, TransparentStatic)
	beego.InsertFilter("/*", beego.BeforeRouter, TransparentStatic)
}

func TransparentStatic(ctx *context.Context){
	orpath := ctx.Request.URL.Path
	log.Println(orpath)
	//如果url中有api,则取消静态路由重定向
	if strings.Index(orpath, "api") >= 0 {
		return
	}
	http.ServeFile(ctx.ResponseWriter, ctx.Request, "static/html/" + orpath)
}

func main() {
	ignoreStaticPath()
	beego.Run()
}

注意:导入的是github.com/astaxie/beego/context,而不是context