Java 在弹簧选择的何处使用“in”而不是“=”时出现异常
我正在使用Spring选择一个值。这是存储库中的查询:Java 在弹簧选择的何处使用“in”而不是“=”时出现异常,java,mysql,spring,Java,Mysql,Spring,我正在使用Spring选择一个值。这是存储库中的查询: @Query(value = "select * from incidents where descriptioninfo like %:descriptioninfo% and fixed = :fixed and starttimestamp > :startTime and deviceid in (select id from devices) and deviceid in (select deviceid from dev
@Query(value = "select * from incidents where descriptioninfo like %:descriptioninfo% and fixed = :fixed and starttimestamp > :startTime and deviceid in (select id from devices) and deviceid in (select deviceid from devicesmaps) and (incidentseverityid in (:incidentseverityid)) order by starttimestamp desc limit :start, :length", nativeQuery = true)
public List<IncidentEntity> getByStarttimestampAndDescriptioninfoAndSeverityAndFixed(@Param("startTime") String startTime, @Param("descriptioninfo") String descriptioninfo, @Param("incidentseverityid") List<Integer> incidentseverityid, @Param("start") int start, @Param("length") int length, @Param("fixed") int fixed);
到
修复异常并检索所需的值
对另一个参数“incidentseverityid”而不是异常“descriptioninfo”中的参数从“in”到“=”进行尽可能小的更改,即可解决此问题
为什么?
带有“in”或“=”的select在MySQL工作台中使用相同的参数。
请不要告诉我将:param更改为?1。
请注意,该表在MySQL中被转储、还原甚至修复,其引擎在InnoDB和MyISAM之间更改。
还要注意——即使创建一个名为“IncidentsServerLitiesEntity”的子类并使用一个合适的int-ID也没有帮助——只不过将ig从“in”切换到了“=”
@Param("incidentseverityid") List<IncidentsServeritiesEntity> incidentseverityid
或:
用括号括起来。解决方案有点难看,但有效:用=而不是in定义缺少的内容,创建一个长or命令并传递它
String allParams = "";
for (String currParam : param)
{
allParams += ("param = " + currParam + " or ");
}
allParams = allParams .substring(5, allParams .length() - 3);
(incidentseverityid = (:incidentseverityid))
@Param("incidentseverityid") List<IncidentsServeritiesEntity> incidentseverityid
identseverityid in :incidentseverityid
(identseverityid in (:incidentseverityid))
String allParams = "";
for (String currParam : param)
{
allParams += ("param = " + currParam + " or ");
}
allParams = allParams .substring(5, allParams .length() - 3);