我有以下类(class)。
public class MultipartFileWrapper {
@Extensions({".jpg",".png",".gif",".bmp",".mp4"})
MultipartFile multipartFile;
...
}
现在我想将格式提取为常量。 但我不明白如何替换
@Extensions({".jpg",".png",".gif",".bmp",".mp4"})
如果我有数组
String[] validFormats
其中包含列出的格式。我想写这样的东西:
public class MultipartFileWrapper {
@Extensions(validFormats)
MultipartFile multipartFile;
...
}
最佳答案
现在我明白了你的问题...也许你可以在类里面尝试这个方法:
public String[] getExtensions()throws NoSuchFieldException, SecurityException{
return MultipartFileWrapper.class.getDeclaredField("multipartFile").getAnnotation(Extensions.class).value();
}
调用该方法并获取“注释”值
关于java - 如何将数组作为注释参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28417310/