zoukankan      html  css  js  c++  java
  • gorm 动态拼接查询条件

    结构体
    type Mould struct {
    	MouldId string `grom:"column:mouldID"`
    	MouldInteriorID string `grom:"column:mouldInteriorID"`
    	MouldName string `grom:"column:mouldName"`
    	ProjectInteriorID string `grom:"column:projectInteriorID"`
    	projectName string `grom:"column:projectName"`
    	ProjectId string `grom:"column:projectID"`
    }
    
      
    
    func GetMouldAll(mouldInteriorID string,projectInteriorID string)(moulds []Mould, err error){
    	var sql bytes.Buffer
    	sql.WriteString("select projectName,mouldInteriorID,mouldName,mould.mouldID,mould.projectID,projectInteriorID from mould ")
    	sql.WriteString("inner join Project on Project.projectID = mould.projectID where 1 = 1 ")
    	if mouldInteriorID != ""{
    		sql.WriteString(" and mould.mouldInteriorID='")
    		sql.WriteString(mouldInteriorID)
    		sql.WriteString("'")
    	}
    	if projectInteriorID!="" {
    		sql.WriteString(" and projectInteriorID='")
    		sql.WriteString(projectInteriorID)
    		sql.WriteString("'")
    	}
    	rows,err := MsDb.Raw(sql.String()).Rows()
    	if err != nil{
    		panic(err)
    	}
    	for rows.Next(){
    		mould := Mould{}
    		err = rows.Scan(&mould.projectName,&mould.MouldInteriorID,&mould.MouldName,&mould.MouldId,&mould.ProjectId,&mould.ProjectInteriorID)
    		moulds = append(moulds, mould)
    	}
    	rows.Close()
    	return
    }
    
  • 相关阅读:
    05day02wdt
    05day02pwm
    05day01ioctl_led
    04clock_06semqphore
    04lock_05seqlock
    04lock_03rwlock
    [git]入门-工作区、暂存区、版本库
    [git]入门-创建版本库
    [linux-脚本]shebang(shabang #!)
    [ffmpeg]安装
  • 原文地址:https://www.cnblogs.com/haima/p/13335189.html
Copyright © 2011-2022 走看看