首页 > 其他分享 >gorm 使用where in 条件查询时,使用uint8[] 类型报错的解决方案

gorm 使用where in 条件查询时,使用uint8[] 类型报错的解决方案

时间:2023-10-16 11:47:39浏览次数:44  
标签:type list uint8 报错 Test model where

出现问题:

在开发过程中,遇到这样一个问题,GORM Model 如下:

type Test struct {
	...
	
     cloumnType uint8  `gorm:"not null;default:0"`
    ...
}

其中有一个类型字段,数据范围是1-10 所以使用uint8字段来存储,在查询某些类型的数据时,使用了下面的查询语句

var list []model.Test
db.model(&model.Test{}).Where("column_type in ?",[]uint8{1,2}).Find(&list)

执行该语句后出现了如下报错

解决方案:

  • 方法一
    进行类型转换
db.model(&model.Test{}).Where("column_type in ?",cast.ToIntSlice([]uint8{1,2})).Find(&list)
  • 方法二
    加括号
db.model(&model.Test{}).Where("column_type in (?)",[]uint8{1,2}).Find(&list)

标签:type,list,uint8,报错,Test,model,where
From: https://www.cnblogs.com/xingzr/p/17766938.html

相关文章

  • redis在添加键值时报错"(error) MOVED...."
    问题描述:redis在添加键值时报错"(error)MOVED....",如下所示:数据库:redis6.2.5架构:三主三从1、异常重现192.168.133.97:6001>setk1v1(error)MOVED12706192.168.133.99:6001--集群信息192.168.133.97:6001>clusternodesb98cc2012f531244c29e2633f3d40ffc0c8bb2711......
  • poi报错org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetExcepti
    场景使用poi时报错org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException报错信息:org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetExceptionatorg.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory......
  • nbcio-boot升级到3.1后出现online表单新增报错       nbcio-boot升级springboot、
        nbcio-boot升级springboot、mybatis-plus和JSQLParser后出现新增online表单的时候报错,如下: 2023-08-1321:18:01.292[http-nio-8080-exec-12][1;31mERROR[0;39m[36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m-Handlerdispatchfailed;neste......
  • 记录Orcad中报错和解决方法
    本章目的:使用Orcad画原理图总会遇到奇怪的报错,故整理总结 1、根本原因:有元器件没有编号;更新一下位号解决。提示➤ERROR(ORNET-1048):Designisnotannotated.ERROR(ORNET-1006): Netlist failed or may be unusable. 2、根本原因:DesignCache右键CleanupCache,和......
  • grpc服务报错: http2 frame too large
    报错如下:14xxBadRequesterrorreadingserverpreface:http2:frametoolarge其中4xx为客户端报错中的一个具体数字。比如:404/415,仅以报错举例,且出现报错码不固定。但是errormsg的核心内容不变:frametoolarge...这个是因为客户端在没有TLS加密的情况下发送HTT......
  • 从链接器的角度详细分析g++报错: (.text+0x24): undefined reference to `main'
    /usr/bin/ld:/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o:infunction`_start':(.text+0x24):undefinedreferenceto`main'collect2:error:ldreturned1exitstatus  在使用g++编译链接两个C++源文件main.cpp以及VecAdd.cpp时出现了以上......
  • npm安装依赖报错npm ERR code ENOTFOUND npm ERR errno ENOTFOUND
    第一种方法:1:执行:npmconfiggetproxynpmconfiggethttps-proxy如两个返回值都为null,则直接执行第二步,要确保两个返回值都是null才可以,否则就要执行下面的代码:npmconfigsetproxynullnpmconfigsethttps-proxynull2:执行npmconfigsetregistryhttp://regis......
  • mysql报错:You must reset your password using ALTER USER statement before executin
    新安装mysql后,登录后,执行任何命令都会报错:YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.【解决办法】MySQL版本5.7.6版本以前用户可以使用如下命令:mysql>SETPASSWORD=PASSWORD('Admin2022!');MySQL版本5.7.6版本开始的用户可以使......
  • 关于Cortex-M3报错解决方法总结:Flash Download failed错误
    事情原因:在一次使用ST-LINKv2下载程序时,突然出现Error:FlashDownloadFailed-"Cortex-M3”这个错误,显示没有错误,没有警告。芯片型号接线都没有问题。当时就很摸不着头脑,然后上网查看了一下。原来是因为STM32F103C8T6有64kFlash和20kRAM,tm他们不属于高容量的Flash。所以我改了......
  • 在Node.js项目中使用node-postgres连接postgres以及报错指南
    什么是node-postgres官方文档nodepostgres是node.js模块的集合,用于与PostgreSQL数据库接口。它支持回调、promise、async/await、连接池、准备好的语句、游标、流式结果、C/C++绑定、富类型解析等等!就像PostgreSQL本身一样,它有很多功能:本文档旨在让您快速、正确地运行。它还试图......