小编Lad*_*and的帖子

Spring Boot:请求参数中的自定义验证

我想验证我的控制器中的请求参数之一。请求参数应该来自给定值列表之一,如果不是,则应该抛出错误。在下面的代码中,我希望请求参数 orderBy 来自@ValuesAllowed 中存在的值列表。

@RestController
@RequestMapping("/api/opportunity")
@Api(value = "Opportunity APIs")
@ValuesAllowed(propName = "orderBy", values = { "OpportunityCount", "OpportunityPublishedCount", "ApplicationCount",
        "ApplicationsApprovedCount" })
public class OpportunityController {

@GetMapping("/vendors/list")
    @ApiOperation(value = "Get all vendors")

    public ResultWrapperDTO getVendorpage(@RequestParam(required = false) String term,
            @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size,
            @RequestParam(required = false) String orderBy, @RequestParam(required = false) String sortDir) {
Run Code Online (Sandbox Code Playgroud)

我编写了一个自定义 bean 验证器,但不知何故这不起作用。即使我为查询 param 传递了任何随机值,它也不会验证并抛出错误。

@Repeatable(ValuesAllowedMultiple.class)
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {ValuesAllowedValidator.class})
public @interface ValuesAllowed {

    String message() default "Field value should …
Run Code Online (Sandbox Code Playgroud)

validation controller spring-annotations http-request-parameters spring-boot

11
推荐指数
2
解决办法
3万
查看次数

动态设置 KUBECONFIG 环境变量

我对 Bash 很陌生,并且正在处理多个 kubernetes 集群。我想要某种实用程序,可以在处理多个集群时动态设置 KUBECONFIG 变量。我的 kubeconfig 文件位于多个文件夹中。我想要的是找到所有 kubeconfig 文件,获取路径并将路径与冒号连接,将其设置为 KUBECONFIG 变量并将其导出到 bashrc 文件中。

我知道一些命令,但无法构建完整的代码。

find /Users/anandabhishe/gitlab/ -name kubeconfig.yaml -exec echo {} \; 
Run Code Online (Sandbox Code Playgroud)

我想连接 find 命令的输出并设置我的 KUBECONFIG。像这样 ”

export KUBECONFIG=/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc1-staging-hrwork-dev/kubeconfig.yaml:/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc2-prod-hrwork-uat/kubeconfig.yaml:/Users/anandabhishe/gitlab/work2/kubeconfigs/scdc2-prod-hrwork/kubeconfig.yaml

bash shell find

11
推荐指数
1
解决办法
3万
查看次数