java - 如何在 spring-boot 应用程序中为 @Query(value=xyz) 提供最终值
问题描述
我正在从属性文件中读取我的 SQL 查询,并且我正在传递给 @Query(value=xyz) 但得到一致的错误“属性值必须是常量”。有没有可用的解决方案?
public class QueryUtils {
public static Properties properties;
static {
try {
FileReader reader = new FileReader("sql.properties");
properties = new Properties();
properties.load(reader);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String findAllTags2 = properties.getProperty("ResourceTagRepository.find_all_tags");
}
我正在尝试在打击代码中使用它。
@Component
@Repository
public interface QueryRepo extends JpaRepository<XYZ, Long>, JpaSpecificationExecutor<XYZ> {
@Query(value = findAllTags2)
public List<ResourceTagMapping> findAllTags(@Param("list") Set<String> names);
}
解决方案
尝试使您的 String findAllTags2 成为最终字段
推荐阅读
- windows - 在终端上的 Windows 中优雅地退出 golang
- php - 如何在单个模型功能上传递来自不同控制器功能的多个参数
- wordpress - Woocommerce 通过 id 获取产品数量(在购物车中)
- javascript - 父元素onclick中的子元素onclick
- graphql - 无法扩展远程 graphql 嵌套输入类型
- java - Hashmap相同值不同键比较
- node.js - 为什么我的自定义 process.env 在 dotenv 中不起作用?
- javascript - 我的代码和其他代码有什么区别?
- python-3.x - 加载泡菜 NotFittedError:TfidfVectorizer - 未安装词汇
- c - 在 C 中动态插入结构数组。退出,分段错误