You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
705 B

package Test
import (
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/DbUtil"
"fmt"
"strings"
"testing"
)
func TestSqlIn(t *testing.T) {
//方式1:传入字符串数组
idAry := []string{"1", "2", "3"}
ids := strings.Join(idAry, "','")
sqlRaw := fmt.Sprintf(`SELECT * FROM table WHERE id IN ('%s')`, ids)
fmt.Println(sqlRaw)
//方式2:传入整数数组
nums := []int{11, 12, 13}
ids = strings.Join(CommonUtil.ConvertIntegerArrayToStringArray(nums), "','")
sqlRaw = fmt.Sprintf(`select * from t_dm_subject where subject_id in ('%s')`, ids)
fmt.Println(sqlRaw)
var db = DbUtil.Engine
list, err := db.SQL(sqlRaw).Query().List()
if err != nil {
fmt.Println(err)
}
fmt.Println(list)
}