gpt4 book ai didi

spring - 如何在 .antmatchers.access() 中使用常量

转载 作者:行者123 更新时间:2023-12-02 03:26:03 25 4
gpt4 key购买 nike

我想在 .antmatchers.access(): 中使用 AuthoritiesConstants.java 中的一些常量:

.antMatchers("/first/**").access("hasAuthority('ROLE_ALL') and hasAuthority('ROLE_ME')")

它有效,但我想使用常量 ALL:

public static final String ALL = "ROLE_ALL";

我试过:

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");

但这行不通。

请帮忙

最佳答案

这行不通,因为它实际上并没有引用常量。它假设 'AuthoritiesConstants.ALL' 只是一个 String 文字,并且是这样计算的。

.antMatchers("/first/**").access("hasAuthority('AuthoritiesConstants.ALL')");

你可以尝试使用类似的东西:

.antMatchers("/first/**").hasAuthority(AuthoritiesConstants.ALL);

或者如果您需要在访问表达式中引用常量,您可以使用以下语法:access("hasAuthority(T(com.example.AuthoritiesConstants).ALL) and ...") ,其中 com.example. 是包含 AuthoritiesConstants 类的包。

关于spring - 如何在 .antmatchers.access() 中使用常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30237238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com