![](/style/images/good.png)
3
![](/style/images/bad.png)
请问我像动态地修改@ApiOperation("远程测试")注解的value的值,然后怎么在...
source link: https://www.oschina.net/question/4719421_2324293
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
请问我像动态地修改@ApiOperation("远程测试")注解的value的值,然后怎么在swagger中呈现出来
@ApiOperation("远程测试") @GetMapping("/test") public String test() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException { Method method = this.getClass().getMethod("test"); ApiOperation apiOperation = method.getAnnotation(ApiOperation.class); //获取 foo 这个代理实例所持有的 InvocationHandler InvocationHandler handler = Proxy.getInvocationHandler(apiOperation); // 获取 AnnotationInvocationHandler 的 memberValues 字段 Field hField = handler.getClass().getDeclaredField("memberValues"); // 因为这个字段事 private final 修饰,所以要打开权限 hField.setAccessible(true); // 获取 memberValues Map memberValues = (Map) hField.get(handler); // 修改 value 属性值 memberValues.put("value", "增加"); String s = apiOperation.value(); log.debug(":::{}", s); return "success"; }
我更改了@ApiOperation("远程测试")里的value值为”增加“,可是刷新doc.html页面注解并没有改变
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK