spring boot jpa写原生sql报Cannot resolve table错误怎么办

这篇文章主要介绍了spring boot jpa写原生sql报Cannot resolve table错误怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

错误如图

spring boot jpa写原生sql报Cannot resolve table错误怎么办

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

打开View→Tool Windows→Persistence选项

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

在弹出的Persistence窗口的项目上右键,选择Generate Persistence Mapping→By Database Schema

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

在此处进行数据库相关配置,配置成功后即可在下方看到数据库中的表

spring boot jpa写原生sql报Cannot resolve table错误怎么办

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

选择下载driver files,或者使用自己本地的connector

spring boot jpa写原生sql报Cannot resolve table错误怎么办

自定义连接

 spring boot jpa写原生sql报Cannot resolve table错误怎么办

填写mysql相关的配置信息

spring boot jpa写原生sql报Cannot resolve table错误怎么办

选择data source,就可以看到数据库相关的配置了。

spring boot jpa写原生sql报Cannot resolve table错误怎么办

在弹出的Persistence窗口的项目上右键,选择Assign Data Sources...

spring boot jpa写原生sql报Cannot resolve table错误怎么办

选择上面我们自定义的数据库配置

spring boot jpa写原生sql报Cannot resolve table错误怎么办

然后在程序中加上库的名字就可以了。

@Repository
public interface CollectSwitchRepository extends JpaRepository<CollectSwitchEntity, Integer> {
  @Modifying
  @Query(nativeQuery = true, value = "update rexel_hzzg.COLLECT_SWITCH t set t.collect = :collect")
  public void updateOne(@Param("collect") String collect);
}

一套连招下来之后,错误解决。

spring boot jpa写原生sql报Cannot resolve table错误怎么办

感谢你能够认真阅读完这篇文章,希望小编分享的“spring boot jpa写原生sql报Cannot resolve table错误怎么办”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注行业资讯频道,更多相关知识等着你来学习!