[golang]-实现搜索功能

导语:实现界面上搜索项目的功能
html处修改

加入5-22行

{{template "../public/page_header.html" .}}
<div class="container-fluid">
    <div class="row">
 
        <!-- 搜索 -->
        <div class="panel panel-default">
            <div class="panel-heading">
                搜索
            </div>
            <div class="panel-body">
                <form role="form" class="form-inline" method="get" action="/{{config "String" "adminPath" ""}}/job">
                    <div class="form-group">
                        <label for="name">输入关键词</label>
                        <input type="text" class="form-control" value="{{.keyword}}" id="keyword" name="keyword" placeholder="请输入job名称">
                    </div>
        
                    <div class="form-group">
                        <button type="submit" class="btn btn-default">开始搜索</button>
                    </div>
                </form>
            </div>
        </div>
 
            <!-- 列表展示 -->
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead>
                    <tr class="th">
                        <th>job名称</th>
                        <th>job更新/创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {{range $key,$value := .jobinfo}}
                    
                    
                    <tr>
                        <td>{{$value.Name}}</td>
                        <td>{{$value.AddTime | unixToDate}}</td>         
                        <td class="text-center">

                            <a href="/{{config "String" "adminPath" ""}}/job/test/deploy?id={{$value.Id}}">测试环境发布</a> 
                            <a href="/{{config "String" "adminPath" ""}}/job/test/deploy?id={{$value.Id}}"><button class="btn btn-primary">测试环境发布</button></a> 

                            <!-- <a href="/{{config "String" "adminPath" ""}}/job/edit?id={{$value.Name}}">当前测试环境发布日志</a>  -->
            
                            <a href="/{{config "String" "adminPath" ""}}/job/test/toProdDirect?id={{$value.Id}}">申请直接上线</a> 
                            <a href="/{{config "String" "adminPath" ""}}/job/test/toProdDirect?id={{$value.Id}}"><button class="btn btn-danger">申请直接上线</button></a> 

                            <!-- <a href="/{{config "String" "adminPath" ""}}/job/edit?id={{$value.Name}}">当前生产环境发布日志</a>  -->

                            <!-- <a href="/{{config "String" "adminPath" ""}}/job/cancelDeploy?id={{$value.Id}}">取消上线申请</a>  -->
                            <!-- <a href="/{{config "String" "adminPath" ""}}/job/edit?id={{$value.Id}}">取消上线</a>  -->

                            <!-- <a class="delete" href="/{{config "String" "adminPath" ""}}/job/delete?id={{$value.Name}}">删除</a> -->
                        </td>
                    </tr>
                    {{end}}
                </tbody>
            </table>
        </div>

    </div>
</div>

</body>
</html>
go代码调整

原先

func (c *JobListController) JobList() {
	// 这里应该需要调整where参数吧?
	jobinfo := []models.Deploypara{}
	models.DB.Find(&jobinfo)
	c.Data["jobinfo"] = jobinfo
	// 输出各个job及对应的分支信息
	//beego.Info(jobinfo)

	c.TplName = "admin/job/index.html"
}

修改后 通过调整查询的sql 实现搜索功能

func (c *JobListController) JobList() {
	keyword := c.GetString("keyword")
	beego.Info("keyword", keyword)
	where := "1=1"
	if len(keyword) > 0 {
		where += " AND name like \"%" + keyword + "%\""
	}

	// 这里应该需要调整where参数吧?
	jobinfo := []models.Deploypara{}
	models.DB.Where(where).Find(&jobinfo)
	c.Data["jobinfo"] = jobinfo
	// 输出各个job及对应的分支信息
	//beego.Info(jobinfo)

	c.TplName = "admin/job/index.html"
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值