简体   繁体   English

Java 应用程序中的版本控制对象

[英]Versioning objects in Java application

I have this variable in my Java application:我的 Java 应用程序中有这个变量:

@Pattern(
    regexp = "^[a-zA-Z0-9-]{4,}$",
    message =
        "Alphanumeric characters and '-' only allowed. Must be at least four characters long.",
    groups = FormatCheck.class)
private String registration;

This is fine as I currently have one client which sends a registration that matches the pattern.这很好,因为我目前有一个客户端发送与模式匹配的注册。 In the future I could potentially have multiple clients, all which have their own registration patterns.将来我可能有多个客户端,所有客户端都有自己的注册模式。 Is it possible to in some way version the variable or the pattern so that all my clients could use the same variable but each could validate against a different pattern?是否有可能以某种方式对变量或模式进行版本控制,以便我的所有客户都可以使用相同的变量,但每个客户都可以针对不同的模式进行验证? I'd like to avoid creating new variables for each client that uses its own pattern.我想避免为每个使用自己模式的客户端创建新变量。

Since annotations are evaluated at compilation, you can't use a runtime variable as a parameter since during compilation the runtime variables don't already have values.由于注释是在编译时评估的,因此您不能将运行时变量用作参数,因为在编译期间运行时变量还没有值。

In your case, you will most likely need to create a getter/setter method that will do the pattern matching logic and return null or throw an exception if it fails在您的情况下,您很可能需要创建一个 getter/setter 方法来执行模式匹配逻辑并返回 null 或在失败时抛出异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM