Методы для получения пользовательских аннотаций с использованием AbstractProcessor Получает имя атрибута и значение аннотации. Значение атрибута имеет тип AnnotationValue. Создать код с помощью javapoet AnnotationSpec.Builder (xx).AddMember (имя строки, формат строки, объект ... аргументы) Сгенерирован неправильный код: например: метод (@ AnnotationName (значение = "/" v1 / "/ v2" / ")) метод (@annotationname (значение =){"v1", "v2"})) Поскольку существует несколько типов атрибутов аннотаций, как определить, что такое AnnotationValue, и сгенерировать правильный код с помощью javapoet
AnnotationSpec.Builder builder = AnnotationSpec.builder(cc);
//Gets the attributes and attribute values of the annotation
//String:Attribute name of the annotation
//Object:(AnnotationVale) Attribute value
Map<String, Object> annoMap = annotationModel.getParams();
if (annoMap != null) {
Set<Map.Entry<String, Object>> set = annoMap.entrySet();
for (Map.Entry<String, Object> m : set) {
String memberName = m.getKey();
Object values = m.getValue();
builder.addMember(memberName, "$S", values);
}
}
Вот код ошибки, сгенерированный в настоящее времяjavapoet:
@RequestMapping( method = "org.springframework.web.bind.annotation.RequestMethod.GET,org.springframework.web.bind.annotation.RequestMethod.POST", value = "\"/api\",\"/ll\"" ) class TestController$ { @RequestMapping( vv = "@com.seal.base.core.annotation.SealVar(\"1111\")", method = "org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET", name = "name", value = "\"/register\",\"/api\"" )