设为首页 加入收藏

TOP

Gin-Go学习笔记四:Gin-Web框架 文件的上传下载(二)
2017-12-23 06:06:47 】 浏览:4026
Tags:Gin-Go 学习 笔记 Gin-Web 框架 文件 上传下载
).show(); var html='<image src="/static/uploadfile/'+file.name+'" style="height:150px;width:150px;margin:20px;"/>'; $("#imgdiv").append(html); } }); }); //下载图片 function download(){ //暂时没有提供后台的方法 //gin暂时没有实现下载方法 //只有使用url window.location.href="/static/img/1.jpg"; } </script>  </body> </html>

  

5>在路由中添加路由

package routers

import (
  "github.com/gin-gonic/gin"
  . "GinLearn/GinLearn/apis" //api部分
  . "GinLearn/GinLearn/controllers" //constroller部分
 )
 
func InitRouter() *gin.Engine{
  router := gin.Default()
  //Hello World
  router.GET("/", IndexApi)
  //渲染html页面
  router.LoadHTMLGlob("views/*")
  router.GET("/home/index", ShowHtmlPage)
  //列表页面
  router.GET("/home/list", ListHtml)
  router.POST("/home/PageData", GetDataList)
  router.POST("/home/PageNextData", PageNextData)

  //新增页面
  router.GET("/home/add", AddHtml)
  router.POST("/home/saveadd", AddPersonApi)
  
   //编辑页面
   router.GET("/home/edit", EditHtml)
   router.POST("/home/saveedit", EditPersonApi)

    //删除
    router.POST("/home/delete", DeletePersonApi)

    //Bootstrap布局页面
    router.GET("/home/bootstrap", Bootstraphtml)

    //文件的上传和下载 
    router.GET("/home/fileopt", Fileopthtml)
    router.POST("/home/fileuplaod", Fileupload)
    router.GET("/home/filedown", Filedown)
    
    return router
 }
 

  

6>项目的结构如下:

 

 

7>执行的效果如下:

1->文件操作的页面如下,路由如下:

 

 

2->点击选择文件按钮,选择需要上传的图片,点击打开按钮,效果如下:

 

 

3->点击下载图片按钮,浏览器下载一张指定的图片

 

 

8>下一章,将文件内容的读取。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Golang学习--TOML配置处理 下一篇Gin-Go学习笔记六:Gin-Web框架 A..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目