beego实现web api接口

2020-12-13 16:05

阅读:497

标签:style   blog   http   io   color   ar   java   for   sp   

1)程序代码:

/**
 * 类似beego版物联网首页产品数据的调用
 */import (
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/httplib"
)

type MainController struct {
    beego.Controller
}

func (this *MainController) Get() {

    str, _ := httplib.Get("http://shop.iotywl.com/tools/cms.ashx?cmdParam=Select_Product_List").String()

    this.Data["JsonDatas"] = str

    this.TplNames = "index.html"
}

2)视图代码:

DOCTYPE html>

html>
    head>
        title>Beegotitle>
        meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        script type="text/javascript" src="/static/js/jquery-1.9.1.min.js">script>
    head>
    body>
          ul id="html_data">ul>
    body>
    script type="text/javascript">
      var jsonDatas= "{{.JsonDatas}}";
  $(
function(){ var web_url = "http://shop.iotywl.com"; var image_url = "http://images.iotywl.com" var list=eval(jsonDatas); var strTemp = "";
for (var i = 0; i list.length; i++) { strTemp += "
  • " + web_url + "/Product/ProductDetail/" + list[i].Id + "\" target=\"_blank\">" + image_url + list[i].SmallImage + "\" />

    " + list[i].Title + "
  • "; } $("#html_data").html(strTemp); })   script> html>

     

       ---童飞

    beego实现web api接口

    标签:style   blog   http   io   color   ar   java   for   sp   

    原文地址:http://www.cnblogs.com/yunkeji/p/4079335.html


    评论


    亲,登录后才可以留言!